Monitoring water pressure on my home domestic water system (pressure tank from a well)
Sketch & device work perfectly, updates to the Web Dashboard and to my Android phone
Alarm works correctly
Code seems to have all the necessary parts for OTA updates, but updated firmware version number doesn’t show on OTA screen. Have updated firmware number, saved, exported binary a couple of times, no luck. Also, when OTA shipment starts, under “Status” it says “Live” but “Target: 0 devices”!
Sketch didn’t have a BLYNK_DEVICE_NAME on the first iteration, so I made one up - no change to OTA behavior.
Can’t seem to find more specific instructions
• Sketch code. Code should be formatted as example below.
#define BLYNK_TEMPLATE_ID "TMPLcH71gq1m"
#define BLYNK_TEMPLATE_NAME "Water Pressure"
#define BLYNK_DEVICE_NAME "Bowen Water Pressure"
#define BLYNK_FIRMWARE_VERSION "0.1.3"
#define BLYNK_AUTH_TOKEN " my auth token was here, correctly "
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <ESP8266mDNS.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 32 // OLED display height, in pixels
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
BlynkTimer timer; // Create a timer object
// WiFi credentials
char ssid[] = " my ssid was here ";
char pass[] = " my pw was here ";
// Input/output pins
const int analogPin = A0;
#define alarmLEDPin 14
// Pressure range (psi)
float pressure;
const float pressure_comp_factor = 1.273; // Factor is linear; at gauge 70 psi it reads 55 psi, so factor = 70/55
const float minPressure = 0;
const float maxPressure = 100;
// Voltage range (VDC)
float voltage;
const float minVoltage = 0.306;
const float maxVoltage = 3.1;
// Blynk virtual pins
const int pressureVPin = V0;
// Other variables
int lowPressAlarmLimit = 10;
bool lowAlarm = false;
void myTimer() {
// Read voltage from analog input
voltage = analogRead(analogPin) * (3.1 / 1023.0);
// Scale voltage to pressure reading, apply compensation factor
pressure = pressure_comp_factor * ((voltage - minVoltage) * (maxPressure - minPressure) / (maxVoltage - minVoltage) + minPressure);
#define constrain(pressure,minPressure,maxPressure)
// Print pressure value to serial monitor
Serial.print("Pressure (psi): ");
Serial.println(pressure);
Serial.print("Voltage (VDC): ");
Serial.println(voltage);
Serial.print("Alarm State: ");
if (lowAlarm == false) {
Serial.println("NORMAL");
} else if (lowAlarm == true) {
Serial.println("ALARM");
}
// Send pressure value to Blynk
Blynk.virtualWrite(pressureVPin, pressure);
// Check for alarm, set LED, & send status to Blynk
if (pressure < lowPressAlarmLimit) {
lowAlarm = true;
digitalWrite(alarmLEDPin, HIGH);
} else if (pressure >= lowPressAlarmLimit) {
lowAlarm = false;
digitalWrite(alarmLEDPin, LOW);
}
Blynk.virtualWrite(V2, lowAlarm);
// Print to the OLED display
// Clear the buffer
display.clearDisplay();
display.setTextSize(1); // Normal 1:1 pixel scale
display.setTextColor(SSD1306_WHITE); // Draw white text
display.setCursor(0, 0); // Start at top-left corner
display.print(F("Water Pressure: "));
display.setTextSize(2);
display.setCursor(0, 9);
display.print(pressure);
display.print(" ");
if (lowAlarm == false) {
display.print(F("psi"));
}
if (lowAlarm == true) {
display.print("Alarm");
}
display.display();
}
BLYNK_CONNECTED() {
// request V1 value on connect
Blynk.syncVirtual(V1);
}
BLYNK_WRITE(V1) {
lowPressAlarmLimit = param.asInt(); // assigning incoming value from pin V1 to variable "lowPressAlarmLimit"
}
void setup() {
// Start serial communication
Serial.begin(9600);
// Connect to Blynk
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
char auth[] = "ZUzaF8TPs6GdTuoEC1K7M-rhNdZZE6CH"; // Replace with your Blynk auth token
char ssid[] = "Redish01"; // Replace with your Wi-Fi network name
char pass[] = "da7d7226bf"; // Replace with your Wi-Fi network password
Blynk.begin(auth, ssid, pass);
// Set Pin mode
pinMode(alarmLEDPin, OUTPUT);
// Set analog reference voltage to default (3.3V)
analogReference(DEFAULT);
// Setup a function to call the timer function every two seconds
timer.setInterval(2000L, myTimer);
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
Serial.println("SSD1306 allocation failed");
for (;;)
; // Don't proceed, loop forever
}
// Show initial display buffer contents on the screen -- Adafruit splash screen.
display.display();
delay(2000); // Pause for 2 seconds
// Clear the display buffer
display.clearDisplay();
// display.setTextColor(WHITE);
ArduinoOTA.setHostname("wemos-d1-mini-pro"); // Replace with your desired hostname
ArduinoOTA.onStart([]() {
String type;
if (ArduinoOTA.getCommand() == U_FLASH) {
type = "sketch";
} else { // U_SPIFFS
type = "filesystem";
}
// NOTE: if updating SPIFFS this would be the place to unmount SPIFFS using SPIFFS.end()
Serial.println("Start updating " + type);
});
ArduinoOTA.onEnd([]() {
Serial.println("\nEnd");
});
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
});
ArduinoOTA.onError([](ota_error_t error) {
Serial.printf("Error[%u]: ", error);
if (error == OTA_AUTH_ERROR) {
Serial.println("Auth Failed");
} else if (error == OTA_BEGIN_ERROR) {
Serial.println("Begin Failed");
} else if (error == OTA_CONNECT_ERROR) {
Serial.println("Connect Failed");
} else if (error == OTA_RECEIVE_ERROR) {
Serial.println("Receive Failed");
} else if (error == OTA_END_ERROR) {
Serial.println("End Failed");
}
});
ArduinoOTA.begin();
}
void loop() {
Blynk.run();
ArduinoOTA.handle();
timer.run();
}