yeelink与WIFI Shield v3递增数数据上传测试

2014-06-241.4万
AI 快速预览详细 收起
本文介绍了使用WIFI Shield v3和yeelink进行递增数数据上传的方法。通过Grey大神的教程,可以轻松实现数据上传。需要注意的是,在配置完成后,将V3扩展板上的开关切到Arduino一边,才能让系统正常工作。此外,由于硬件推送速率比服务器保存数据的速率高,建议推送速率大于10秒。
用Grey大神发的帖子做的递增数wifi数据上传样例。Grey大神教程的连接:https://www.dfrobot.com.cn/commun ... viewthread&tid=2285

挺好用的,很好用的教程,配合上yeelink官方的一些配置信息很快的就能跑通。不过在通过手机配置路由器设置和外网ip设定,完成后,切断手机连接并且将V3扩展板上的开关切到Arduino一边,才能让系统正常工作。这个小细节需要注意一下。这点其实在其他小伙伴的帖子里面也有提到:https://mc.dfrobot.com.cn/forum.php?mod=viewthread&tid=2516&extra=page%3D1


yeelink与WIFI Shield v3递增数数据上传测试图1


这是我在yeelink上上传的递增数,不过,通过递增数的测试可以发现,yeelink服务器的采样率在10s,样例程序用了2s推送一个数据的形式往服务器上推递增数。硬件推送速率比服务器保存数据的速率高,所以,保存的实际有意义的数值,只有0,5,10,15,20.....其他数据全部都会被服务器滤掉。所以硬件节点端推送速率比10s长会比较合适!


以下是基于Grey大神的样例改的自己的yeelink,递增数样例=。=


void setup() {
  Serial.begin(115200);
  pinMode(13,OUTPUT);
}
int randomValue = 0;
void loop() {
  if(randomValue < 255)  randomValue ++;
  else randomValue = 0;
//  Serial.println(sensorValue, DEC);
  digitalWrite(13,HIGH);
  Serial.println("POST /v1.0/device/9351/sensor/19412/datapoints HTTP/1.1"); //“/device/4290/sensor/9970/”device,sensor 后面的数值用你自己的替代
  Serial.println("Host: api.yeelink.net");
  Serial.print("Accept: *");
  Serial.print("/");
  Serial.println("*");
  Serial.print("U-ApiKey: ");
  Serial.println("2400c0117d8c58b363f1b6e03132a9ee");   // 此处用你的APIKEY替代
  Serial.print("Content-Length: ");
  int thisLength = 10 + getLength(randomValue);
  Serial.println(thisLength);   
  Serial.println("Content-Type: application/x-www-form-urlencoded");
  Serial.println("Connection: close");
  Serial.println();
  Serial.print("{\"value\":");
  Serial.print(randomValue);  
  Serial.println("}");
  delay(1000);
  digitalWrite(13,LOW);
  delay(1000);
}

int getLength(int someValue) {
  // there's at least one byte:
  int digits = 1;
  // continually divide the value by ten,
  // adding one to the digit count for each
  // time you divide, until you're at 0:
  int dividend = someValue /10;
  while (dividend > 0) {
    dividend = dividend /10;
    digits++;
  }
  // return the number of digits:
  return digits;
}


创作许可协议

本项目采用 None(不开放任何权利,保留所有权利) 进行许可。

评论(3)
johnny_87
johnny_87
有没有通过wifi模块从yeelink上查询数据的样例
him
him
为什么我的数据无法传到yeelink呢?
lauren
lauren
作者
回复him
你第一次玩WIFI吗?这个问题太模糊了,要看你具体的配置,代码,和硬件情况了。原因可能有很多,能分享下你的项目和现在的东西吗?比如照片和你用的源码什么的,这样别人才有可能帮你哈
Grey
Grey
确实如此,yeelink官网给的也是10s一次的样例,但对于某些设备,采样频率太低了
Grey
Grey回复lauren
没有正式试过乐联,看过库,大同小异,上传的方式都一样,从样例上来看,采样率应该比yeelink高,毕竟是收费的
lauren
lauren
作者
回复Grey
乐联和其他家的物联网呢,也是一样的吗?。
- 没有更多了 -