极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 40182|回复: 28

arduino+linkspite(Diamondback)+yeelink数据上传出现问题!!

[复制链接]
发表于 2012-9-22 19:46:19 | 显示全部楼层 |阅读模式
5
仿照linkspite中的simpletweet的例子我修改了函数库里Wiserver.cpp/request.cpp/string.c这几个文件,自认为在http协议方面没有出错,但还是不能向yeelink发送数据,求大神指点一下
附上代码以及linkspite



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

使用道具 举报

发表于 2012-9-23 08:27:28 | 显示全部楼层
帮顶等高手
回复

使用道具 举报

发表于 2012-9-23 13:11:18 | 显示全部楼层
post的头文件放哪儿了?
回复

使用道具 举报

 楼主| 发表于 2012-9-23 18:52:04 | 显示全部楼层
zcbzjx 发表于 2012-9-23 13:11
post的头文件放哪儿了?

不是request.cpp中的函数完成post的功能吗?
回复

使用道具 举报

发表于 2012-9-24 01:51:58 | 显示全部楼层
自己 发表于 2012-9-23 18:52
不是request.cpp中的函数完成post的功能吗?

至少没加“U-ApiKey: xxxxxxxxxxxxxx”进去
回复

使用道具 举报

 楼主| 发表于 2012-9-26 12:59:34 | 显示全部楼层
zcbzjx 发表于 2012-9-24 01:51
至少没加“U-ApiKey: xxxxxxxxxxxxxx”进去

char* auth = "285eff467ef4a7576a748ba0ee4e8954";在yeelinktest.ino里
        if (req->auth) {
                WiServer.print_P(apikey);
                WiServer.println(req->auth);
        }在Wiserver.cpp里

回复

使用道具 举报

 楼主| 发表于 2012-9-26 13:04:46 | 显示全部楼层
zcbzjx 发表于 2012-9-24 01:51
至少没加“U-ApiKey: xxxxxxxxxxxxxx”进去

char* auth = "285eff467ef4a7576a748ba0ee4e8954";在yeelinktest.ino里
        if (req->auth) {
                WiServer.print_P(apikey);
                WiServer.println(req->auth);
        }在Wiserver.cpp里

回复

使用道具 举报

发表于 2012-9-26 13:41:39 | 显示全部楼层
前面的"U-ApiKey:"在哪儿?"U-ApiKey: 285eff467ef4a7576a748ba0ee4e8954"应该在头文件内吧,没看见你构建
回复

使用道具 举报

 楼主| 发表于 2012-9-26 18:15:26 | 显示全部楼层
zcbzjx 发表于 2012-9-26 13:41
前面的"U-ApiKey:"在哪儿?"U-ApiKey: 285eff467ef4a7576a748ba0ee4e8954"应该在头文件内吧,没看见你构建

WiServer.print_P(apikey);就是这句
回复

使用道具 举报

发表于 2012-9-26 18:48:21 | 显示全部楼层
自己 发表于 2012-9-26 18:15
WiServer.print_P(apikey);就是这句

在string.c中找到了定义。。。不知道了,同求高手解答。。。
回复

使用道具 举报

 楼主| 发表于 2012-9-26 22:24:34 | 显示全部楼层
zcbzjx 发表于 2012-9-26 18:48
在string.c中找到了定义。。。不知道了,同求高手解答。。。

啊,你也不知道。。。
回复

使用道具 举报

发表于 2012-9-27 05:54:38 | 显示全部楼层
把你的模块给我,我帮你调试,hoho,我没这个模块,没法测试{:soso_e120:}
回复

使用道具 举报

 楼主| 发表于 2012-9-27 21:23:18 | 显示全部楼层
zcbzjx 发表于 2012-9-27 05:54
把你的模块给我,我帮你调试,hoho,我没这个模块,没法测试

我去问问我们同学他同意就送你~~
回复

使用道具 举报

发表于 2012-10-7 09:17:56 | 显示全部楼层
给你贴一段能用的代码吧。
  1. #include <SoftwareSerial.h>

  2. /*
  3. * Web Client
  4. *
  5. * A simple web client example using the WiShield 1.0
  6. */

  7. #include <WiShield.h>

  8. #define WIRELESS_MODE_INFRA        1
  9. #define WIRELESS_MODE_ADHOC        2

  10. // Wireless configuration parameters ----------------------------------------
  11. unsigned char local_ip[] = {192,168,42,2};        // IP address of WiShield
  12. unsigned char gateway_ip[] = {192,168,42,1};        // router or gateway IP address
  13. unsigned char subnet_mask[] = {255,255,255,0};        // subnet mask for the local network
  14. const prog_char ssid[] PROGMEM = {"AndroidAP"};                // max 32 bytes

  15. unsigned char security_type = 3;        // 0 - open; 1 - WEP; 2 - WPA; 3 - WPA2

  16. // WPA/WPA2 passphrase
  17. const prog_char security_passphrase[] PROGMEM = {"qwertyuiop"};        // max 64 characters

  18. // WEP 128-bit keys
  19. // sample HEX keys
  20. prog_uchar wep_keys[] PROGMEM = {        0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d,        // Key 0
  21.                                                                         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,        0x00,        // Key 1
  22.                                                                         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,        0x00,        // Key 2
  23.                                                                         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,        0x00        // Key 3
  24.                                                                 };

  25. // setup the wireless mode
  26. // infrastructure - connect to AP
  27. // adhoc - connect to another WiFi device
  28. unsigned char wireless_mode = WIRELESS_MODE_INFRA;

  29. unsigned char ssid_len;
  30. unsigned char security_passphrase_len;



  31. //---------------------------------------------------------------------------

  32. void setup()
  33. {
  34.         Serial.begin(9600);
  35.         WiFi.init();

  36. }

  37. unsigned char loop_cnt = 0;

  38. // The stack does not have support for DNS and therefore cannot resolve
  39. // host names. It needs actual IP addresses of the servers. This info
  40. // can be obtained by executing, for example, $ ping twitter.com on
  41. // a terminal on your PC
  42. //char google_ip[] = {74,125,67,100};        // Google
  43. //char twitter_ip[] = {202,136,56,203};        // Twitter
  44. char twitter_ip[] = {202,136,56,203};        // yeelink

  45. // This string can be used to send a request to Twitter.com to update your status
  46. // It will need a valid Authorization string which can be derived from your
  47. // Twitter.com username and password using Base64 algorithm
  48. // See, [url]http://en.wikipedia.org/wiki/Basic_access_authentication[/url]
  49. // You need to replace <-!!-Authorization String-!!-> with a valid string before
  50. // using this sample sketch.
  51. // The Content-Length variable should equal the length of the data string
  52. // In the example below, "Content-Length: 21" corresponds to "status=Ready to sleep"
  53. //const prog_char twitter[] PROGMEM = {"POST /statuses/update.xml HTTP/1.1\r\nAuthorization: Basic <-!!-Authorization String-!!->\r\nUser-Agent: uIP/1.0\r\nHost: twitter.com\r\nContent-Length: 21\r\nContent-Type: application/x-www-form-urlencoded\r\n\r\nstatus=Ready to sleep"};
  54. const prog_char twitter[] PROGMEM = {"POST /v1.0/device/113/sensor/393/datapoints HTTP/1.1 \r\nHost: api.yeelink.net\r\nU-ApiKey: 4bb0814c782a074e99e2e3c586bc6963\r\nContent-Length: 13\r\nConnection: close\r\n\r\n{"value":456}\r\n"};

  55. void loop()
  56. {
  57.         // if this is the first iteration
  58.         // send the request
  59.         if (loop_cnt == 0) {
  60.                 Serial.println(twitter);
  61.                 webclient_get(twitter_ip, 80, "/");

  62.                 loop_cnt = 1;
  63.         }
  64.        
  65.         WiFi.run();
  66. }
复制代码
回复

使用道具 举报

发表于 2012-10-7 09:19:49 | 显示全部楼层
需要注意的几点,
1. 注意wifi的加密方式和网络结构
2. 注意组装好要发送的http包的字符串结构
3. 尽量避免修改基础的函数,尽量从外面调用,避免对其他程序构成影响(基础函数可能被其他函数调用)
回复

使用道具 举报

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

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

Archiver|联系我们|极客工坊

GMT+8, 2024-4-28 04:03 , Processed in 0.041358 second(s), 18 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

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