极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 10160|回复: 2

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

[复制链接]
发表于 2016-2-20 13:54:26 | 显示全部楼层 |阅读模式
#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的程序,怎么能跑起来呢?串口打印看见温湿度数据了吗?
回复 支持 反对

使用道具 举报

 楼主| 发表于 2016-2-21 17:11:51 | 显示全部楼层
lm35只是一个变量而已,我想一块arduino板子能上传两个数据
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-4-27 02:18 , Processed in 0.054912 second(s), 18 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表