Updating OTA is amazing

@monaco you mention passwords but that is not ESP related. Did you actually set a password for OTA?

1.6.12 is working fine for OTA updates.

for me, both OTA and blynk work perfectly individually but not together… It fails during the setup:

  • if I setup OTA first and then Blynk, blynk fail to connect to wifi
  • if I setup blynk first and then OTA , OTA fail to connect to wifi

any idea ?

edit :SOLVED !!

here is my setup code:

  Serial.begin(9600);
  Blynk.begin(auth, ssid2, pass);
  Serial.println("Booting");
  
  ArduinoOTA.begin();
  Serial.println("Ready");
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());
1 Like

@bobli sketch, MCU, Smartphone, local or cloud, IDE version, Blynk library version, Arduino core version, shoe size etc?

how?

I have posted my new setup code, if you initialise blynk first, for the ota part only you only need ArduinoOTA.begin(); and not the rest (you MUST delete the rest of OTA setup)

This indication sould be written in the frst post

1 Like

Any way to have OTA serial monitor, for remote development ?

edit: here is a dirty workaround, if anybody has a better solution he’s welcome

edit 2 : in fact it doesn’t work :confused: here is my own solution :smiley: .
I have opened another thread about this question here :slight_smile:

Code snippets should be formatted. Please edit your initial post:

How to do that:


 ``` cpp <--put 3 backticks BEFORE your code starts  ("cpp" means C++ language) 

   //Put your code here
   //..................
   //..................

 ``` <--insert 3 backticks AFTER your code

**This makes your code readable and with highlighted syntax, like this

↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

//comment goes here 
void helloWorld() { 
   String message =  "hello" + "world"; 
}
1 Like

Hi, I’d like to ask. How can I embed OTA code to my own sketch for me to be able to upload code over and over again through OTA. I’ve tried many times but always fail. :frowning:
Here’s my code with embedded OTA (BasicOTA.ino): Any help would be appreciated. Thanks Much.

This is Temperature and Humidity Sensor (DHT22)

#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>
#include <DHT.h>

// Replace with your network credentials
const char* ssid = "*******";
const char* password = "********";
const char* server = "********"; //server for my database where I store my Data.

#define DHTPIN 4 // what pin we're connected to
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
WiFiClient client;

int redPin = 12; //Red LED, connected to digital pin 12 (D6)
int grnPin = 14; //Green LED, connected to digital pin 14 (D5)
int bluPin = 13; //Blue LED, connected to digital pin 13 (D7)

int sensorPin = 4; //DHT22 Pin, connected to digital pin 4 (D2)

void setup() {
  Serial.begin(115200);
  Serial.println("Booting");
  WiFi.mode(WIFI_STA);
  delay(10);
  dht.begin();

  pinMode(redPin, OUTPUT);
  pinMode(grnPin, OUTPUT);
  pinMode(bluPin, OUTPUT);

  WiFi.begin(ssid, password);
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);

  WiFi.begin(ssid, password);
  while (WiFi.waitForConnectResult() != WL_CONNECTED) {
    Serial.println("Connection Failed! Rebooting...");
    delay(500);
    ESP.restart();
    Serial.print(".");
  }

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

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

  // No authentication by default
  // ArduinoOTA.setPassword((const char *)"123");

  ArduinoOTA.onStart([]() {
    Serial.println("Start");
  });
  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());

  Serial.println("");
  Serial.println("WiFi connected");
}

void loop() {
  ArduinoOTA.handle();

  float h = dht.readHumidity();
  float t = dht.readTemperature();
  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }

  Serial.print("Temperature: ");
  Serial.print(t);
  Serial.print(" ");
  Serial.print(h);
  Serial.println("% send to Server");
  delay(500);
  if (client.connect(server, 80)) {

    // Create a URL for the request
    String url = "/sample.php?temp_c=";
    url += (String(t));
    url += ("&humidity=");
    url += (String(h));
    //Serial.print("Requesting URL: ");
    //Serial.println(url);

    // This will send the request to the server
    client.print(String("GET ") + url + " HTTP/1.1\r\n" +
                 "Host: " + server + "\r\n" +
                 "Connection: close\r\n\r\n");

  }
  client.stop();

  if (t >= 27)
  {
    digitalWrite(redPin, HIGH);
    delay(300000);
    digitalWrite(redPin, LOW);
    digitalWrite(grnPin, LOW);
    digitalWrite(bluPin, LOW);

  }

  if ((t <= 27) && (t > 16))
  {
    digitalWrite(grnPin, HIGH);
    delay(300000);
    digitalWrite(grnPin, LOW);
    digitalWrite(redPin, LOW);
    digitalWrite(bluPin, LOW);

  }

  if (t <= 16)
  {
    digitalWrite(bluPin, HIGH);
    delay(300000);
    digitalWrite(bluPin, LOW);
    digitalWrite(grnPin, LOW);
    digitalWrite(redPin, LOW);

  }
  //Serial.println("Waiting...");
  // delay between updates
  //delay(10000);  //2 minute delay
}

@vanjsy it doesn’t work because your hardware is permanently asleep with those crazy delay(300000) entries you have in loop().

With or without Blynk you need SimpleTimer to call functions at intervals.


Hi Sir, thank you. How about this one Sir? Once uploaded via OTA I cant upload another code via OTA. I dont know if i made a mistake embedding the code to my own sketch.

#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>
#include <DHT.h>

const char* ssid = "***********";
const char* password = "*******";
cons char* server = "******************";

#define DHTPIN 4
#define DHTTYPE DHT22

const int sensorPin = 4; //DHT22 Sensor

DHT dht(DHTPIN, DHTTYPE);
WiFiClient client;


void setup(){
  Serial.begin(115200);
  Serial.println("Booting");
  WiFi.mode(WIFI_STA);
  delay(10);
  dht.begin();

  //WiFi.begin(ssid,password);
  //Serial.println();
  //Serial.println();
  //Serial.print("Connecting to ");
  //Serial.println(ssid);


  WiFi.begin(ssid,password);
  while(WiFi.waitForConnectResult() != WL_CONNECTED) {
    Serial.println("Connection Failed! Rebooting...");
    delay(500);
    Serial.print(".");
    ESP.restart();
  }

  ArduinoOTA.onStart([]() {
    Serial.println("Start");
  });
  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());
  
}

void loop() {

  float h = dht.readHumidity();
  float t = dht.readTemperature();
  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor");
  }else{
    Serial.print(t);
    Serial.print("\t");
    Serial.print(h);
    Serial.print("\t");
    delay(500);
  }

if (client.connect(server,80)) {
 
// We now create a URI for the request
  String url = "/sample.php?temp_c=";
  url += (String(t));
  url += ("&humidity=");
  url += (String(h));
  //Serial.print("Requesting URL: ");
  //Serial.println(url);
 
  // This will send the request to the server
  client.print(String("GET ") + url + " HTTP/1.1\r\n" +
               "Host: " + server + "\r\n" +
               "Connection: close\r\n\r\n");
}
 ArduinoOTA.handle(); 
}

I’ve been working in days but I can’t solved it. :frowning: Please help. Thanks much.

Try it with just the single line of ArduinoOTA.handle() in loop().

If it works, how can i embed my code to send my data into my database? The GET one.

Okay, I’ll post here once working without those code for my database, if I can upload random code again

SimpleTimer but get OTA working first.

Please Visit Advantages and Disadvantages of OTA Upload
and Write your Own experiences about advantage or disadvantage of OTA Uploading
Thank you.

@s.d.engineering, please do not post messages like this. maybe i’m wrong, but its kind of spamming, and without any reason. topic discussing ota already exists.

if you read through this topic which contains all the relevant information and user experience about ota, i’m sure you will find the answers for your questions, and will figure out what are the disadvantages (if any) using ota.

thanks!

1 Like

@wanek,
ok. maybe you right but in this topic users sent many post contain everything and any inf.
i read this topic but got confused.
you are a pro. user so i think it’s necessary to have a abstract topic about this new feature.

2 posts were merged into an existing topic: Advantages and Disadvantages of OTA Upload

@s.d.engineering

@wanek is correct… make note of time/date stamps before posting, and please do not “spam” old (or new) topics with unnecessary “over here” references to your new topic.

1 Like