智能家居初步实现--手机或PC机通过2440的boa服务器控制zigbee
来源:互联网 发布:杭州数据分析师 编辑:程序博客网 时间:2024/06/10 15:09
第一步 移植boa服务器到2440,在上一篇文章已经描述过。
第二步 2440通过串口连接CC2530 ,2440一共有3个串口,dev/tts/0(1,2)其中串口0是RS232电平的,串口1,2只有TTL电平,串口0要用作终端控制,所以选择串口2作为串口输出,通过一个转换芯片把TTL连接到CC2530的RS232接口上。修改mini2440的串口程序,使程序每执行一次,则发出一个字母‘a’,mini2440 串口程序如下
# include <stdio.h># include <stdlib.h># include <termio.h># include <unistd.h># include <fcntl.h># include <getopt.h># include <time.h># include <errno.h># include <string.h>int main(int argc, char **argv){ int CommFd, TtyFd; struct termios TtyAttr; struct termios BackupTtyAttr; int DeviceSpeed = B115200; int TtySpeed = B115200; int ByteBits = CS8; const char *DeviceName = "/dev/ttyS0"; const char *TtyName = "/dev/tty"; int OutputHex = 0; int OutputToStdout = 0; int UseColor = 0; opterr = 0;printf("Content-type: text/html\n\n"); printf("<TITLE>Mult Result</TITLE>"); printf("<H3>Mult Result</H3>"); DeviceName = "/dev/tts/2";<span style="white-space:pre"></span> OutputToStdout = 1; CommFd = open(DeviceName, O_RDWR, 0); if (CommFd < 0)<span style="white-space:pre"></span>Error("Unable to open device"); if (fcntl(CommFd, F_SETFL, O_NONBLOCK) < 0) <span style="white-space:pre"></span>Error("Unable set to NONBLOCK mode"); memset(&TtyAttr, 0, sizeof(struct termios)); TtyAttr.c_iflag = IGNPAR; TtyAttr.c_cflag = DeviceSpeed | HUPCL | ByteBits | CREAD | CLOCAL; TtyAttr.c_cc[VMIN] = 1; if (tcsetattr(CommFd, TCSANOW, &TtyAttr) < 0) Warning("Unable to set comm port");TtyFd = open(TtyName, O_RDWR | O_NDELAY, 0); if (TtyFd < 0)<span style="white-space:pre"></span>Error("Unable to open tty"); TtyAttr.c_cflag = TtySpeed | HUPCL | ByteBits | CREAD | CLOCAL; if (tcgetattr(TtyFd, &BackupTtyAttr) < 0)<span style="white-space:pre"></span>Error("Unable to get tty");// if (tcsetattr(TtyFd, TCSANOW, &TtyAttr) < 0) è¿™æ¡å‘½ä»¤ä¼šæ˜¯WEBæ— æ³•æ‰§è¡Œä¸²å£ç¨‹åºru guo you zhe ju hua web buzhi xing chuankou chengxu//<span style="white-space:pre"></span>Error("Unable to set ") for (;;) {<span style="white-space:pre"></span>unsigned char Char = 0; unsigned char Cha='a'; int i=3;<span style="white-space:pre"></span>fd_set ReadSetFD;<span style="white-space:pre"></span>void OutputStdChar(FILE *File) {<span style="white-space:pre"></span> char Buffer[10];<span style="white-space:pre"></span> int Len = sprintf(Buffer, OutputHex ? "%.2X " : "%c", Char);<span style="white-space:pre"></span> fwrite(Buffer, 1, Len, File);<span style="white-space:pre"></span>}<span style="white-space:pre"></span>FD_ZERO(&ReadSetFD);<span style="white-space:pre"></span>FD_SET(CommFd, &ReadSetFD);<span style="white-space:pre"></span>FD_SET( TtyFd, &ReadSetFD);#<span style="white-space:pre"></span>define max(x,y) ( ((x) >= (y)) ? (x) : (y) )//<span style="white-space:pre"></span>if (select(max(CommFd, TtyFd) + 1, &ReadSetFD, NULL, NULL, NULL) < 0) {//<span style="white-space:pre"></span> Error(strerror(errno)); // 这条命令会使程序需要一个输入才输出//<span style="white-space:pre"></span>}#<span style="white-space:pre"></span>undef max<span style="white-space:pre"></span><span style="white-space:pre"></span>static int EscKeyCount = 0; write(CommFd, &Cha, 1);<span style="white-space:pre"></span>if (OutputToStdout) {<span style="white-space:pre"></span> if (UseColor)<span style="white-space:pre"></span>fwrite("\x1b[01;31m", 1, 8, stderr); OutputStdChar(stderr);<span style="white-space:pre"></span> if (UseColor)<span style="white-space:pre"></span>fwrite("\x1b[00m", 1, 8, stderr);<span style="white-space:pre"></span> fflush(stderr);<span style="white-space:pre"></span> } goto ExitLabel; <span style="white-space:pre"></span>if (Char == '\x1b') { EscKeyCount ++; if (EscKeyCount >= 1) goto ExitLabel; } else EscKeyCount = 0;<span style="white-space:pre"></span> } ExitLabel: if (tcsetattr(TtyFd, TCSANOW, &BackupTtyAttr) < 0)<span style="white-space:pre"></span>Error("Unable to set tty"); return 0;}
交叉编译之后生成armcomtest程序,用mv命令改名字为test.cgi,ftp到板子里
第三步 通过IAR将CC2530的zigbee程序编译好下载CC2530里,协调器程序为一旦串口接受到‘a’字母即向终端发送点灯命令,然后在开发板上执行./test.cgi命令 测试能不能点灯成功,测试发现可以成功。
第四步 通过boa调用test.cgi程序,由于C程序里有<pre name="code" class="cpp">printf("Content-type: text/html\n\n"); printf("<TITLE>Mult Result</TITLE>"); printf("<H3>Mult Result</H3>");
这三条语句,这是CGI程序的接口,表明这个程序可以被boa服务器调用,然后设置mini2440里index.html,调用test.cgi,可以通过网页控制zigbee
第五步 电脑开热点,2440连热点,被分配一个本地IP,手机连上热点访问这个本地IP就可以通过手机控制zigbee。
1 0
- 智能家居初步实现--手机或PC机通过2440的boa服务器控制zigbee
- zigbee&云服务器智能家居控制系统
- 智能家居服务器和zigbee方面遇到的问题
- 基于android手机的智能家居控制
- 通过PC控制、操作andriod 手机-androidscreencast
- 使用ZigBee模块实现PC机与树莓派的无线通信
- 智能家居项目-1-boa服务器简单测试
- 一个嵌入式web服务器项目,实现通过手机Android App实现对嵌入式设备的控制
- mini2440基于boa服务器通过WEB控制GPIO
- pc机上boa webserver的构建
- ARM及ZigBee技术实现智能家居控制器的设计
- 实践操作整理:嵌入式linux上通过boa服务器实现cgi的web上网
- 嵌入式Linux上通过boa服务器实现cgi/html的web上网(转)
- 嵌入式Linux上通过boa服务器实现cgi-html的web上网
- 嵌入式Linux上通过boa服务器实现cgi/html的web上网
- 嵌入式Linux上通过boa服务器实现cgi/html的web上网
- 嵌入式Linux上通过boa服务器实现cgi/html的web上网(转)
- thinkphp通过浏览器ua信息判断访客为手机端或PC端的方法
- Java Web入门之我的理解
- Hadoop 集群 傻瓜式搭建手记 (一) 软件准备
- [python]python标准库(模块)简介
- HDU ACM Step 2.2.2 Joseph(约瑟夫环问题)
- Windows不能在本地计算机启动OracleDBConsoleorcl .错误代码2
- 智能家居初步实现--手机或PC机通过2440的boa服务器控制zigbee
- 判断1000-2000年之间的闰年,并输出
- Spinner + AsyncTask + Progress Bar 一次過搞定
- Openlayers3实战(一)
- linux系统的7种运行级别
- 浙江大学PAT_甲级_1005.1005. Spell It Right (20)
- JAVA中this的用法
- 开源消息总线eventBus学习
- ant build