caihuiwei 发表于 2014-10-22 00:29:50

使用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;
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界面



洞洞龟 发表于 2014-10-22 14:53:44

POST 后面不用加 http://api.yeelink.net试试

Youyou 发表于 2014-10-22 16:52:50

本帖最后由 Youyou 于 2014-10-22 16:54 编辑

试试这段代码:

//没有传感器,上传一个循环的1-10的数字
int i;

//for yeelink api
#define APIKEY   "*******" //改为自己的
#define DEVICEID   ****   //改为自己的
#define SENSORID   ****//改为自己的

void postData(int thisData) {
    Serial.print("POST /v1.0/device/");
    Serial.print(DEVICEID);
    Serial.print("/sensor/");
    Serial.print(SENSORID);
    Serial.print("/datapoints");
    Serial.println(" HTTP/1.1");
    Serial.println("Host: api.yeelink.net");
    Serial.print("Accept: *");
    Serial.print("/");
    Serial.println("*");
    Serial.print("U-ApiKey: ");
    Serial.println(APIKEY);
    Serial.print("Content-Length: ");
   
    int thisLength = 10 + getLength(thisData);
    Serial.print(thisLength);
    Serial.println();
    Serial.println("Content-Type: application/x-www-form-urlencoded");
    Serial.println();
    Serial.print("{"value":");
    Serial.print(thisData);
    Serial.println("}");
}



int getLength(int someValue) {
int digits = 1;
int dividend = someValue /10;
while (dividend > 0) {
    dividend = dividend /10;
    digits++;
}
return digits;
}



void setup(){
Serial.begin(115200);
}

void loop() {
for(i=1;i<10;i++){
postData(i);
delay(5*1000);
}
}

参考:http://blog.sina.com.cn/s/blog_54bf41d30101qpq4.html#commonComment

咆哮的过来 发表于 2014-10-23 13:23:56

我也是!数据都上传不了,好心塞

咆哮的过来 发表于 2014-10-23 13:25:02

我买的是seeeduino的板和wifi shield(好像叫wifly吧),总是failed connect

caihuiwei 发表于 2014-10-23 20:32:30

感谢楼上几位的回复,可是试了都不行啊,还是没有数据,直接放弃这块板了,买了其他的板再试,DFROBOT的客服做的太垃圾了,东西卖高价,客服对你不理不睬的

咆哮的过来 发表于 2014-10-23 22:13:25

caihuiwei 发表于 2014-10-23 20:32
感谢楼上几位的回复,可是试了都不行啊,还是没有数据,直接放弃这块板了,买了其他的板再试,DFROBOT的客 ...

买了什么板呢?试了有用我也去买!seeeduino的板和wifi都太难懂了,网上的例程都找不到

咆哮的过来 发表于 2014-10-23 22:13:26

caihuiwei 发表于 2014-10-23 20:32
感谢楼上几位的回复,可是试了都不行啊,还是没有数据,直接放弃这块板了,买了其他的板再试,DFROBOT的客 ...

买了什么板呢?试了有用我也去买!seeeduino的板和wifi都太难懂了,网上的例程都找不到
页: [1]
查看完整版本: 使用WIFI Shield V3上传温湿度到YEELINK,yeelink无数据