Help for OTA

Hardware: NodeMCU
Local Server: 0.30.0
Blynk Library: 0.5.0

Hi, I tried to search on the forum but I’m still confused. I loaded this sketch on NodeMCU and I received on serial (photo 1)… So I think it’s right.

#define BLYNK_PRINT Serial


#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <ESP8266mDNS.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>

#define ONE_WIRE_BUS 4
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
DeviceAddress termometroH2o;


char auth[] = "xxxxxxxxxxxxxxxxxx";
char ssid[] = "CasaBonch";
char pass[] = "xxxxxxxxxxxxx";

float allarmeTEMP;
float offsetTEMP;
float temperatura;
uint8_t statoluci;
int timer1;
int timer2;
int timer3;
uint8_t connessione = 0;

bool primaconn = true;
bool notifica = true;

BlynkTimer timer;

BLYNK_CONNECTED() {

  if ( primaconn == true ) {
    primaconn = false;
    Blynk.virtualWrite (V6, connessione);
  }
  else {
    connessione++;
    Blynk.virtualWrite (V6, connessione);
  }
}

BLYNK_WRITE(V1) {
  allarmeTEMP = param.asFloat();
  Blynk.virtualWrite (V2, allarmeTEMP);
}

BLYNK_WRITE(V3) {
  offsetTEMP = param.asFloat();
  Blynk.virtualWrite (V4, offsetTEMP);
}

//BLYNK_WRITE(V5) {
//  statoluci = param.asInt();
//}

//void luci() {
//
//  if (statoluci == 1) {
//    digitalWrite (2, HIGH);
//  }
//
//  if (statoluci == 0) {
//    digitalWrite (2, LOW);
//  }
//#if DEBUG_TEMP
//  //Serial.println (statoluci);
//#endif
//}

void letturaTEMP ()
{
  //  timer.restartTimer(timer1);
  delay(10);

  Serial.print("[");
  Serial.print(millis());
  Serial.print("] ");
  Serial.print("Richiesta temperature...");
  sensors.requestTemperatures(); // Send the command to get temperatures
  Serial.println("Fatto!");

  Serial.print("[");
  Serial.print(millis());
  Serial.print("] ");
  printTemperature(termometroH2o);
  Serial.println();
}

void InvioDati () {

  //  timer.restartTimer(timer1);
  timer.restartTimer(timer2);
  delay(10);

  Blynk.virtualWrite (V0, temperatura);

  if (temperatura < allarmeTEMP) {
    Blynk.setProperty(V0, "color", "#5291EF");
    notifica = true;
  }

  if (temperatura > allarmeTEMP) {
    Blynk.setProperty(V0, "color", "#D3435C");
    if ((temperatura > allarmeTEMP) && (notifica == true)) {
      Blynk.notify("ALLARME TEMPERATURA ACQUA ALTA");
      notifica = false;
    }
  }
}

void printTemperature(DeviceAddress deviceAddress)
{
  float tempC = sensors.getTempC(deviceAddress);
  temperatura = tempC + offsetTEMP;
  Serial.print("Temp C: ");
  Serial.print(temperatura);
}

void printAddress(DeviceAddress deviceAddress)
{
  for (uint8_t i = 0; i < 8; i++)
  {
    if (deviceAddress[i] < 16) Serial.print("0");
    Serial.print(deviceAddress[i], HEX);
  }
}


void setup()
{

  Serial.begin(9600);

  Serial.println("Booting");
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, pass);
  while (WiFi.waitForConnectResult() != WL_CONNECTED) {
    Serial.println("Connection Failed! Rebooting...");
    delay(5000);
    ESP.restart();
  }

  // Port defaults to 8266
  // ArduinoOTA.setPort(8266);

  // Hostname defaults to esp8266-[ChipID]
  // ArduinoOTA.setHostname("myesp8266");

  // No authentication by default
  // ArduinoOTA.setPassword("admin");

  // Password can be set with it's md5 value as well
  // MD5(admin) = 21232f297a57a5a743894a0e4a801fc3
  // ArduinoOTA.setPasswordHash("21232f297a57a5a743894a0e4a801fc3");

  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();
  Serial.println("Ready");
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());

  //  pinMode (5, OUTPUT);
  //  digitalWrite(5, LOW);


  Blynk.begin(auth, ssid, pass, IPAddress(192, 168, 0, 200), 8447);

  Blynk.syncVirtual (V1);
  Blynk.syncVirtual (V3);
  //  Blynk.syncVirtual (V5);

  Serial.print("[");
  Serial.print(millis());
  Serial.print("] ");
  Serial.println("Ricerca sonde...");
  sensors.begin();
  if ((sensors.getDeviceCount() == 0) || (sensors.getDeviceCount() > 1)) {
    Serial.print("[");
    Serial.print(millis());
    Serial.print("] ");
    Serial.print("trovate ");
    Serial.print(sensors.getDeviceCount(), DEC);
    Serial.println(" sonde.");
  }
  else {
    Serial.print("[");
    Serial.print(millis());
    Serial.print("] ");
    Serial.print("trovata ");
    Serial.print(sensors.getDeviceCount(), DEC);
    Serial.println(" sonda.");
  }
  Serial.print("[");
  Serial.print(millis());
  Serial.print("] ");
  Serial.print("Parasite power è: ");
  if (sensors.isParasitePowerMode()) Serial.println("ON");
  else Serial.println("OFF");

  if (!sensors.getAddress(termometroH2o, 0)) {
    Serial.print("[");
    Serial.print(millis());
    Serial.print("] ");
    Serial.println("Impossibile trovare l'indirizzo per la sonda 0");
  }

  Serial.print("[");
  Serial.print(millis());
  Serial.print("] ");
  Serial.print("Indirizzo Sonda 0: ");
  printAddress(termometroH2o);
  Serial.println();

  sensors.setResolution(termometroH2o, 11);

  Serial.print("[");
  Serial.print(millis());
  Serial.print("] ");
  Serial.print("Risoluzione Sonda 0: ");
  Serial.print(sensors.getResolution(termometroH2o), DEC);
  Serial.println();


  //  timer1 = timer.setInterval(5000L, luci);
  timer2 = timer.setInterval(300000L, letturaTEMP);
  timer3 = timer.setInterval(304000L, InvioDati);

}

void loop()
{
  Blynk.run();
  ArduinoOTA.handle();
  timer.run();
}

now what I have to do?
Modify the sketch “export demo / template esp8266”?
is it enough to change the “template_esp8266” section as I did with the arduinoOTA sketch?

Thank!

If all you want to do is have OTA facility then you should be finished now.

If you look at the ports available in the Arduino IDE you should now see the IP address of ESP.

2 things to remember, must have Serial Monitor closed when you do an OTA and after any Serial updates to the ESP (not OTA updates) you must reset the ESP before OTA will work.

2 things to remember, must have Serial Monitor closed when you do an OTA and after any Serial updates to the ESP (not OTA updates) you must reset the ESP before OTA will work.

thank you because I did not know it.

If you look at the ports available in the Arduino IDE you should now see the IP address of ESP.

It appears

if it is possible, I would like to load the sketch on the server and make sure that the hardware is updated automatically

Yes that’s possible. This is the basic code you need https://github.com/esp8266/Arduino/blob/master/libraries/ESP8266httpUpdate/examples/httpUpdate/httpUpdate.ino

And some docs to study https://arduino-esp8266.readthedocs.io/en/latest/ota_updates/readme.html#http-server