极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 17740|回复: 3

路由器openwrt+arduino+dht11发微博

[复制链接]
发表于 2013-8-11 15:35:34 | 显示全部楼层 |阅读模式
源码: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.


2.利用1方式获取到的token,发布的微博会有显示来自yeelink。1中获取到的token有效期比较短,如果你想使用有效期比较长的高权限token,请参考
./src/weibo.h中的get_token()函数说明。



最后上图。




arduino+openwrt的结合,这仅仅是个开始,待续。
回复

使用道具 举报

发表于 2013-8-11 16:27:56 | 显示全部楼层
还可以加上视频采集,图文并茂。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-8-11 16:45:34 | 显示全部楼层
pathletboy 发表于 2013-8-11 16:27
还可以加上视频采集,图文并茂。

weibo.h 有发图片+内容的函数,openwrt可以安装mjpg-streamer再装个摄像头就可以截图发微博了。
回复 支持 反对

使用道具 举报

发表于 2015-7-21 00:49:44 | 显示全部楼层
我写的串口通信的代码,只能发出去,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[VTIME] = 0;
        options.c_cc[VMIN] = 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[5];
        sleep(100);
        read(fd, readC, 5);
        printf("%s\n", readC);
        close(fd);
}
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-4-26 20:28 , Processed in 0.038566 second(s), 20 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表