a6641 发表于 2016-2-20 13:54:26

谁来帮我看一下DHT11的数据上传yeelink

#include <Ethernet.h>
#include <SPI.h>
#include <yl_data_point.h>
#include <yl_device.h>
#include <yl_w5100_client.h>
#include <yl_wifi_client.h>
#include <yl_messenger.h>
#include <yl_sensor.h>
#include <yl_value_data_point.h>
#include <yl_sensor.h>
#include "DHT.h"

#define DHT_PIN 2   // what pin we're connected to

// Uncomment whatever type you're using!
//#define DHTTYPE DHT11   // DHT 11
#define DHTTYPE DHT22   // DHT 22(AM2302)
//#define DHTTYPE DHT21   // DHT 21 (AM2301)

DHT dht(DHT_PIN, DHTTYPE);
//this example reads data from a lm35dz sensor, convert value to degree Celsius
//and then post it to yeelink.net

//replace 2633 3539 with ur device id and sensor id
yl_device ardu(164872);
yl_sensor therm(183050, &ardu);
yl_sensor therml(183023, &ardu);
//replace first param value with ur u-apikey
yl_w5100_client client;
yl_messenger messenger(&client, "67091e8255dc2f2d8e589974bc166531", "api.yeelink.net");


float lm35_convertor(int analog_num)
{
float h = dht.readHumidity();
float t = dht.readTemperature();

// check if returns are valid, if they are NaN (not a number) then something went wrong!
if (isnan(t) || isnan(h)) {
    Serial.println("Failed to read from DHT");
} else {
    Serial.print("Humidity: ");
    Serial.print(h);
    Serial.print(" %\t");
    Serial.print("Temperature: ");
    Serial.print(t);
    Serial.println(" *C");
}
}

int h;
int t;

void setup()
{
Serial.begin(9600);        //for output information
byte mac[] = {0xDA, 0xD9, 0x56, 0xF1, 0xd5, 0xA0};
Ethernet.begin(mac);
dht.begin();
}

void loop()
{
yl_value_data_point dph(lm35_convertor(h));
yl_value_data_point dpt(lm35_convertor(t));
therm.single_post(messenger, dph);
therml.single_post(messenger, dpt);
delay(1000 * 5);
}

林定祥 发表于 2016-2-21 16:15:26

中间这段是都LM35的程序,不是读DHT11的程序,怎么能跑起来呢?串口打印看见温湿度数据了吗?

a6641 发表于 2016-2-21 17:11:51

lm35只是一个变量而已,我想一块arduino板子能上传两个数据
页: [1]
查看完整版本: 谁来帮我看一下DHT11的数据上传yeelink