Hi everyone, I am new at the OTA thing and all the videos/articles I see consist of basiclaly just editing the loop code in the Edgent example. Below is my code, it’s a simple weather station. If i want to update the code, for example tune the barometric pressure a bit or what ever, how can I add the Blynk.Air functionality? The weather staion will be sealed in a box, so I want to be able to update code when necessary.
Normally I run it to take measurements and then deep sleep, but if pin 2 is high it stays on so it can be programmed OTA, this will be facilitated by a physical switch on my box.
Any help will be appreciated, thanks!
/*************************************************************
This is a simple demo of sending and receiving some data.
Be sure to check out other examples!
*************************************************************/
/* Fill-in information from Blynk Device Info here */
#define BLYNK_TEMPLATE_ID "TMPL289zSINuI"
#define BLYNK_TEMPLATE_NAME "Janre"
#define BLYNK_AUTH_TOKEN
#define BLYNK_FIRMWARE_VERSION "0.0.2"
#define BLYNK_TEMPLATE_ID "TMPL289zSINuI"
#define BLYNK_TEMPLATE_NAME "Janre"
#define BLYNK_PRINT Serial
//#define BLYNK_DEBUG
#define APP_DEBUG
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <DHT.h>
#include <Wire.h>
#include <Adafruit_BMP280.h>
Adafruit_BMP280 bmp; // I2C
#define DHTPIN 13 // DHT sensor pin
#define DHTTYPE DHT11 // DHT sensor type
DHT dht(DHTPIN, DHTTYPE);
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Janrewifi";
char pass[] = "Janre123";
BlynkTimer timer;
// Pin 2 definition
#define SKIP_DEEP_SLEEP_PIN 2
// This function sends DHT11 data to Blynk
void sendSensorData() {
// Read temperature and humidity from DHT sensor
float temperature = bmp.readTemperature();
float pressure = (bmp.readPressure() / 100.0) + 1000;
float altitude = bmp.readAltitude(1015);
float humidity = dht.readHumidity();
Serial.println("Start Measuring...");
// Send temperature and humidity data to Blynk
delay(1000);
Blynk.virtualWrite(V4, temperature); // Virtual pin V4 for temperature
delay(1000);
Serial.println(temperature);
delay(1000);
Blynk.virtualWrite(V0, humidity); // Virtual pin V0 for humidity
delay(1000);
Serial.println(humidity);
delay(1000);
Blynk.virtualWrite(V1, pressure); // Virtual pin V1 for pressure
delay(1000);
Serial.println(pressure);
delay(1000);
Blynk.virtualWrite(V2, altitude); // Virtual pin V2 for altitude
delay(1000);
Serial.println(altitude);
Serial.println("Measured");
// Check the state of pin 2
int pin2State = digitalRead(SKIP_DEEP_SLEEP_PIN);
if (pin2State == HIGH) {
// Pin 2 is high, skip deep sleep
Serial.println("Pin 2 is HIGH. Skipping deep sleep.");
} else {
// Pin 2 is low, enter deep sleep for 10 minutes (600 seconds)
Serial.println("Going to sleep...");
ESP.deepSleep(600e6); // Deep sleep for 10 minutes (in microseconds)
}
}
void setup() {
// Initialize serial communication
Serial.begin(9600);
// Initialize pin 2 as an input
pinMode(SKIP_DEEP_SLEEP_PIN, INPUT);
// Initialize BMP280 sensor
Serial.println(F("BMP280 test"));
unsigned status = bmp.begin(0x76);
if (!status) {
Serial.println(F("Could not find a valid BMP280 sensor, check wiring or try a different address!"));
while (1) delay(10);
}
// Set BMP280 sampling settings
bmp.setSampling(
Adafruit_BMP280::MODE_NORMAL,
Adafruit_BMP280::SAMPLING_X2,
Adafruit_BMP280::SAMPLING_X16,
Adafruit_BMP280::FILTER_X16,
Adafruit_BMP280::STANDBY_MS_500
);
// Initialize DHT sensor
dht.begin();
// Initialize Blynk
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
// Setup a function to be called every 2 seconds
timer.setInterval(2000L, sendSensorData);
}
void loop() {
// Run Blynk and the timer
Blynk.run();
timer.run();
}