OTA cannot be seen in the arduino ide #160
Unanswered
jagonzalezga
asked this question in
Q&A
Replies: 1 comment
-
you use the ArduinoOTA bundled with the esp32 core, not this ArduinoOTA library |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
hello how are you, i have been working with the OTA library at home and everything worked fine, the arduino ide detects it but when changing to another network it does not appear in the ide, but the rest works except for the power part compile it via OTA.
I hope someone knows what it could be.
this is a header file
`#ifdef ESP32
#include <WiFi.h>
#include <ESPmDNS.h>
#else
#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#endif
#include <RTClib.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>
int restart1=0;
RTC_DS3231 RTC;
#if defined(ESP32_RTOS) && defined(ESP32)
void ota_handle( void * parameter ) {
for (;;) {
}
}
#endif
void setupOTA(const char* nameprefix, const char* ssid, const char* password,const char* Adjust) {
Serial.println("ENTRO A RUTINA SETUP OTA");
// Configure the hostname
uint16_t maxlen = strlen(nameprefix) + 7;
char *fullhostname = new char[maxlen];
uint8_t mac[6];
WiFi.macAddress(mac);
snprintf(fullhostname, maxlen, "%s-%02x%02x%02x", nameprefix, mac[3], mac[4], mac[5]);
ArduinoOTA.setHostname(fullhostname);
delete[] fullhostname;
/*
WiFi.mode(WIFI_STA) station mode: the ESP32 connects to an access point
WiFi.mode(WIFI_AP) access point mode: stations can connect to the ESP32
WiFi.mode(WIFI_STA_AP) access point and a station connected to another access point
*/
WiFi.mode(WIFI_STA);//esta seccion me inidca en que tipo de modo se utilizara el esp32
WiFi.begin(ssid, password);//una vez configurado el json se extraen los valores de ssid y la contraseña del wifi
Serial.print("Connecting to WiFi ..");
/*para saber el estatus de nuestra conexion a wifi llamamos una funcion while que este checando el estatus
si es diferente a WL_CONNECTED y la variable restart es menor a 30 se hara la iteracion
// Port defaults to 3232
// ArduinoOTA.setPort(3232); // Use 8266 port if you are working in Sloeber IDE, it is fixed there and not adjustable
// 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( {
//NOTE: make .detach() here for all functions called by Ticker.h library - not to interrupt transfer process in any way.
String type;
if (ArduinoOTA.getCommand() == U_FLASH)
type = "sketch";
else // U_SPIFFS
type = "filesystem";
});
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("\nAuth Failed");
else if (error == OTA_BEGIN_ERROR) Serial.println("\nBegin Failed");
else if (error == OTA_CONNECT_ERROR) Serial.println("\nConnect Failed");
else if (error == OTA_RECEIVE_ERROR) Serial.println("\nReceive Failed");
else if (error == OTA_END_ERROR) Serial.println("\nEnd Failed");
});
ArduinoOTA.begin();
Serial.println("OTA Initialized");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
Serial.println("\n");
#if defined(ESP32_RTOS) && defined(ESP32)
xTaskCreate(
ota_handle, /* Task function. /
"OTA_HANDLE", / String with name of task. /
10000, / Stack size in bytes. /
NULL, / Parameter passed as input of the task /
1, / Priority of the task. /
NULL); / Task handle. */
#endif
}`
this a main file
`#include <RTClib.h>
#include <SocketIoClient.h>
#include "FS.h"
#include "SD.h"
#include "SPI.h"
#include <Wire.h>//libreria encargada de la interfaz i2c
#include <Arduino_JSON.h>
#include <WiFi.h>
//#include <WebSocketsClient.h>
#include <Adafruit_ADS1X15.h>//libreria del adc
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <OneWire.h>//biblioteca usada para los dispositivos que un solo cable como el sensor DS18620
#include <DallasTemperature.h>//libreria para el control y manejo del sensor DS18620
///////////////////////////////////////////
#include "OTA.h"
///////////////////////////////////
#pragma region variables
//estas tareas se dividen en dos ya que el esp tiene dos nucleos
TaskHandle_t Task1;
TaskHandle_t Task2;
//aqui declaramos las variables JSON con el tipo de dato JSONVar
JSONVar esp32,response,jsonResponse,jsonDigitales;
int restart = 0;//variable que se usa en la seccion de wifi para el conteo
bool enviarDigitales = false;
SocketIoClient socketIO;
//SocketIoClient socket;
Adafruit_ADS1115 ads;
RTC_DS3231 myRTC;
#define SCREEN_WIDTH 128 //constante definida para el ancho del oled display
#define SCREEN_HEIGHT 32 //constante definida para la altura del oled display
#define OLED_RESET 4 //pin de reset de la pantalla oled display
#define SDB 27 //gpio donde el sensor DS18620 sera conectado
float volt = 0,
lectura = 0,
Vcc = 3.3,
VccAds = 4.096,
Resistencia = 10000,
K = 2.5,
constanteV = 4095,
constanteVAds = 32767,
delayR = 2,
pantallaTemperatura;
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
/*el sensor de temperatura DS18620 es un sensor de un solo cable y digital, esto significa que requiere una lina de datps y gnd para comunicarse
con el esp32, cada sensor de temperatura tiene un codigo serial unico de 64bits. Esto permite que podamos conectar multiple sennsores en la misma linea
1.-se comunica a traves de one-wire comunicacion
2.-opera entre 3.0v a 5.5v
3.-rango de operacion de temperatura -55c a +125c
4.-precision de +/-0.5 grados centigrado(entre el rango de -10c a 85c)
*/
OneWire oneWire(SDB);//configura la instancia onewire para comunicarce con culaquier dispositivo que maneje el protocolo onewire
DallasTemperature sensors(&oneWire); //pasa nuestra referencia de la instancia onewire a la biblioteca de DallasTemperature
int numberOfDevices;//variable que guarda en numero de dispositivos que estan conectados al bus de datos
DeviceAddress tempDeviceAddress;
String address = "";
#pragma endregion comment
#pragma region DISPLAY_Methods
//________________________________________________________________
void initDisplay()
{
}
void initTime()
{
}
String getDateTime()
{
// Serial.println(timestamp);
}
String getDateTimeStr()
{
// Serial.println(timestamp);
// Serial.println(str);
}
//________________________________________________________________
void textDraw()
{
}
//________________________________________________________________
void textDrawError()
{
}
//________________________________________________________________
#pragma endregion commit
#pragma region ADS
//________________________________________________________________
void getGain(int i){
switch (i)
{
case 1:
ads.setGain(GAIN_ONE);
break;
case 2:
ads.setGain(GAIN_TWO);
break;
case 4:
ads.setGain(GAIN_FOUR);
break;
case 8:
ads.setGain(GAIN_EIGHT);
break;
case 16:
ads.setGain(GAIN_SIXTEEN);
break;
case 23:
ads.setGain(GAIN_TWOTHIRDS);
break;
}
}
//________________________________________________________________
void initADS(){
if(esp32["variables"]["statusAPS"]){
ads.setGain(GAIN_ONE);//GAIN_ONE = ADS1X15_REG_CONFIG_PGA_4_096V,
ads.begin();
}
}
//________________________________________________________________
#pragma endregion comment
#pragma region SD_Methods
//________________________________________________________________
bool isTypeSDExists()
{
}
//________________________________________________________________
void createDir(fs::FS &fs, const char *path)
{
Serial.printf("Creating Dir: %s\n", path);
if (fs.mkdir(path))
{
Serial.println("Dir created");
}
else
{
Serial.println("mkdir failed");
}
}
//________________________________________________________________
void removeDir(fs::FS &fs, const char *path)
{
Serial.printf("Removing Dir: %s\n", path);
if (fs.rmdir(path))
{
Serial.println("Dir removed");
}
else
{
Serial.println("rmdir failed");
}
}
//________________________________________________________________
void deleteFile(fs::FS &fs, const char *path)
{
Serial.printf("Deleting file: %s\n", path);
if (fs.remove(path))
{
Serial.println("File deleted");
}
else
{
Serial.println("Delete failed");
}
}
//________________________________________________________________
void writeFile(fs::FS &fs, const char *path, const char *message)
{
Serial.printf("Writing file: %s\n", path);
}
//________________________________________________________________
String getDataFromSD(fs::FS &fs, const char *path)
{
// filebytes = Serial.write(file.read());
finalString += (char)file.read();
}
}
}
//se manda a llamar la funcion desde el void setup
void initSD()
{
}
//________________________________________________________________
#pragma endregion comment
#pragma region WIFI_Methods
//________________________________________________________________
//________________________________________________________________
#pragma endregion commit
#pragma region WebSocket_Methods
//________________________________________________________________
void onRestartByWs(const char *payload, size_t length)
{
Serial.printf("got message: %s\n", payload);
if (strlen(payload) != 0)
{
Serial.println("Metodo Reiniciar");
String datos = String(payload);
datos.replace("\", "");
JSONVar restartESP = JSON.parse(datos);
if((strcmp(restartESP["CodigoMDC"],esp32["device"]["CodigoMDC"])) == 0){
ESP.restart();
}
}
}
//________________________________________________________________
void onRelayByWs(const char *payload, size_t length)//
{
Serial.printf("got message: %s\n", payload);
if (strlen(payload) != 0)
{
Serial.println("Metodo encender apagar Relay");
String datos = String(payload);
datos.replace("\", "");
JSONVar restartESP = JSON.parse(datos);
if((strcmp(restartESP["Code"],esp32["device"]["CodigoMDC"])) == 0){
int pin = int(atoi(restartESP["p"]));
pinMode(pin,OUTPUT);
if((strcmp(restartESP["v"],"1.00"))==0){
digitalWrite(pin,HIGH);
Serial.println("Apagar Salida");
sendInfoWebSocket("SetRelee",restartESP);
}else{
digitalWrite(pin,LOW);
Serial.println("Encender Salida");
sendInfoWebSocket("SetRelee",restartESP);
}
}
}
}
//________________________________________________________________
void onGetConfigurationByWs(const char *payload, size_t length)
{
Serial.printf("got message: %s\n", payload);
if (strlen(payload) != 0)
{
String datos = String(payload);
datos.replace("\", "");
jsonResponse = JSON.parse(datos);
if (JSON.typeof(jsonResponse) == "undefined")
{
Serial.println("Parsing input failed!");
return;
}
if ((strcmp(jsonResponse["idRespuesta"], "1")) == 0){
if ((strcmp(jsonResponse["Code"], esp32["device"]["CodigoMDC"])) == 0)
{
}
//________________________________________________________________
void loadPins(){
Serial.println("llegamos a la funcion loadPins");
if (jsonResponse["Pines"].length() > 0){
for (int cnt = 0; cnt < jsonResponse["Pines"].length(); cnt++)
{
Serial.println(jsonResponse["Pines"][cnt]);
if((strcmp(jsonResponse["Pines"][cnt]["t"],"REL")) == 0){
pinMode(int(atoi(jsonResponse["Pines"][cnt]["p"])), OUTPUT);
JSONVar jss = esp32["sendServer"];
jsonResponse["Pines"][cnt]["sendServer"] = jss;
}else if((strcmp(jsonResponse["Pines"][cnt]["t"],"TDI")) != 0){
pinMode(int(atoi(jsonResponse["Pines"][cnt]["p"])), INPUT);
JSONVar js = esp32["varPines"];
JSONVar jss = esp32["sendServer"];
// jss["CodigoMDC"]=esp32+["device"]["CodigoMDC"];
jsonResponse["Pines"][cnt]["vars"] = js;
jsonResponse["Pines"][cnt]["sendServer"] = jss;
}
//________________________________________________________________
/*
esta fucnion es la que emite los eventos y la variable json
el evento que esta en la parte del servidor con listener .on aobtiene el evento y recibe el JSONVar
lo traduce a una caden de estilo c con la funcion c_str() y los serilaiza con la funcion stringify()
/
void sendInfoWebSocket(String metodo, JSONVar object)//
{
if(esp32["variables"]["statusWs"]){
socketIO.emit(metodo.c_str(), JSON.stringify(object).c_str());//manda allamar el evento de emit de la libreria de socketIO.emit
}
}
//________________________________________________________________
/
esta funcion depende de la libreria SocketIoClient.h
void SocketIoClient::on(const char* event, std::function<void (const char * payload, size_t length)> func) {
_events[event] = func;
}
*/
void initWebSocket()
{
if(esp32["variables"]["statusWs"])
{
// server address, port and URL
socketIO.begin(esp32["server"]["host"], int(atoi(esp32["server"]["port"])));
// event handler for the event message
socketIO.on("GetConfiguracion",onGetConfigurationByWs);//listener
socketIO.on("Reiniciar", onRestartByWs);//listener
socketIO.on("SetRelee", onRelayByWs);//listener
sendInfoWebSocket("GetConfiguracion",esp32["device"]);//manda a llamar la funcion sendInfoWebSocket le pasa los argumentos del evento y del dispositivo
}
}
//________________________________________________________________
#pragma endregion commit
#pragma region EXTRAS_Methods
//________________________________________________________________
void crearConfigFile()
{
}
//________________________________________________________________
int16_t getPositionADS(int sel){
switch (sel)
{
case 100:
return ads.readADC_SingleEnded(0);
break;
case 101:
return ads.readADC_SingleEnded(1);
break;
case 102:
return ads.readADC_SingleEnded(2);
break;
case 103:
return ads.readADC_SingleEnded(3);
break;
}
}
//________________________________________________________________
//________________________________________________________________
float getTemperatureDigital(){
}
//________________________________________________________________
float getCurrent(float raw,float volRange,float constantRaw,int cCorriente){
float a = ((((raw * volRange) / constantRaw) * cCorriente) / 5);
return a;
}
//________________________________________________________________
void checkInfo(JSONVar sensor,float value){
//se hace la media para hacer el calculo
if (int(atoi(sensor["vars"]["countSamplers"])) == int(atoi(sensor["vars"]["maxSamplers"]))){
float t = (float)int(atoi(sensor["vars"]["averageSamplers"])) / int(atoi(sensor["vars"]["maxSamplers"]));
if (int(atoi(sensor["vars"]["lastRegister"])) != int(t)){
sensor["vars"]["lastRegister"] = "0";
sensor["vars"]["lastRegister"] = String(int(t));
sensor["sendServer"]["Fecha"] = getDateTime();
sensor["sendServer"]["Valor"] = String(int(value));
sensor["sendServer"]["GPIO"] = JSON.stringify(sensor["p"]).c_str();
sendInfoWebSocket("stateChanged",sensor["sendServer"]);
Serial.print("Load pins Sensor: ");
Serial.println(sensor);
}
sensor["vars"]["averageSamplers"] = "0";
sensor["vars"]["countSamplers"] = "0";
}else{
int sum = 0;
sum = int(atoi(sensor["vars"]["averageSamplers"])) + (int)value;
sensor["vars"]["averageSamplers"] = String(sum);
int num = int(atoi(sensor["vars"]["countSamplers"])) + 1;
sensor["vars"]["countSamplers"] = String(num);
}
}
//________________________________________________________________
void checkInfoCor(JSONVar sensor,float value){
}
//________________________________________________________________
#pragma endregion commit
#pragma region SensoresTemperaturaDigital
//________________________________________________________________
// function to print a device address
String printAddress(DeviceAddress deviceAddress) {
address = "";
for (uint8_t i = 0; i < 8; i++){
if (deviceAddress[i] < 16){
address = address + "0";
}else{
address = address + String(deviceAddress[i],HEX);
}
}
//________________________________________________________________
void InitDigitalTemperature()
{
sensors.begin();
}
//________________________________________________________________
#pragma endregion commit
//________________________________________________________________
void Task1code( void * parameter ){
Serial.print("Task1 is running on core ");
Serial.println(xPortGetCoreID());
while(1){
socketIO.loop();
//delay(500);
vTaskDelay(pdMS_TO_TICKS(500)); // Delay for 1000 milliseconds
}
}
//________________________________________________________________
void setup()
{
Serial.begin(115200);// inicializa el baud rate para la comunicacion de la tablilla de desarrollo
}
//________________________________________________________________
void loop()
{
// if(enviarDigitales){
// enviarDigitales = false;
// sendInfoWebSocket("stateChanged",jsonDigitales);
// }
}`
so thats the problem basically
Beta Was this translation helpful? Give feedback.
All reactions