BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

OTA No Response

My code is still a work in progress.
I have just added OTA to my code, but if i try to update,
just “Sending invitation to 192.168.1.81 …”
but get no response.

error message
/////////////////////////////////////////////////////////////////////////////////////////////////////////
Arduino: 1.8.13 (Windows 10), Board: “ESP32 Dev Module, Disabled, Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS), 240MHz (WiFi/BT), QIO, 80MHz, 4MB (32Mb), 921600, None”

Sketch uses 916642 bytes (69%) of program storage space. Maximum is 1310720 bytes.

Global variables use 43840 bytes (13%) of dynamic memory, leaving 283840 bytes for local variables. Maximum is 327680 bytes.

Sending invitation to 192.168.1.81 …An error occurred while uploading the sketch

.

21:26:30 [ERROR]: No response from the ESP

This report would have more information with
“Show verbose output during compilation”
option enabled in File -> Preferences.
///////////////////////////////////////////////////////////////

Hardware
ESP32
Pi local server (did not install docker when i set up the Pi)
Python 2.7 installed on laptop
my code

//A work in progress

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_LSM303_U.h>
#include <HTTPClient.h>
#define BLYNK_PRINT Serial
#include <ArduinoOTA.h>
#include <ArduinoJson.h>
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>

char auth[] = "o7sRv-CLmo-iD-vQFfvqwIs8tn9XuTyb";
char ssid[] = "FRITZ!Box 7490";
char pass[] = "40253267300484638395";
BlynkTimer timer;  
  String    payload;

int relayA = 23; // NOTE this pin gpio
int relayB = 3; // NOTE this pin gpio
int relayC = 9; // NOTE this pin gpio
int relayD = 16; // NOTE this pin gpio
float DegreesX;
float DegreesY;
float sun_altitude;
float sun_azimuth;
int windy;
//int event;
//xyz



/* Assign a unique ID to this sensor at the same time */
Adafruit_LSM303_Accel_Unified accel = Adafruit_LSM303_Accel_Unified(54321);

  

void setup()
{
  
    pinMode(relayA,OUTPUT);
  pinMode(relayB,OUTPUT);
  pinMode(relayC,OUTPUT);
  pinMode(relayD,OUTPUT);

  digitalWrite (relayA, HIGH);
  digitalWrite (relayB, HIGH);
  digitalWrite (relayC, HIGH);
  digitalWrite (relayD, HIGH);
  // Debug console
  Serial.begin(9600);

  Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,120), 8080);
  delay (3000);
   int rssi = WiFi.RSSI() ; //get signal strenth in DB
 Blynk.virtualWrite(V51,rssi);
 //Blynk.virtualWrite(V0, 1); //update for webhooks
 Serial.println("Booting");
 APIupdate(); //call API to populate payload data
 ////////////////
// timer.setInterval(1000L, takeReadings);
 timer.setInterval(2500L, updateDisplay);
 timer.setInterval(1800*1000L, APIupdate);// set to 12 seconds for testing set to 30 mins for use
//must change to 1800*1000L 30min/////
 ArduinoOTA.onError([](ota_error_t error) { ESP.restart(); });
  ArduinoOTA.setHostname("SunTracker");
  ArduinoOTA.begin();


}

void loop()
{
  Blynk.run();
  timer.run(); // Initiates BlynkTimer
}

void updateDisplay(){
 int rssi = WiFi.RSSI() ; //get signal strenth in DB
 Blynk.virtualWrite(V51,rssi);
   if(!accel.begin())
  {
        Blynk.virtualWrite(V1,"Ooops, no LSM303 detected ... Check your wiring!");
    while(1);
  }
  
sensors_event_t event;  //im unable to move or remove this line due to compile errror
accel.getEvent(&event);
 
 float rawAngleX = event.acceleration.x;
 DegreesX = (rawAngleX * 9);
 map(DegreesX, -10, 10, 0, 180);
 float rawAngleY = event.acceleration.y;
 DegreesY = (rawAngleY * 9);
  map(DegreesY, -10, 10, 0, 180);
  
 Blynk.virtualWrite(V1,"DegreesX; ");
  Blynk.virtualWrite(V1,DegreesX);
  Blynk.virtualWrite(V1,"    RawAngle X; ");
  Blynk.virtualWrite(V1,rawAngleX);
   
  
  Blynk.virtualWrite(V1,"\n "); //new line
  
 Blynk.virtualWrite(V1,"DegreesY: ");
  Blynk.virtualWrite(V1,DegreesY);
  Blynk.virtualWrite(V1,"     RawAngle Y: ");
  Blynk.virtualWrite(V1,rawAngleY);
 Blynk.virtualWrite(V1,"\n "); //new line
 
 Blynk.virtualWrite(V1,"Suns Altitude: ");
//   Blynk.virtualWrite(V1,sun_altitude, 0);
Blynk.virtualWrite(V1,sun_altitude);
  Blynk.virtualWrite(V1,"\n "); //new line
 Blynk.virtualWrite(V4,sun_altitude);
 
 Blynk.virtualWrite(V1,"Azimuth: ");
  // Blynk.virtualWrite(V1,sun_azimuth, 0);
   Blynk.virtualWrite(V1,sun_azimuth);
   Blynk.virtualWrite(V5,sun_azimuth);
 
 
  Blynk.virtualWrite(V1,"\n "); //new line
  Blynk.virtualWrite(V1,"\n "); //new line
}

/*
void takeReadings(){ //every X.. ms

 //Get a new sensor event 
 sensors_event_t event;
 accel.getEvent(&event);
  //map(value, fromLow, fromHigh, toLow, toHigh)
  DegreesX = event.acceleration.x;
  map(event.acceleration.x, -10, 10, 0, 180);
  DegreesY = event.acceleration.y;
  map(event.acceleration.y, -10, 10, 0, 180);
  
}
*/

void APIupdate(){ 
  HTTPClient http;  //Declare an object of class HTTPClient
//new API key
    http.begin("https://api.ipgeolocation.io/astronomy?apiKey=5a0ece4d1b7f49aca1b86d8e78dcebd2&lat=50.3&long=-4.9");  //Specify request destination
    int httpCode = http.GET();     //Send the request
    if (httpCode > 0) { //Check the returning code
   payload = http.getString();   //Get the request response payload
      }

    http.end();   //Close connection
    Serial.println(payload);
const size_t capacity = JSON_OBJECT_SIZE(2) + JSON_OBJECT_SIZE(18) + 320;
DynamicJsonDocument doc(capacity);
deserializeJson(doc, payload);

float location_latitude = doc["location"]["latitude"]; // 
float location_longitude = doc["location"]["longitude"]; // 
const char* date = doc["date"]; // "2020-09-30"
const char* current_time = doc["current_time"]; // "19:06:46.27"
const char* sunrise = doc["sunrise"]; // "07:18"
const char* sunset = doc["sunset"]; // "18:59"
const char* sun_status = doc["sun_status"]; // "-"
const char* solar_noon = doc["solar_noon"]; // "13:09"
const char* day_length = doc["day_length"]; // "11:41"
 sun_altitude = doc["sun_altitude"]; // -2.0393480763745733
float sun_distance = doc["sun_distance"]; // 149810371.16339526
 sun_azimuth = doc["sun_azimuth"]; // 267.4597814448824
const char* moonrise = doc["moonrise"]; // "19:02"
const char* moonset = doc["moonset"]; // "05:23"
const char* moon_status = doc["moon_status"]; // "-"
float moon_altitude = doc["moon_altitude"]; // 1.0738509355096701
float moon_distance = doc["moon_distance"]; // 402084.5279459498
float moon_azimuth = doc["moon_azimuth"]; // 100.76227521973334
float moon_parallactic_angle = doc["moon_parallactic_angle"]; // -38.56220668133565
Serial.println(sun_altitude);
Serial.println(sun_azimuth);
//Serial.println(location_latitude);
}


BLYNK_WRITE(V22)// if button on APP pressed, flattern out solar panel to minimise wind damage
{
    windy = param.asInt();
    ////check if windy
//move up if windy switch and if pannel is less than horizontal
if (windy == 1){
  Blynk.virtualWrite(V1,"Manual Windy");
   digitalWrite (relayA,LOW); //move UP
    //digitalWrite (relayC, LOW);
}else{
   digitalWrite (relayA, HIGH);
   // digitalWrite (relayC, HIGH);
}
if (windy ==1 && DegreesY <=178){ //if set too east move
  digitalWrite (relayC, LOW);
}else{
  digitalWrite (relayC, HIGH);
}
if (windy ==1 && DegreesY >=182){ //if set too west move
  digitalWrite (relayD, LOW);
}else{
  digitalWrite (relayD, HIGH);
}
}
/*
//////////move panel 
void movePannel(){
if (DegreesX >=0){
  digitalWrite (relayA, HIGH);
}
if (DegreesY >=178){
  digitalWrite (relayC, HIGH);
}
if (DegreesY >=183){
  digitalWrite (relayD, HIGH);
}
  
////check if day or night

////check elivation


////check Azimuth
}
*/

any ideas?
many thanks

HI,

First step should be to start with a very, very basic sketch (eg Blink) + the ArduinOTA code. Test that and get it working without the main sketch, it will be much simpler to see what is going on, and troubleshoot.

Having said all that . . . you need to include ArduinoOTA.handle(); in your loop (first line of loop always works for me).

void loop() {
  ArduinoOTA.handle();                                    // OTA first line of loop()
  Blynk.run();
  timer.run();
}

After the first time you upload the code (USB serial) you MUST reset the device for OTA to begin.

Shut and restart the IDE and you should see the device as a network port.

billd

1 Like

Thankyou.
so started again with blank OTA
adding and testing parts of my script.
this code is working

#define BLYNK_PRINT Serial
#include <ArduinoOTA.h>
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>

#include <HTTPClient.h>
#include <ArduinoJson.h>
char auth[] = "************************";
char ssid[] = "*********************************";
char pass[] = "*********************";
BlynkTimer timer;  
  String    payload;
  float DegreesX;
float DegreesY;
float sun_altitude;
float sun_azimuth;
int windy;
//int event;
//xyz

void setup()
{
  // Debug console
 Serial.begin(9600);
 Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,120), 8080);
ArduinoOTA.onError([](ota_error_t error) { ESP.restart(); }); //MUST be AFTER Blynl.begin
 ArduinoOTA.setHostname("SunTracker");
 ArduinoOTA.begin();
// Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,120), 8080);
 // delay (3000);
// APIupdate(); //call API to populate payload data
 ////////////////
// timer.setInterval(1000L, takeReadings);
// tiimer.setInterval(2500L, updateDisplay);
 timer.setInterval(1800*1000L, APIupdate);// set to 12 seconds for testing set to 30 mins for use
//must change to 1800*1000L 30min/////
 APIupdate(); //call API to populate payload data
}

void loop()
{
  ArduinoOTA.handle(); //MUST be BEFORE Blynk.run
  Blynk.run();
   timer.run(); // Initiates BlynkTimer
}


void APIupdate(){ 
  HTTPClient http;  //Declare an object of class HTTPClient
//new API key
    http.begin("https://api.ipgeolocation.io/astronomy?apiKey=5a0ece4d1b7f49aca1b86d8e78dcebd2&lat=50.3&long=-4.9");  //Specify request destination
    int httpCode = http.GET();     //Send the request
    if (httpCode > 0) { //Check the returning code
   payload = http.getString();   //Get the request response payload
      }

    http.end();   //Close connection
    Serial.println(payload);
const size_t capacity = JSON_OBJECT_SIZE(2) + JSON_OBJECT_SIZE(18) + 320;
DynamicJsonDocument doc(capacity);
deserializeJson(doc, payload);

float location_latitude = doc["location"]["latitude"]; // 
float location_longitude = doc["location"]["longitude"]; // 
const char* date = doc["date"]; // "2020-09-30"
const char* current_time = doc["current_time"]; // "19:06:46.27"
const char* sunrise = doc["sunrise"]; // "07:18"
const char* sunset = doc["sunset"]; // "18:59"
const char* sun_status = doc["sun_status"]; // "-"
const char* solar_noon = doc["solar_noon"]; // "13:09"
const char* day_length = doc["day_length"]; // "11:41"
 sun_altitude = doc["sun_altitude"]; // -2.0393480763745733
float sun_distance = doc["sun_distance"]; // 149810371.16339526
 sun_azimuth = doc["sun_azimuth"]; // 267.4597814448824
const char* moonrise = doc["moonrise"]; // "19:02"
const char* moonset = doc["moonset"]; // "05:23"
const char* moon_status = doc["moon_status"]; // "-"
float moon_altitude = doc["moon_altitude"]; // 1.0738509355096701
float moon_distance = doc["moon_distance"]; // 402084.5279459498
float moon_azimuth = doc["moon_azimuth"]; // 100.76227521973334
float moon_parallactic_angle = doc["moon_parallactic_angle"]; // -38.56220668133565
Serial.println(sun_altitude);
Serial.println(sun_azimuth);
Blynk.virtualWrite(V1,sun_altitude);
Blynk.virtualWrite(V1,"\n "); //new line
Blynk.virtualWrite(V1,sun_azimuth);
//Serial.println(location_latitude);
}

the next intagration runs for abot 10 seconds then Blynk disconnects, OTA will not update, but IP address pings OK.

#define BLYNK_PRINT Serial
#include <ArduinoOTA.h>
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>

#include <HTTPClient.h>
#include <ArduinoJson.h>

//LSM303
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_LSM303_U.h>
Adafruit_LSM303_Accel_Unified accel = Adafruit_LSM303_Accel_Unified(54321);


char auth[] = "*************************";
char ssid[] = "*****************";
char pass[] = "**************************";
BlynkTimer timer;  
  String    payload;
  float DegreesX;
float DegreesY;
float sun_altitude;
float sun_azimuth;
int windy;
//int event;
//xyz

void setup()
{
  // Debug console
 Serial.begin(9600);
 Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,120), 8080);
ArduinoOTA.onError([](ota_error_t error) { ESP.restart(); }); //MUST be AFTER Blynl.begin
 ArduinoOTA.setHostname("SunTracker");
 ArduinoOTA.begin();
// Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,120), 8080);
 // delay (3000);
// APIupdate(); //call API to populate payload data
 ////////////////
// timer.setInterval(1000L, takeReadings);
 timer.setInterval(2500L, updateDisplay);
 timer.setInterval(1800*1000L, APIupdate);// set to 12 seconds for testing set to 30 mins for use
//must change to 1800*1000L 30min/////
 APIupdate(); //call API to populate payload data
}

void loop()
{
  ArduinoOTA.handle(); //MUST be BEFORE Blynk.run
  Blynk.run();
   timer.run(); // Initiates BlynkTimer
}


void APIupdate(){ 
  HTTPClient http;  //Declare an object of class HTTPClient
//new API key
    http.begin("https://api.ipgeolocation.io/astronomy?apiKey=5a0ece4d1b7f49aca1b86d8e78dcebd2&lat=50.3&long=-4.9");  //Specify request destination
    int httpCode = http.GET();     //Send the request
    if (httpCode > 0) { //Check the returning code
   payload = http.getString();   //Get the request response payload
      }

    http.end();   //Close connection
    Serial.println(payload);
const size_t capacity = JSON_OBJECT_SIZE(2) + JSON_OBJECT_SIZE(18) + 320;
DynamicJsonDocument doc(capacity);
deserializeJson(doc, payload);

float location_latitude = doc["location"]["latitude"]; // 
float location_longitude = doc["location"]["longitude"]; // 
const char* date = doc["date"]; // "2020-09-30"
const char* current_time = doc["current_time"]; // "19:06:46.27"
const char* sunrise = doc["sunrise"]; // "07:18"
const char* sunset = doc["sunset"]; // "18:59"
const char* sun_status = doc["sun_status"]; // "-"
const char* solar_noon = doc["solar_noon"]; // "13:09"
const char* day_length = doc["day_length"]; // "11:41"
 sun_altitude = doc["sun_altitude"]; // -2.0393480763745733
float sun_distance = doc["sun_distance"]; // 149810371.16339526
 sun_azimuth = doc["sun_azimuth"]; // 267.4597814448824
const char* moonrise = doc["moonrise"]; // "19:02"
const char* moonset = doc["moonset"]; // "05:23"
const char* moon_status = doc["moon_status"]; // "-"
float moon_altitude = doc["moon_altitude"]; // 1.0738509355096701
float moon_distance = doc["moon_distance"]; // 402084.5279459498
float moon_azimuth = doc["moon_azimuth"]; // 100.76227521973334
float moon_parallactic_angle = doc["moon_parallactic_angle"]; // -38.56220668133565
Serial.println(sun_altitude);
Serial.println(sun_azimuth);
Blynk.virtualWrite(V1,sun_altitude);
Blynk.virtualWrite(V1,"\n "); //new line
Blynk.virtualWrite(V1,sun_azimuth);
//Serial.println(location_latitude);
}

void updateDisplay(){
  /*
 int rssi = WiFi.RSSI() ; //get signal strenth in DB
 Blynk.virtualWrite(V51,rssi);
   if(!accel.begin())
  {
        Blynk.virtualWrite(V1,"Ooops, no LSM303 detected ... Check your wiring!");
    while(1);
  }
  */
sensors_event_t event;  //im unable to move or remove this line due to compile errror
accel.getEvent(&event);
 /*
 float rawAngleX = event.acceleration.x;
 DegreesX = (rawAngleX * 9);
 map(DegreesX, -10, 10, 0, 180);
 float rawAngleY = event.acceleration.y;
 DegreesY = (rawAngleY * 9);
  map(DegreesY, -10, 10, 0, 180);
  
 Blynk.virtualWrite(V1,"DegreesX; ");
  Blynk.virtualWrite(V1,DegreesX);
  Blynk.virtualWrite(V1,"    RawAngle X; ");
  Blynk.virtualWrite(V1,rawAngleX);
   
  
  Blynk.virtualWrite(V1,"\n "); //new line
  
 Blynk.virtualWrite(V1,"DegreesY: ");
  Blynk.virtualWrite(V1,DegreesY);
  Blynk.virtualWrite(V1,"     RawAngle Y: ");
  Blynk.virtualWrite(V1,rawAngleY);
 Blynk.virtualWrite(V1,"\n "); //new line
 
 Blynk.virtualWrite(V1,"Suns Altitude: ");
//   Blynk.virtualWrite(V1,sun_altitude, 0);
Blynk.virtualWrite(V1,sun_altitude);
  Blynk.virtualWrite(V1,"\n "); //new line
 Blynk.virtualWrite(V4,sun_altitude);
 
 Blynk.virtualWrite(V1,"Azimuth: ");
  // Blynk.virtualWrite(V1,sun_azimuth, 0);
   Blynk.virtualWrite(V1,sun_azimuth);
   Blynk.virtualWrite(V5,sun_azimuth);
 
 
  Blynk.virtualWrite(V1,"\n "); //new line
  Blynk.virtualWrite(V1,"\n "); //new line
  */
}

any help will be great.

Blynk.begin is a blocking function.
Use wifi.begin to join the network and Blynk.config to join the server.

This way will allow the OTA UPDATES.

Thank you
So remove

Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,120), 8080);

And replace with

wifi.begin ();
Blynk.config(auth, ssid, pass, IPAddress(192,168,1,120), 8080)

Try adding these two blocks of code into your void setup begore your ArduinoOTA.begin

  ArduinoOTA.onStart([]() {
  Serial.println("OTA Starting"); 
  });
  
  ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
  Serial.printf("Progress: %u%%\r", (progress / (total / 100))); Blynk.run();
  }); // Blynk.run during the OTA process to avoid Blynk disconnection

This should print “OTA Starting” at the beginning of the OTA upload then show you the progress percentage in the serial monitor.
It will also execute a Blynk.run at each step to avoid a disconnection.

Pete.

i added the code and now get error

‘wifi’ was not declared in this scope

#define BLYNK_PRINT Serial
#include <ArduinoOTA.h>
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>

#include <HTTPClient.h>
#include <ArduinoJson.h>

//LSM303
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_LSM303_U.h>
Adafruit_LSM303_Accel_Unified accel = Adafruit_LSM303_Accel_Unified(54321);


char auth[] = "**************";
char ssid[] = "*****************";
char pass[] = "*************************";
BlynkTimer timer;  
  String    payload;
  float DegreesX;
float DegreesY;
float sun_altitude;
float sun_azimuth;
int windy;
//int event;
//xyz

void setup()
{
  // Debug console
 Serial.begin(9600);
 wifi.begin ();
Blynk.config(auth, ssid, pass, IPAddress(192,168,1,120), 8080)
 //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,120), 8080);
////////////////////
ArduinoOTA.onStart([]() {
  Serial.println("OTA Starting"); 
  });
  
  ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
  Serial.printf("Progress: %u%%\r", (progress / (total / 100))); Blynk.run();
  }); // Blynk.run during the OTA process to avoid Blynk disconnection
////////////////////
ArduinoOTA.onError([](ota_error_t error) { ESP.restart(); }); //MUST be AFTER Blynl.begin
 ArduinoOTA.setHostname("SunTracker");
 ArduinoOTA.begin();
// Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,120), 8080);
 // delay (3000);
// APIupdate(); //call API to populate payload data
 ////////////////
// timer.setInterval(1000L, takeReadings);
 timer.setInterval(2500L, updateDisplay);
 timer.setInterval(1800*1000L, APIupdate);// set to 12 seconds for testing set to 30 mins for use
//must change to 1800*1000L 30min/////
 APIupdate(); //call API to populate payload data
}

void loop()
{
  ArduinoOTA.handle(); //MUST be BEFORE Blynk.run
  Blynk.run();
   timer.run(); // Initiates BlynkTimer
}


void APIupdate(){ 
  HTTPClient http;  //Declare an object of class HTTPClient
//new API key
    http.begin("https://api.ipgeolocation.io/astronomy?apiKey=5a0ece4d1b7f49aca1b86d8e78dcebd2&lat=50.3&long=-4.9");  //Specify request destination
    int httpCode = http.GET();     //Send the request
    if (httpCode > 0) { //Check the returning code
   payload = http.getString();   //Get the request response payload
      }

    http.end();   //Close connection
    Serial.println(payload);
const size_t capacity = JSON_OBJECT_SIZE(2) + JSON_OBJECT_SIZE(18) + 320;
DynamicJsonDocument doc(capacity);
deserializeJson(doc, payload);

float location_latitude = doc["location"]["latitude"]; // 
float location_longitude = doc["location"]["longitude"]; // 
const char* date = doc["date"]; // "2020-09-30"
const char* current_time = doc["current_time"]; // "19:06:46.27"
const char* sunrise = doc["sunrise"]; // "07:18"
const char* sunset = doc["sunset"]; // "18:59"
const char* sun_status = doc["sun_status"]; // "-"
const char* solar_noon = doc["solar_noon"]; // "13:09"
const char* day_length = doc["day_length"]; // "11:41"
 sun_altitude = doc["sun_altitude"]; // -2.0393480763745733
float sun_distance = doc["sun_distance"]; // 149810371.16339526
 sun_azimuth = doc["sun_azimuth"]; // 267.4597814448824
const char* moonrise = doc["moonrise"]; // "19:02"
const char* moonset = doc["moonset"]; // "05:23"
const char* moon_status = doc["moon_status"]; // "-"
float moon_altitude = doc["moon_altitude"]; // 1.0738509355096701
float moon_distance = doc["moon_distance"]; // 402084.5279459498
float moon_azimuth = doc["moon_azimuth"]; // 100.76227521973334
float moon_parallactic_angle = doc["moon_parallactic_angle"]; // -38.56220668133565
Serial.println(sun_altitude);
Serial.println(sun_azimuth);
Blynk.virtualWrite(V1,sun_altitude);
Blynk.virtualWrite(V1,"\n "); //new line
Blynk.virtualWrite(V1,sun_azimuth);
//Serial.println(location_latitude);
}

void updateDisplay(){
  /*
 int rssi = WiFi.RSSI() ; //get signal strenth in DB
 Blynk.virtualWrite(V51,rssi);
   if(!accel.begin())
  {
        Blynk.virtualWrite(V1,"Ooops, no LSM303 detected ... Check your wiring!");
    while(1);
  }
  */
sensors_event_t event;  //im unable to move or remove this line due to compile errror
accel.getEvent(&event);
 /*
 float rawAngleX = event.acceleration.x;
 DegreesX = (rawAngleX * 9);
 map(DegreesX, -10, 10, 0, 180);
 float rawAngleY = event.acceleration.y;
 DegreesY = (rawAngleY * 9);
  map(DegreesY, -10, 10, 0, 180);
  
 Blynk.virtualWrite(V1,"DegreesX; ");
  Blynk.virtualWrite(V1,DegreesX);
  Blynk.virtualWrite(V1,"    RawAngle X; ");
  Blynk.virtualWrite(V1,rawAngleX);
   
  
  Blynk.virtualWrite(V1,"\n "); //new line
  
 Blynk.virtualWrite(V1,"DegreesY: ");
  Blynk.virtualWrite(V1,DegreesY);
  Blynk.virtualWrite(V1,"     RawAngle Y: ");
  Blynk.virtualWrite(V1,rawAngleY);
 Blynk.virtualWrite(V1,"\n "); //new line
 
 Blynk.virtualWrite(V1,"Suns Altitude: ");
//   Blynk.virtualWrite(V1,sun_altitude, 0);
Blynk.virtualWrite(V1,sun_altitude);
  Blynk.virtualWrite(V1,"\n "); //new line
 Blynk.virtualWrite(V4,sun_altitude);
 
 Blynk.virtualWrite(V1,"Azimuth: ");
  // Blynk.virtualWrite(V1,sun_azimuth, 0);
   Blynk.virtualWrite(V1,sun_azimuth);
   Blynk.virtualWrite(V5,sun_azimuth);
 
 
  Blynk.virtualWrite(V1,"\n "); //new line
  Blynk.virtualWrite(V1,"\n "); //new line
  */
}

also removed

Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,120), 8080);

replaced with

wifi.begin ();
Blynk.config(auth, ssid, pass, IPAddress(192,168,1,120), 8080)

The comments from @Madhukesh were shorthand for the actual steps that you need to take.

However, my suggested changes were as an alternative which would have allowed you to (hopefully) overcome the OTA issue without switching from Blynk.config.

Try going back to your original code snd just making the OTA changes.

Pete.

1 Like

Some WiFi library require capitalization.

WiFi.begin();  //vs
wifi.begin();

The process of connecting to WiFi requires SSID and password (unless you’re using an open network) and needs an “attempt to connect, pause, attempt again” process until a connection is established.
Blynk.config does not accept SSID and password as parameters.

Pete.

Finaly got somewere.
All of the above changes incorperated into code.
it was the LSM303 driver library interfearing with OTA and BLYNK. Only working with your code suggestions and new updated drivers.
a lot of cleaning up to do (removing serial prints) and further coding. But i have Blynk, OTA, API and sensor woking.

// file name:
//ESP32_WiFi_OTA_Test6New303lib
///////////////////////////////////

#define BLYNK_PRINT Serial
#include <ArduinoOTA.h>
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>

#include <HTTPClient.h>
#include <ArduinoJson.h>

//LSM303
#include <Adafruit_LSM303_Accel.h>
#include <Adafruit_Sensor.h>
#include <Wire.h>

/* Assign a unique ID to this sensor at the same time */
Adafruit_LSM303_Accel_Unified accel = Adafruit_LSM303_Accel_Unified(54321);


char auth[] = "*************************";
char ssid[] = "************************";
char pass[] = "***********************";
BlynkTimer timer;  
  String    payload;
  float DegreesX;
float DegreesY;
float sun_altitude;
float sun_azimuth;
int windy;
//int event;
//xyz

void setup()
{
  // Debug console
 Serial.begin(9600);
 //////////////////////////////////////////////
 //WiFi.begin ( ssid, pass);
 //Blynk.config(auth,IPAddress(192,168,1,120), 8080);
 Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,120), 8080);
///////////////////////////////////////////////
ArduinoOTA.onStart([]() {
  Serial.println("OTA Starting"); 
  });
  
  ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
  Serial.printf("Progress: %u%%\r", (progress / (total / 100))); Blynk.run();
  }); // Blynk.run during the OTA process to avoid Blynk disconnection
////////////////////
ArduinoOTA.onError([](ota_error_t error) { ESP.restart(); }); //MUST be AFTER Blynl.begin
 ArduinoOTA.setHostname("SunTracker");
 ArduinoOTA.begin();
// Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,120), 8080);
 // delay (3000);
// APIupdate(); //call API to populate payload data
 ////////////////
// timer.setInterval(1000L, takeReadings);
 timer.setInterval(2500L, updateDisplay);
 timer.setInterval(1800*1000L, APIupdate);// set to 12 seconds for testing set to 30 mins for use
//must change to 1800*1000L 30min/////
 APIupdate(); //call API to populate payload data
 /////LSM303/////////////
 Serial.println("Accelerometer Test");
  Serial.println("");

  /* Initialise the sensor */
  if (!accel.begin()) {
    /* There was a problem detecting the ADXL345 ... check your connections */
    Serial.println("Ooops, no LSM303 detected ... Check your wiring!");
    while (1)
      ;
  }

  /* Display some basic information on this sensor */
//  displaySensorDetails();

  accel.setRange(LSM303_RANGE_4G);
  Serial.print("Range set to: ");
  lsm303_accel_range_t new_range = accel.getRange();
  switch (new_range) {
  case LSM303_RANGE_2G:
    Serial.println("+- 2G");
    break;
  case LSM303_RANGE_4G:
    Serial.println("+- 4G");
    break;
  case LSM303_RANGE_8G:
    Serial.println("+- 8G");
    break;
  case LSM303_RANGE_16G:
    Serial.println("+- 16G");
    break;
  }

  accel.setMode(LSM303_MODE_NORMAL);
  Serial.print("Mode set to: ");
  lsm303_accel_mode_t new_mode = accel.getMode();
  switch (new_mode) {
  case LSM303_MODE_NORMAL:
    Serial.println("Normal");
    break;
  case LSM303_MODE_LOW_POWER:
    Serial.println("Low Power");
    break;
  case LSM303_MODE_HIGH_RESOLUTION:
    Serial.println("High Resolution");
    break;
  }
 
}

void loop()
{
  ArduinoOTA.handle(); //MUST be BEFORE Blynk.run
  Blynk.run();
   timer.run(); // Initiates BlynkTimer
}


void APIupdate(){ 
  HTTPClient http;  //Declare an object of class HTTPClient
//new API key
    http.begin("https://api.ipgeolocation.io/astronomy?apiKey=5a0ece4d1b7f49aca1b86d8e78dcebd2&lat=50.3&long=-4.9");  //Specify request destination
    int httpCode = http.GET();     //Send the request
    if (httpCode > 0) { //Check the returning code
   payload = http.getString();   //Get the request response payload
      }

    http.end();   //Close connection
    Serial.println(payload);
const size_t capacity = JSON_OBJECT_SIZE(2) + JSON_OBJECT_SIZE(18) + 320;
DynamicJsonDocument doc(capacity);
deserializeJson(doc, payload);

float location_latitude = doc["location"]["latitude"]; // 
float location_longitude = doc["location"]["longitude"]; // 
const char* date = doc["date"]; // "2020-09-30"
const char* current_time = doc["current_time"]; // "19:06:46.27"
const char* sunrise = doc["sunrise"]; // "07:18"
const char* sunset = doc["sunset"]; // "18:59"
const char* sun_status = doc["sun_status"]; // "-"
const char* solar_noon = doc["solar_noon"]; // "13:09"
const char* day_length = doc["day_length"]; // "11:41"
 sun_altitude = doc["sun_altitude"]; // -2.0393480763745733
float sun_distance = doc["sun_distance"]; // 149810371.16339526
 sun_azimuth = doc["sun_azimuth"]; // 267.4597814448824
const char* moonrise = doc["moonrise"]; // "19:02"
const char* moonset = doc["moonset"]; // "05:23"
const char* moon_status = doc["moon_status"]; // "-"
float moon_altitude = doc["moon_altitude"]; // 1.0738509355096701
float moon_distance = doc["moon_distance"]; // 402084.5279459498
float moon_azimuth = doc["moon_azimuth"]; // 100.76227521973334
float moon_parallactic_angle = doc["moon_parallactic_angle"]; // -38.56220668133565
Serial.println(sun_altitude);
Serial.println(sun_azimuth);
Blynk.virtualWrite(V1,sun_altitude);
Blynk.virtualWrite(V1,"\n "); //new line
Blynk.virtualWrite(V1,sun_azimuth);
//Serial.println(location_latitude);
}

void updateDisplay(){
  /*
 int rssi = WiFi.RSSI() ; //get signal strenth in DB
 Blynk.virtualWrite(V51,rssi);
   if(!accel.begin())
  {
        Blynk.virtualWrite(V1,"Ooops, no LSM303 detected ... Check your wiring!");
    while(1);
  }
  */
  //////////////////////////////////////////////////////////////////////////////////////////////////////
sensors_event_t event;  
accel.getEvent(&event);
sensor_t sensor;
  accel.getSensor(&sensor);

 ///////////////////////////////////////////////////////////////////////////////////////////////
 
 float rawAngleX = event.acceleration.x;
 DegreesX = (rawAngleX * 9);
 map(DegreesX, -10, 10, 0, 180);
 float rawAngleY = event.acceleration.y;
 DegreesY = (rawAngleY * 9);
  map(DegreesY, -10, 10, 0, 180);
  
 Blynk.virtualWrite(V1,"DegreesX; ");
  Blynk.virtualWrite(V1,DegreesX);
  Blynk.virtualWrite(V1,"    RawAngle X; ");
  Blynk.virtualWrite(V1,rawAngleX);
   
  
  Blynk.virtualWrite(V1,"\n "); //new line
  
 Blynk.virtualWrite(V1,"DegreesY: ");
  Blynk.virtualWrite(V1,DegreesY);
  Blynk.virtualWrite(V1,"     RawAngle Y: ");
  Blynk.virtualWrite(V1,rawAngleY);
 Blynk.virtualWrite(V1,"\n "); //new line
 
 Blynk.virtualWrite(V1,"Suns Altitude: ");
//   Blynk.virtualWrite(V1,sun_altitude, 0);
Blynk.virtualWrite(V1,sun_altitude);
  Blynk.virtualWrite(V1,"\n "); //new line
 Blynk.virtualWrite(V4,sun_altitude);
 
 Blynk.virtualWrite(V1,"Azimuth: ");
  // Blynk.virtualWrite(V1,sun_azimuth, 0);
   Blynk.virtualWrite(V1,sun_azimuth);
   Blynk.virtualWrite(V5,sun_azimuth);
 
 
  Blynk.virtualWrite(V1,"\n "); //new line
  Blynk.virtualWrite(V1,"\n "); //new line
  
}

Many Thanks for all your help. :smiley:

2 Likes