极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 28714|回复: 10

Arduino+W5100 通过LeweiClient上传数据,不用再理解http了-乐联网应用

[复制链接]
发表于 2013-1-17 17:58:21 | 显示全部楼层 |阅读模式
本帖最后由 laoliu1982 于 2013-3-3 10:15 编辑

之前用W5100,参考cosm client的程序,上传,感觉对于不了解http的爱好者用起来不是很友好,比如计算content-length的时候,不容易描述清楚,最近把http post的过程封装成了LeweiClient 类库,去掉了类似content-length 的计算过程,终于让数据上传乐联网不用再了解http 的相关细节了。

作者说明:created by aozima(@wuyangyong )for art (RT-Thread)

                    modifyed by @grissiom  for arduino

代码已经更新到 https://github.com/lewei50/leweiclient  可能与这里的不一致,以github上面为准



需要把 LeweiClient 两个文件(leweiclient.c   leweiclient.h )放到 librariesLeWei 里并且在 IDE 里引用,USER_KEY  需要修改

LeweiClient 下载地址


  1. /*
  2.    lewei50 open platform sensor client
  3.    This code is in the public domain.
  4.   */

  5. #include <LeweiClient.h>
  6. #include <SPI.h>
  7. #include <Ethernet.h>

  8. #define LW_USERKEY "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
  9. #define LW_GATEWAY "01"

  10. //delay between updates
  11. #define POST_INTERVAL (10*1000)

  12. LeWeiClient *lwc;

  13. const unsigned long postingInterval = 10*1000;

  14. void setup() {
  15.    // start serial port:
  16.    Serial.begin(9600);
  17.    // hope no exception here
  18.    lwc = new LeWeiClient(LW_USERKEY, LW_GATEWAY);
  19. }

  20. void loop() {
  21.    // read the analog sensor:
  22.    //int sensorReading = analogRead(A0);  

  23.   // if there's incoming data from the net connection.
  24.    // send it out the serial port.  This is for debugging
  25.    // purposes only:

  26.   if (lwc) {
  27.     Serial.print("*** start data collection ");
  28.     lwc->append("BH", 123);
  29.     lwc->append("DS1", 456);
  30.     Serial.print("*** start either net send ");
  31.     lwc->send();
  32.     Serial.print("*** stop either net send ");

  33.    delay(POST_INTERVAL);
  34.    }
  35. }

复制代码


欢迎更多人使用乐联网平台 :更多技术交流请加入乐为物联技术支持群:59162154 或者 关注我们的新浪微博 @乐为物联

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复

使用道具 举报

发表于 2013-1-17 23:59:54 | 显示全部楼层
辛苦了,顺求有空做个28j60版的
回复 支持 反对

使用道具 举报

发表于 2013-1-18 08:31:23 来自手机 | 显示全部楼层
好强!!!
回复 支持 反对

使用道具 举报

发表于 2013-1-18 08:48:20 | 显示全部楼层
支持!!!!
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-1-18 13:11:38 | 显示全部楼层
wasdpkj 发表于 2013-1-17 23:59
辛苦了,顺求有空做个28j60版的

这两天就发一个28J60的
回复 支持 反对

使用道具 举报

发表于 2013-1-18 22:18:57 | 显示全部楼层
编译报错

E:\arduino-1.0.2\libraries\leweiclient\LeweiClient.cpp: In constructor 'LeWeiClient::LeWeiClient(const char*, const char*)':
E:\arduino-1.0.2\libraries\leweiclient\LeweiClient.cpp:51: error: 'rt_kprintf' was not declared in this scope
E:\arduino-1.0.2\libraries\leweiclient\LeweiClient.cpp:55: error: 'rt_kprintf' was not declared in this scope
E:\arduino-1.0.2\libraries\leweiclient\LeweiClient.cpp: In member function 'int LeWeiClient::append(const char*, int)':
E:\arduino-1.0.2\libraries\leweiclient\LeweiClient.cpp:67: error: 'rt_malloc' was not declared in this scope
E:\arduino-1.0.2\libraries\leweiclient\LeweiClient.cpp:89: error: 'rt_realloc' was not declared in this scope
E:\arduino-1.0.2\libraries\leweiclient\LeweiClient.cpp:104: error: 'rt_kprintf' was not declared in this scope
E:\arduino-1.0.2\libraries\leweiclient\LeweiClient.cpp: In member function 'int LeWeiClient::append(const char*, double)':
E:\arduino-1.0.2\libraries\leweiclient\LeweiClient.cpp:115: error: 'rt_malloc' was not declared in this scope
E:\arduino-1.0.2\libraries\leweiclient\LeweiClient.cpp:118: error: 'rt_kprintf' was not declared in this scope
E:\arduino-1.0.2\libraries\leweiclient\LeweiClient.cpp:131: error: 'rt_kprintf' was not declared in this scope
E:\arduino-1.0.2\libraries\leweiclient\LeweiClient.cpp:139: error: 'rt_realloc' was not declared in this scope
E:\arduino-1.0.2\libraries\leweiclient\LeweiClient.cpp:142: error: 'rt_kprintf' was not declared in this scope
E:\arduino-1.0.2\libraries\leweiclient\LeweiClient.cpp:155: error: 'rt_kprintf' was not declared in this scope
E:\arduino-1.0.2\libraries\leweiclient\LeweiClient.cpp: In member function 'int LeWeiClient::send()':
E:\arduino-1.0.2\libraries\leweiclient\LeweiClient.cpp:182: error: 'rt_kprintf' was not declared in this scope
E:\arduino-1.0.2\libraries\leweiclient\LeweiClient.cpp:189: error: 'rt_kprintf' was not declared in this scope
E:\arduino-1.0.2\libraries\leweiclient\LeweiClient.cpp:202: error: 'rt_free' was not declared in this scope
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-1-19 09:21:08 | 显示全部楼层
太惭愧了,直接把rt-thread的art板上面跑的给传上来了,已经更新附件,谢谢muggle
回复 支持 反对

使用道具 举报

发表于 2013-1-19 20:40:11 | 显示全部楼层
封装成库才好用。。。顺便建议,写一下库语法的教程。。。。。
回复 支持 反对

使用道具 举报

发表于 2013-5-12 17:43:33 | 显示全部楼层
麻烦问一下“LeWeiClient *lwc;”编译的时候总是报错,是怎么胡思hi呢
回复 支持 反对

使用道具 举报

发表于 2013-5-13 12:08:26 | 显示全部楼层
http不靠谱... 为了服务器偶尔要查询下设备状态就得让设备自己没事一直去轮询...多本末导致啊
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-5-24 22:44:40 | 显示全部楼层
alex ,这不是控制用的啊
回复 支持 反对

使用道具 举报

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

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

Archiver|联系我们|极客工坊

GMT+8, 2024-5-29 08:12 , Processed in 0.042563 second(s), 25 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

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