I wrote a code for Wemos D1 mini to connect to Blynk and read the temperature on the sensor DS18B20 and also go to Deep Sleep for a determinated time preserve power.
#define BLYNK_PRINT Serial
#include <BlynkSimpleEsp8266.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 2 // Your ESP8266 pin (ESP8266 GPIO 2 = WeMos D1 Mini pin D4)
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
// how long to sleep between checking and TX temp/batt values - in seconds
#define SLEEP_LENGTH 60
char auth[] = "xxx";
char ssid[] = "xxx";
char pass[] = "xxx";
SimpleTimer timer;
float roomTemperature; // Room temperature in F
void setup()
{
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
while (Blynk.connect() == false) {
// Wait until connected
}
sensors.begin(); // Starts the DS18B20 sensor(s).
sensors.setResolution(10);
{
sensors.requestTemperatures(); // Polls the sensors.
roomTemperature = sensors.getTempFByIndex(0) // Stores temperature. Change to getTempCByIndex(0) for celcius.
Blynk.virtualWrite(1, roomTemperature); // Send temperature to Blynk app virtual pin 1.
}
Blynk.run();
timer.run();
ESP.deepSleep(SLEEP_LENGTH * 1000000,WAKE_RF_DEFAULT); //try the default mode
delay(100);
}
void loop()
{
Blynk.run();
timer.run();
}