martincccc 发表于 2015-3-19 19:25
dht+uno+esp 能给个完整的程序研究一下吗?
//#include <Wire.h>
#include <DHT22.h>
#define BMP085_ADDRESS 0x77 // BMP085的I2C地址
#define OUT
#define REQUEST_RATE 15000 // (毫秒)yeelink要求数据传输间隔必须大于15秒
const unsigned char OSS = 0; // 采样设置
#define SSID "Tenda_F780C0" //type your own SSID name
#define PASSWORD "5416048388" //type your own WIFI password
#include "uartWIFI.h"
#include <SoftwareSerial.h>
WIFI wifi;
extern int chlID; //client id(0-4)
// for yeelink api
#define APIKEY "34bde5ff710374a81034bfbbe2981626" // replace your yeelink api key here
#define DEVICEID 2512 // replace your device ID
#define SENSORID0 31234 // sensor ID for temperature sensor of DHT22.3408
#define SENSORID1 32357 // sensor ID for humidity sensor of DHT22.3563
#define SENSORID2 31234 // sensor ID for perature sensor of BMP085.4381
#define SENSORID3 31234 // sensor ID for temperature sensor of BMP085.4387
char server[] = "api.yeelink.net"; // name address for yeelink API
unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds
boolean lastConnected = false; // state of the connection last time through the main loop
const unsigned long postingInterval = 5*1000; // delay between 2 datapoints, 5s
String returnValue = "";
boolean ResponseBegin = false;
//DHT22初始化
#define DHT22_PIN 12 //DHT22采用1线制,数据线连Aduino D9
DHT22 myDHT22(DHT22_PIN);
//定义使用函
short Btemperature;
long Bpressure;
float Temperature;
float Humidity;
int SendData;
int sensor=1;
void setup()
{
wifi.begin();
bool b = wifi.Initialize(STA, SSID, PASSWORD);
if(!b)
{
// Serial.println("Init error");
}
delay(8000); //make sure the module can have enough time to get an IP address
String ipstring = wifi.showIP();
//Serial.println(ipstring); //show the ip address of module
}
void loop()
{
// Btemperature = bmp085GetTemperature(bmp085ReadUT());
// Bpressure = bmp085GetPressure(bmp085ReadUP());
DHT22_ERROR_t errorCode;
delay(1000);
errorCode = myDHT22.readData();
Temperature=myDHT22.getTemperatureC();
Humidity=myDHT22.getHumidity();
//char message[400];
// if you're not connected, and ten seconds have passed since
// your last connection, then connect again and send data:
if((millis() - lastConnectionTime > postingInterval)) {
// static char buf[20];
switch(sensor){
case 1: //sensor 1 DHT22 Temperature
sensor=sensor+1;
sendData(DEVICEID,SENSORID0,Temperature*10);
break;
case 2: //sensor 2 DHT22 Humidity
sensor=1;
sendData(DEVICEID,SENSORID1,Humidity*10);
break;
/* case 3: //sensor 3 BMP085 Perature
sensor=sensor+1;
// get_send_string(buf,Bpressure/10);
sendData(DEVICEID,SENSORID2,23);//Bpressure/10);
break;
case 4: //sensor 4 BMP085 Temperature
sensor=1;
// get_send_string(buf,(Btemperature-40));
sendData(DEVICEID,SENSORID3,30);//(Btemperature-40));*/
}
}
/* if(wifi.ReceiveMessage(message))
{
DebugSerial.println(message);
}*/
delay(10);
}
|