1 - Basic ESP8266 & ESP32 based Blynk with OTA template
Let’s start off with a basic starter sketch I use for all my ESP based projects… saves me a bit of typing
Nope, I haven’t yet set it up for automatic #ifdef
choice of ESP8266 or ESP32… I will leave that for you for now
#define BLYNK_PRINT Serial // This prints to Serial Monitor
// #define BLYNK_DEBUG // Optional, this enables more detailed prints
//// Pick one Blynk Device Library group or other
////----------
// #include <WiFi.h> // for ESP32
// #include <WiFiClient.h> // for ESP32
// #include <BlynkSimpleEsp32.h> // for ESP32
////----------
#include <ESP8266WiFi.h> // for ESP8266
#include <BlynkSimpleEsp8266.h> // for ESP8266
////----------
//// Pick one OTA Library or other
////----------
// #include <ESPmDNS.h> // For OTA w/ ESP32
////----------
#include <ESP8266mDNS.h> // For OTA w/ ESP8266
////----------
#include <WiFiUdp.h> // For OTA
#include <ArduinoOTA.h> // For OTA
char auth[] = "xxxxxxxxxx";
char ssid[] = "xxxxxxxxxx";
char pass[] = "xxxxxxxxxx";
char server[] = "xxx.xxx.xxx.xxx"; // IP for your Local Server
int port = 8080;
void setup() {
Serial.begin(9600); // BLYNK_PRINT data
WiFi.begin(ssid, pass);
Blynk.config(auth, server, port);
Blynk.connect();
ArduinoOTA.setHostname("Blynkified ESP Device"); // For OTA - Use your own device identifying name
ArduinoOTA.begin(); // For OTA
}
void loop() {
Blynk.run();
ArduinoOTA.handle(); // For OTA
}