|
最近在试把传感器数据上传到物联网上去,然后把DS18B20的代码和YEELINK的代码混合了一下,拷到Arduino中,发现输出的数据一直是-127,我单独检查了接线和传感器,都没有问题,不知道是不是代码混合了就有问题了,求大神帮忙看看。代码如下:
#include <Ethernet.h>
#include <WiFi.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 <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 5
//replace 2633 3539 with ur device id and sensor id
yl_device ardu(4136); //此处替换为你的设备编号
yl_sensor therm(5895, &ardu);//此处替换为你的传感器编号
//replace first param value with ur u-apikey
yl_w5100_client client;
yl_messenger messenger(&client, "dc7d1c98898fa2e45xxxxxxx", "api.yeelink.net"); //此处替换为你自己的API KEY
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
void setup()
{
// 设置串口通信波特率
Serial.begin(9600);
// 初始库
sensors.begin();
//for output information
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xAA};
Ethernet.begin(mac);
}
void loop()
{
sensors.requestTemperatures(); // 发送命令获取温度
Serial.println(sensors.getTempCByIndex(0));
yl_value_data_point dp(sensors.getTempCByIndex(0));
therm.single_post(messenger, dp);
delay(1000);
}
|
|