8261| 7
|
使用WIFI Shield V3上传温湿度到YEELINK,yeelink无数据 |
弄了很久都没有弄好,现在只能找大家帮忙了,折腾好几个晚上了 程序: #include <dht11.h> dht11 DHT; float TEMP; int HUMI; int thisLength; int time=0; void setup() { Serial.begin(115200); pinMode(13,OUTPUT); } void loop() { int chk = DHT.read(4); TEMP = DHT.temperature; HUMI = DHT.humidity; TEMP = (int(TEMP * 100.0)) / 100.0; char tempStr[20]; floatToString(TEMP,tempStr); String data; data+=""; data+=String(tempStr); int t=data.length(); time=time+1; if (time%2==1) { Serial.println("POST http://api.yeelink.net/v1.0/device/14899/sensor/25567/datapoints/add"); Serial.println("Host: api.yeelink.net"); Serial.print("Accept: *"); Serial.print("/"); Serial.println("*"); Serial.print("U-ApiKey: "); Serial.println("9d2b482044dfaa42ad59806af17ae5c3"); // 此处用你的APIKEY替代 Serial.print("Content-Length: "); int thislength=17+t; Serial.println(thislength); Serial.println("Content-Type: application/x-www-form-urlencoded"); Serial.println("Connection: close"); Serial.println(); Serial.print("params={\"value\":"); Serial.print(TEMP); Serial.println("}"); delay(1000); digitalWrite(13,LOW); delay(5000); } else if(time%2==0) { Serial.println("POST http://api.yeelink.net/v1.0/device/14899/sensor/25786/datapoints/add"); Serial.println("Host: api.yeelink.net"); Serial.print("Accept: *"); Serial.print("/"); Serial.println("*"); Serial.print("U-ApiKey: "); Serial.println("9d2b482044dfaa42ad59806af17ae5c3"); Serial.print("Content-Length: "); int thislength=17+getLength(HUMI); Serial.println(thislength); Serial.println("Content-Type: application/x-www-form-urlencoded"); Serial.println("Connection: close"); Serial.println(); Serial.print("params={\"value\":"); Serial.print(HUMI); Serial.println("}"); delay(1000); digitalWrite(13,LOW); delay(5000); } } 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; } void floatToString(float in,char* out){ uint16_t Tc_100 = in*100; uint8_t whole, fract; whole = Tc_100/100 ; // separate off the whole and fractional portions fract = Tc_100 % 100; sprintf(out,"%d.%d",whole,fract); delay (10000); } COM的数据 POST http://api.yeelink.net/v1.0/device/14899/sensor/25567/datapoints/add Host: api.yeelink.net Accept: */* U-ApiKey: 9d2b482044dfaa42ad59806af17ae5c3 Content-Length: 21 Content-Type: application/x-www-form-urlencoded Connection: close params={"value":28.00} POST http://api.yeelink.net/v1.0/device/14899/sensor/25786/datapoints/add Host: api.yeelink.net Accept: */* U-ApiKey: 9d2b482044dfaa42ad59806af17ae5c3 Content-Length: 19 Content-Type: application/x-www-form-urlencoded Connection: close params={"value":71} POST http://api.yeelink.net/v1.0/device/14899/sensor/25567/datapoints/add Host: api.yeelink.net Accept: */* U-ApiKey: 9d2b482044dfaa42ad59806af17ae5c3 Content-Length: 21 Content-Type: application/x-www-form-urlencoded Connection: close params={"value":28.00} 下面是wifi sheild的设置界面的截图,连续好几天都折腾到深夜,还是无果,求大家帮忙看一下 YEELINK界面 |
本帖最后由 Youyou 于 2014-10-22 16:54 编辑 试试这段代码:
参考:http://blog.sina.com.cn/s/blog_5 ... .html#commonComment |
© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed