Need help to modify this sketch to implement multiple sensors. The alarm Levels should be Equal for all sensors, both high and low.
Have found the Project at: https://github.com/MLXXXp/Blynk_ESP8266_DS18B20
/*****************************************************************************
Arduino sketch to report the temperature using an ESP8266 with connected
Dallas DS18B20 sensor, for the Blynk system.
http://www.blynk.cc
*****************************************************************************/
/*
#define BLYNK_DEBUG
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <OneWire.h>
#include <DallasTemperature.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "myssid";
char pass[] = "mypassword";
// Temperature sensor full ID, including family code and CRC
DeviceAddress tempSensor = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
// Alert messages
char alertMessageLow[] = "House temperature is LOW!";
char alertMessageHigh[] = "House temperature is HIGH!";
// Pin used for the OneWire interface
#define ONEWIRE_PIN 4
OneWire oneWire(ONEWIRE_PIN);
DallasTemperature sensors(&oneWire);
SimpleTimer timer;
// Current temperature is a global so it can used to reset min/max temperatures
float currentTemp = 0;
// Minimum and maximum temperatures are set to out of range values that will be
// overridden the first time the actual temperature is read.
float minTemp = 10000.0;
float maxTemp = -10000.0;
int alertTempLow, alertTempHigh;
boolean lowAlertOn = false;
boolean highAlertOn = false;
// Virtual pins to send temperature reading (from device)
#define V_PIN_TEMP_A V0 // Value - Widget must allow color change
#define V_PIN_TEMP_B V1
// Virtual pins for alert temperature set points (to device)
#define V_PIN_ALERT_LOW V2
#define V_PIN_ALERT_HIGH V3
// Virtual pins for min/max temperatures (from device)
#define V_PIN_TEMP_MIN V4
#define V_PIN_TEMP_MAX V5
// Virtual pin for min/max temperature reset (to device)
#define V_PIN_MIN_MAX_RESET V6
#undef TEMP_IN_FAHRENHEIT
// Uncomment to use Fahrenheit or comment out for Celsius
#define TEMP_IN_FAHRENHEIT
// Hysteresis in degrees for alerts
#define ALERT_HYSTERESIS 1
// Temperature reading interval, in SECONDS
#define READ_INTERVAL 60
// Check interval for network connection, in milliseconds
// This should be a bit shorter than the Blynk reconnect poll time, which
// at the time of writing was 7 seconds
#define CONNECTION_CHECK_TIME 6500
// LED flash time for link down, in milliseconds
#define LED_DISC_FLASH_TIME 2000
// LED blink rate for "sensor not found" indication, in milliseconds
#define NO_SENSOR_BLINK_SPEED 500
// LED blink time for "sensor not found" indication, in milliseconds
#define NO_SENSOR_BLINK_TIME 200
// LED flash time for successful sensor read, in milliseconds
#define LED_READ_OK_FLASH_TIME 30
// LED flash time for sensor read error, in milliseconds
#define LED_READ_ERR_FLASH_TIME 5000
// Pin for LED indicator
#define LED_PIN 2
// The number of bits of temperature resolution
// 9 = 0.5, 10 = 0.25, 11 = 0.125, 12 = 0.0625 degrees Celsius
#define TEMPERATURE_RES_BITS 10
// Temperature conversion wait time, in milliseconds
#define READ_CONV_WAIT 800
// Pin values for indicator LED on and off
#define LED_ON LOW
#define LED_OFF HIGH
// Widget colors for alerts
#define ALERT_COLOR_OK "#23C48E" // Green
#define ALERT_COLOR_LOW "#5F7CD8" // Dark Blue
#define ALERT_COLOR_HIGH "#D3435C" // Red
//--------------------- SETUP -------------------
void setup() {
Serial.begin(9600);
pinMode(LED_PIN, OUTPUT);
indLEDoff();
sensors.begin();
if (!sensors.isConnected(tempSensor)) {
while (true) {
indLEDon();
delay(NO_SENSOR_BLINK_TIME);
indLEDoff();
delay(NO_SENSOR_BLINK_SPEED - NO_SENSOR_BLINK_TIME);
}
}
// Set the resolution of the temperature readings
sensors.setResolution(tempSensor, TEMPERATURE_RES_BITS);
// We'll do the "wait for conversion" ourselves using a timer,
// to avoid the call to delay() that the library would use
sensors.setWaitForConversion(false);
// Start up Blynk
Blynk.begin(auth, ssid, pass);
// Start the interval timer that checks if the connection is up
timer.setInterval(CONNECTION_CHECK_TIME, connectionCheck);
// Start the timer that handles the temperature read interval
timer.setInterval(READ_INTERVAL * 1000, startSensorRead);
}
//-----------------------------------------------
// Synchronize pins when connection comes up
BLYNK_CONNECTED() {
Blynk.syncAll();
}
// Set low alert temperature
BLYNK_WRITE(V_PIN_ALERT_LOW) {
alertTempLow = param.asInt();
}
// Set high alert temperature
BLYNK_WRITE(V_PIN_ALERT_HIGH) {
alertTempHigh = param.asInt();
}
// Reset minimum and maximum temperatures
BLYNK_WRITE(V_PIN_MIN_MAX_RESET) {
if (param.asInt()) { // if button pressed
minTemp = maxTemp = currentTemp;
Blynk.virtualWrite(V_PIN_TEMP_MIN, currentTemp);
Blynk.virtualWrite(V_PIN_TEMP_MAX, currentTemp);
}
}
// Blink the LED if the connection is down
void connectionCheck() {
if (Blynk.connected()) {
return;
}
indLEDon();
delay(LED_DISC_FLASH_TIME);
indLEDoff();
}
// Start a temperature read and the conversion wait timer
void startSensorRead() {
if (!Blynk.connected()) {
return;
}
sensors.requestTemperatures();
timer.setTimeout(READ_CONV_WAIT, sensorRead);
}
// Read the temperature from the sensor and perform the appropriate actions
void sensorRead() {
int16_t tempRaw;
if (!Blynk.connected()) {
return;
}
tempRaw = sensors.getTemp(tempSensor);
if (tempRaw != DEVICE_DISCONNECTED_RAW) {
#ifdef TEMP_IN_FAHRENHEIT
currentTemp = sensors.rawToFahrenheit(tempRaw);
#else
currentTemp = sensors.rawToCelsius(tempRaw);
#endif
// Send temperature value
Blynk.virtualWrite(V_PIN_TEMP_A, currentTemp);
Blynk.virtualWrite(V_PIN_TEMP_B, currentTemp);
// Low temperature alerts
if ((currentTemp <= alertTempLow) && !lowAlertOn) {
Blynk.setProperty(V_PIN_TEMP_A, "color", ALERT_COLOR_LOW);
Blynk.notify(alertMessageLow);
lowAlertOn = true;
}
else if (lowAlertOn && (currentTemp > alertTempLow + ALERT_HYSTERESIS)) {
Blynk.setProperty(V_PIN_TEMP_A, "color", ALERT_COLOR_OK);
lowAlertOn = false;
}
// High temperature alerts
if ((currentTemp >= alertTempHigh) && !highAlertOn) {
Blynk.setProperty(V_PIN_TEMP_A, "color", ALERT_COLOR_HIGH);
Blynk.notify(alertMessageHigh);
highAlertOn = true;
}
else if (highAlertOn && (currentTemp < alertTempHigh - ALERT_HYSTERESIS)) {
Blynk.setProperty(V_PIN_TEMP_A, "color", ALERT_COLOR_OK);
highAlertOn = false;
}
// Minimum and maximum temperatures
if (currentTemp < minTemp) {
minTemp = currentTemp;
Blynk.virtualWrite(V_PIN_TEMP_MIN, currentTemp);
}
if (currentTemp > maxTemp) {
maxTemp = currentTemp;
Blynk.virtualWrite(V_PIN_TEMP_MAX, currentTemp);
}
flashLED(LED_READ_OK_FLASH_TIME);
}
else {
flashLED(LED_READ_ERR_FLASH_TIME);
}
}
//--------------------- LOOP --------------------
void loop() {
Blynk.run();
timer.run();
}
//-----------------------------------------------
// Flash the indicator LED for the specified duration
void flashLED(long dur) {
timer.setTimeout(dur, indLEDoff);
indLEDon();
}
// Turn on the indicator LED
void indLEDon() {
digitalWrite(LED_PIN, LED_ON);
}
// Turn off the indicator LED
void indLEDoff() {
digitalWrite(LED_PIN, LED_OFF);
}