wemos d1 mini blynk? display temperature&humidity?
this is my code and it works to display c&% on display and blynk app and it notifies me when it starts and run time, is there a way to display runtime/uptime on the display and should i remove anything? maybe add in code to send email when offline for more than 5 minutes?
why does the screen go black when it updates?
what other data can i display on the screen? it will be used to monitor server room temperature, thanks
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include "Adafruit_SSD1306.h"
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <DHT.h>
#define OLED_RESET 0 // GPIO0
Adafruit_SSD1306 display(OLED_RESET);
#define BLYNK_PRINT Serial
#define DHTPIN D4
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "";
char pass[] = "";
BlynkTimer timer;
void notifyUptime()
{
long uptime = millis() / 60000L;
// Actually send the message.
// Note:
// We allow 1 notification per 15 seconds for now.
Blynk.notify(String("Running for ") + uptime + " minutes.");
}
void sendSensor()
{
float h = dht.readHumidity();
float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit
if (isnan(h) || isnan(t)) {
Serial.println("where is my DHT sensor!");
return;
}
// You can send any value at any time.
// Please don't send more that 10 values per second.
Blynk.virtualWrite(V5, h);
Blynk.virtualWrite(V6, t);
}
void setup()
{
// Debug console
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
// You can also specify server:
//Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8442);
//Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8442);
dht.begin();
// Notify immediately on startup
Blynk.notify("Device started");
// Setup a function to be called every minute
timer.setInterval(60000L, notifyUptime);
// Setup a function to be called every second
timer.setInterval(1000L, sendSensor);
}
void loop()
{
Blynk.run();
timer.run();
Serial.begin(115200);
dht.begin();
// by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3C (for the 64x48)
display.display();
delay(5000);
// Efface l'écran et positionne le curseur dans le coin supérieur gauche - clear display and set cursor on the top left corner
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(0,0);
float h = dht.readHumidity();
float t = dht.readTemperature();
float f = dht.readTemperature(true);
float bat = ESP.getVcc();// / 1024;
// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println("where is DHT sensor!");
return;
}
// Température en Celcius - Temperature in Celcius
// display.println("Temp.");
display.print(t);
display.println(" c");
// Humidité en % - Humidity in %
// display.println("Humidity");
//display.setTextSize(1);
display.print(h);
display.print(" %");
display.display();
}
Comments