// for yeelink api
#define APIKEY "bb802c56bdebfcf43d1d3843c432361d" // replace your yeelink api key here
//replace the device ID and sensor ID for temperature sensor.
#define DEVICEID0 358269 // replace your device ID
#define SENSORID0 407758 // replace your sensor ID
//replace the device ID and sensor ID for humidity sensor.
#define DEVICEID1 358269 // replace your device ID
#define SENSORID1 407760 // replace your sensor ID
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;
int DHT11PIN=4; //Connect D4 to data pin of DHT11
int humidity;
int temperature;
int post_number;
void setup()
{
wifi.begin();
bool b = wifi.Initialize(STA, SSID, PASSWORD);
if(!b)
{
DebugSerial.println("Init error");
}
delay(8000); //make sure the module can have enough time to get an IP address
String ipstring = wifi.showIP();
DebugSerial.println(ipstring); //show the ip address of module
}
void loop()
{
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)) {
// if there's incoming data from the net connection.
// send it out the serial port. This is for debugging
// purposes only:
if(wifi.ReceiveMessage(message))
{
DebugSerial.println(message);
}
wifi.Send(cmd);
// note the time that the connection was made:
lastConnectionTime = millis();
}
else {
// if you couldn't make a connection:
DebugSerial.println("connection failed");
DebugSerial.println("disconnecting.");
wifi.closeMux();
}
}
int getLength(int someValue) {
// there's at least one byte:
int digits = 1;
// continually divide the value by ten,
// adding one to the digit count for each
// time you divide, until you're at 0:
int dividend = someValue /10;
while (dividend > 0) {
dividend = dividend /10;
digits++;
}
// return the number of digits:
return digits;
}
int dht11_read(int pin)
{
// BUFFER TO RECEIVE
int bits[5];
int cnt = 7;
int idx = 0;