路由器openwrt+arduino+dht11发微博
源码:https://github.com/ljymc/WeiboOntimer程序的运行环境:刷了openwrt的路由器hg255d+通过USB接入路由器的arduino+DHT11温湿度传感器
功能:程序通过串口获取DHT11的数据,然后结合预先写好的微博内容发布到微博上。
示例微博:http://weibo.com/u/3703781171
在这份源码中,你可以知道的主要内容是
1.你可以知道如何通过C语言编写程序发微博,当然前提是你要获得Token.
./src/weibo.h ./src/weibo.c
2.C程序如何通过串口和arduino通信
./src/serialib.h ./src/serialib.c
3.ye.conf配置文件请放在和程序相同的路径下。
4.源码应该是比较清晰简单,其余部分就不多说了。
token的获取:
1.通过yeelink获取,仅仅是利用了该平台的token.
http://yeso.me/wp-content/uploads/2013/08/token.jpg
2.利用1方式获取到的token,发布的微博会有显示来自yeelink。1中获取到的token有效期比较短,如果你想使用有效期比较长的高权限token,请参考
./src/weibo.h中的get_token()函数说明。
最后上图。
http://yeso.me/wp-content/uploads/2013/08/weibo.jpg
http://yeso.me/wp-content/uploads/2013/08/IMG_20130811_150401-168x300.jpg
arduino+openwrt的结合,这仅仅是个开始,待续。 还可以加上视频采集,图文并茂。 pathletboy 发表于 2013-8-11 16:27 static/image/common/back.gif
还可以加上视频采集,图文并茂。
weibo.h 有发图片+内容的函数,openwrt可以安装mjpg-streamer再装个摄像头就可以截图发微博了。 我写的串口通信的代码,只能发出去,arduino也能接收到,就是arduino发送回来的,这边接收不到,请大神帮忙看下代码
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <termios.h>
#include <errno.h>
#include <string.h>
#define FALSE -1
#define TRUE 0
int main(){
//open port
int fd = open("/dev/ttyACM0", O_RDWR | O_NOCTTY | O_NDELAY);
if(FALSE == fd){
perror("cant't open port\n");
exit(1);
}
if(fcntl(fd, F_SETFL, 0) < 0){
printf("fcntl faild\n");
exit(1);
}else{
printf("fcntl=%d\n", fcntl(fd, F_SETFL, 0));
}
if(0 == isatty(STDIN_FILENO)){
printf("standard input is not a terminal device\n");
exit(1);
}else{
printf("isatty success\n");
}
//set port
struct termios options;
if(tcgetattr(fd, &options) != 0){
perror("SetupSerial 1");
exit(1);
}
cfsetispeed(&options, 9600);
cfsetospeed(&options, 9600);
options.c_cc = 0;
options.c_cc = 0;
options.c_cflag |= CLOCAL;
options.c_cflag |= CREAD;
options.c_cflag |= CRTSCTS;
options.c_cflag &= ~CSIZE;
options.c_cflag |= CS8;
options.c_cflag |= PARENB;
options.c_cflag &= ~PARODD;
options.c_iflag |= INPCK;
options.c_cflag &= ~CSTOPB;
tcsetattr(fd, TCSANOW, &options);
//send data
int sendLen = write(fd, "hello123", 9);
printf("send: %d\n", sendLen);
tcflush(fd, TCOFLUSH);
//read data
char readC;
sleep(100);
read(fd, readC, 5);
printf("%s\n", readC);
close(fd);
}
页:
[1]