林定祥 发表于 2015-3-19 10:46:34

ESP8266向yeelink发数据问题

ESP8266用http://www.geek-workshop.com/forum.php?mod=viewthread&tid=11266&highlight=ESP提供的库和方法向yeelink发数据,DTH有温度和湿度,只发一个时数据是连续的,但是循环分别发两个出现了,两个数据都不连续,一段时间温度发成功,湿度发布成功,一段是间湿度成功了,温度不成功,不知道问题出在哪儿了,我的yeelink网址是http://www.yeelink.net/devices/2512最下面的wifi的两个数据是通过ESP8266发的。

huan 发表于 2015-3-19 11:09:47

本帖最后由 huan 于 2015-3-19 11:16 编辑

按照要求上传数据间隔要10S,我不知道不同传感器的数据有没有这个要求,你的DHT22数据看起来不错,我用DHT11误差比较大,而且数据上下跳动厉害,小数部分根本没用的

林定祥 发表于 2015-3-19 13:24:58

是的,dht11精确到个位,dht22精确到小数后1位。

林定祥 发表于 2015-3-19 13:26:53

我用的是dht+uno+esp,请问你的系统是?

suoma 发表于 2015-3-19 15:02:32

网络没问题吗?

林定祥 发表于 2015-3-19 15:53:20

suoma 发表于 2015-3-19 15:02 static/image/common/back.gif
网络没问题吗?

没有问题,因为我如果发一个温度或湿度可以是连续的,现在在某一时刻要么是温度,要么是湿度,都有中断,但隔一段时间又能续上。

林定祥 发表于 2015-3-19 15:54:21

huan 发表于 2015-3-19 11:09 static/image/common/back.gif
按照要求上传数据间隔要10S,我不知道不同传感器的数据有没有这个要求,你的DHT22数据看起来不错,我用DHT11 ...

我用的是dht+uno+esp,请问你的系统是?

huan 发表于 2015-3-19 17:42:01

林定祥 发表于 2015-3-19 15:54 static/image/common/back.gif
我用的是dht+uno+esp,请问你的系统是?

一样,我看你的数据基本一分钟左右有一次,没什么问题啊

林定祥 发表于 2015-3-19 18:02:40

图像上面的4个使用lan送的,最后标有wifi的的两个是用esp送的,在曲线上拉一下能看出不连续,而且两条线是互斥的。

martincccc 发表于 2015-3-19 19:25:06

林定祥 发表于 2015-3-19 18:02 static/image/common/back.gif
图像上面的4个使用lan送的,最后标有wifi的的两个是用esp送的,在曲线上拉一下能看出不连续,而且两条线是互 ...

dht+uno+esp能给个完整的程序研究一下吗?

林定祥 发表于 2015-3-19 21:33:00

martincccc 发表于 2015-3-19 19:25 static/image/common/back.gif
dht+uno+esp能给个完整的程序研究一下吗?

好,明天贴。

林定祥 发表于 2015-3-20 08:24:41

martincccc 发表于 2015-3-19 19:25 static/image/common/back.gif
dht+uno+esp能给个完整的程序研究一下吗?

//#include <Wire.h>
#include <DHT22.h>
#define BMP085_ADDRESS 0x77// BMP085的I2C地址
#define OUT
#define REQUEST_RATE 15000 // (毫秒)yeelink要求数据传输间隔必须大于15秒
const unsigned char OSS = 0;// 采样设置


#define SSID       "Tenda_F780C0"               //type your own SSID name
#define PASSWORD   "5416048388"                              //type your own WIFI password
#include "uartWIFI.h"
#include <SoftwareSerial.h>
WIFI wifi;
extern int chlID;      //client id(0-4)
// for yeelink api
#define APIKEY         "34bde5ff710374a81034bfbbe2981626" // replace your yeelink api key here
#define DEVICEID      2512 // replace your device ID
#define SENSORID0       31234 // sensor ID for temperature sensor of DHT22.3408
#define SENSORID1       32357 // sensor ID for humidity sensor of    DHT22.3563
#define SENSORID2       31234 // sensor ID for perature sensor of    BMP085.4381
#define SENSORID3       31234 // sensor ID for temperature sensor of BMP085.4387
char server[] = "api.yeelink.net";   // name address for yeelink API

unsigned long lastConnectionTime = 0;          // last time you connected to the server, in milliseconds
boolean lastConnected = false;               // state of the connection last time through the main loop
const unsigned long postingInterval = 5*1000; // delay between 2 datapoints, 5s
String returnValue = "";
boolean ResponseBegin = false;



//DHT22初始化
#define DHT22_PIN 12 //DHT22采用1线制,数据线连Aduino D9
DHT22 myDHT22(DHT22_PIN);

//定义使用函
shortBtemperature;
long   Bpressure;
floatTemperature;
floatHumidity;
int    SendData;
int    sensor=1;

void setup()
{
   wifi.begin();
    bool b = wifi.Initialize(STA, SSID, PASSWORD);
      if(!b)
      {
//    Serial.println("Init error");
      }
      delay(8000);//make sure the module can have enough time to get an IP address
      String ipstring= wifi.showIP();
      //Serial.println(ipstring);                //show the ip address of module

}

void loop()
{
   // Btemperature = bmp085GetTemperature(bmp085ReadUT());
   // Bpressure = bmp085GetPressure(bmp085ReadUP());
   
    DHT22_ERROR_t errorCode;
    delay(1000);
    errorCode = myDHT22.readData();
    Temperature=myDHT22.getTemperatureC();
    Humidity=myDHT22.getHumidity();

   //char message;
   // if you're not connected, and ten seconds have passed since
// your last connection, then connect again and send data:
if((millis() - lastConnectionTime > postingInterval)) {
//static char buf;
    switch(sensor){
      case 1:          //sensor 1 DHT22 Temperature
            sensor=sensor+1;
            sendData(DEVICEID,SENSORID0,Temperature*10);
      break;
         
       case 2:    //sensor 2 DHT22 Humidity
         sensor=1;
         sendData(DEVICEID,SENSORID1,Humidity*10);
       break;
         
      /*case 3:    //sensor 3 BMP085 Perature
          sensor=sensor+1;
         // get_send_string(buf,Bpressure/10);
          sendData(DEVICEID,SENSORID2,23);//Bpressure/10);
      break;
            
      case 4:    //sensor 4 BMP085 Temperature
          sensor=1;
         // get_send_string(buf,(Btemperature-40));
          sendData(DEVICEID,SENSORID3,30);//(Btemperature-40));*/
             }
               }
/* if(wifi.ReceiveMessage(message))
{
      DebugSerial.println(message);   
}*/
delay(10);

}

林定祥 发表于 2015-3-20 08:25:23

林定祥 发表于 2015-3-20 08:24 static/image/common/back.gif
//#include
#include
#define BMP085_ADDRESS 0x77// BMP085的I2C地址


// this method makes a HTTP connection to the server:
void sendData(int device_id,int sensor_id,int thisData) {
// if there's a successful connection:
if (wifi.ipConfig(TCP,server, 80)) {
   //Serial.println("connecting...");
    // send the HTTP PUT request:
    String cmd;
      cmd = "POST /v1.0/device/";
      cmd += String(device_id);
      cmd += "/sensor/";
      cmd += String(sensor_id);
      cmd += "/datapoints";
      cmd += " HTTP/1.1\r\n";
      cmd += "Host: api.yeelink.net\r\n";
      cmd += "Accept: *";
      cmd += "/";
      cmd += "*\r\n";
      cmd += "U-ApiKey: ";
      cmd += APIKEY;
      cmd += "\r\n";
      cmd += "Content-Length: ";
      int thisLength = 11 + getLength(thisData);
      cmd += String(thisLength);
      cmd += "\r\n";
      cmd+= "Content-Type: application/x-www-form-urlencoded\r\n";
      cmd += "Connection: close\r\n";
      cmd += "\r\n";
      cmd += "{\"value\":";
      cmd += String(thisData/10);
      cmd += ".";
      cmd += String(thisData%10);
      cmd += "}\r\n";
      // Serial.println(cmd);
      wifi.Send(cmd);
    // note the time that the connection was made:
    lastConnectionTime = millis();
}
else {
    // if you couldn't make a connection:
//DebugSerial.println("connection failed");
//DebugSerial.println("disconnecting.");
    wifi.closeMux();
}
}

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;
}

林定祥 发表于 2015-3-20 08:27:05

林定祥 发表于 2015-3-20 08:25 static/image/common/back.gif
// this method makes a HTTP connection to the server:
void sendData(int device_id,int sensor_id,i ...

由于调试没有完成,因此程序较乱一些。

martincccc 发表于 2015-3-20 23:25:15

林定祥 发表于 2015-3-20 08:27 static/image/common/back.gif
由于调试没有完成,因此程序较乱一些。

谢谢。!~~~我研究研究。。
页: [1] 2
查看完整版本: ESP8266向yeelink发数据问题