本帖最后由 a6641 于 2016-2-15 22:10 编辑
[pre lang=""]#include <Ethernet.h>
#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 2 // what pin we're connected to
int BH1750address = 0x23;
byte buff[2];
// Uncomment whatever type you're using!
//#define DHTTYPE DHT11 // DHT 11
#define DHTTYPE DHT22 // DHT 22 (AM2302)
//#define DHTTYPE DHT21 // DHT 21 (AM2301)
Adafruit_BMP085 bmp;
DHT dht(DHTPIN, DHTTYPE);
yl_device ardu(164872);
yl_sensor generic(183023, &ardu);
yl_sensor generic(183049, &ardu);
yl_sensor generic(183050, &ardu);
yl_sensor generic(381365, &ardu);
//replace first param value with ur u-apikey
yl_w5100_client client;
yl_messenger messenger(&client, "u-apikey", "api.yeelink.net");
personal_info_dp qinqingege("personal_info");
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();
}
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);
return 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!
if (isnan(t) || isnan(h)) {
Serial.println("Failed to read from DHT");
} else {
Serial.print("Humidity: ");
Serial.print(h);
Serial.print(" %\t");
}
}[/code] |