[pre lang="arduino" line="1" file="sketch_yeelink"]#include <Ethernet.h>
#include <LiquidCrystal.h> //LCD1602的库
#include <WiFi.h>
#include <SPI.h>
#include <HttpClient.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 <Wire.h>
#include <Adafruit_BMP085.h>
#include "DHT.h"
#include <math.h>
#define DHTPIN 7 // what pin we're connected to
int BH1750address = 0x23;
byte buff[2];
LiquidCrystal lcd1602(12, 11, 5, 4, 3, 2);//设置Arduino与LCD液晶屏的接口
// Uncomment whatever type you're using!
//#define DHTTYPE DHT11 // DHT 11
#define DHTTYPE DHT22 // DHT 22 (AM2302)
//#define DHTTYPE DHT21 // DHT 21 (AM2301)
char ssid[] = "HomeWiFi"; // your network SSID (name)
char pass[] = ""; // your network password
Adafruit_BMP085 bmp;
DHT dht(DHTPIN, DHTTYPE);
yl_device ardu(164872);
yl_sensor generic(183023, &ardu);
yl_sensor generic2(183049, &ardu);
yl_sensor generic3(183050, &ardu);
yl_sensor generic4(381365, &ardu);
//replace first param value with ur u-apikey
yl_w5100_client client;
yl_messenger messenger(&client, "u-apikey", "api.yeelink.net");
void setup() {
// put your setup code here, to run once:
Serial.begin(9600); //for output information
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xAA};
Ethernet.begin(mac);
bmp.begin();
dht.begin();
Wire.begin(); //初始化总线
Serial.print("yeelink:");
}
void loop() {
// put your main code here, to run repeatedly:
uint16_t val = 0;
BH1750_Init(BH1750address);
delay(200);
if (2 == BH1750_Read(BH1750address))
{
val = ((buff[0] << 8) | buff[1]) / 1.2;
}
Serial.print("Sensor value is: ");
Serial.println((int)val);
}
int BH1750_Read(int address) //
{
int i = 0;
Wire.beginTransmission(address);
Wire.requestFrom(address, 2);
while (Wire.available()) //
{
buff = Wire.read(); // receive one byte
i++;
}
Wire.endTransmission();
return i;
}
void BH1750_Init(int address)
{
Wire.beginTransmission(address);
Wire.write(0x10);//1lx reolution 120ms
Wire.endTransmission();
Serial.print("Temperature = ");
Serial.print(bmp.readTemperature());
Serial.println(" *C");
Serial.print("Pressure = ");
Serial.print(bmp.readPressure());
Serial.println(" Pa");
float h = dht.readHumidity();
// check if returns are valid, if they are NaN (not a number) then something went wrong!
Serial.print("Humidity: ");
Serial.print(h);
Serial.print(" %\t");
delay(5000);
}[/code] |