Home > other >  My esp8266 kept to restart
My esp8266 kept to restart

Time:05-15

My small white, do you want to be a temperature and humidity meter, and then copy the code from the Internet, but esp8266 kept restart, wifi even once broken, online help, thank you!!!!!!
# define BLINKER_WIFI//define the wifi module
# define BLINKER_MIOT_SENSOR//small love classmate is defined as the sensor devices
#include //contains Blinker header file
#include //header file contains the DHT

2//# define DHTPIN definition DHT11 module connection pin io2

# define DHTTYPE DHT11//type temperature humidity module to the use of the DHT11

Char auth []="b21a410f19ad";//your device key
Char ssid []="V30";//your wifi name
Char PSWD []="123456789";//your wifi password

//component object data types, new role: the transmission of data to the mobile phone blinker app
HUMI BlinkerNumber HUMI (" ");//define humidity data key name
BlinkerNumber TEMP (" \ ");//define temperature data key name

DHT DHT (DHTPIN DHTTYPE);//object generated DHT, the type of parameter is the pin and DHT

Float humi_read=0, temp_read=0;//define floating-point global variable data storage temperature and humidity sensor is read

Void heartbeat ()
{
HUMI. Print (humi_read);//to the organiser blinkerapp humidity data
TEMP. Print (temp_read);//to blinkerapp back temperature data
}

Void miotQuery (int32_t queryCode)//small love classmate voice command feedback
{
BLINKER_LOG (" MIOT Query codes: ", queryCode);

Int humi_read_int=humi_read;//remove humidity floating-point
BlinkerMIOT. Humi (humi_read_int);//small love feedback humidity attribute
BlinkerMIOT. Temp (temp_read);//small love feedback temperature attribute
BlinkerMIOT. Print ();//send the above properties give a little love, make small love can receive the data of temperature and humidity

}


Void setup ()//put setup code here, run once;
{
//initialize the port
Serial.begin(115200);
BLINKER_DEBUG. Stream (Serial);
BLINKER_DEBUG. DebugAll ();
Blinker. Delay (2000);//delay function
Blinker.begin(auth, ssid, pswd);////initializes the blinker
Blinker.attachHeartbeat(heartbeat);//to pass the data of sensors to blinker app
DHT. The begin ();//initialize the DHT sensor
//in the callback function of feedback control state
BlinkerMIOT. AttachQuery (miotQuery);//each exhale love classmate, is called miotQuery () function

}
//loop through constant reading data of temperature and humidity sensors
Void loop ()//put your main code here, repeat:
{
Blinker.run();//run Blinker

Float. H=DHT readHumidity (); DHT11 sensor reading//humidity and assigned to h
Float t=DHT. ReadTemperature ();//read the temperature of the sensor and assigned to t
If (isnan (h) | | isnan (t))//determine whether success to temperature and humidity data read
{
Sensor BLINKER_LOG (" Failed to read the from DHT!" );//read the temperature and humidity failed!
}
The else//success read data
{
//print
BLINKER_LOG (" Humidity: "h," % ");
BLINKER_LOG (", "Temperature, t," * C ");

Humi_read=h;//to read to the humidity of assigned to global variables humi_read
Temp_read=t;//to read the temperature of the assigned to global variables temp_read
}
Blinker. Delay (2000);//delay function
}
  • Related