ESP32-WROOM-32 - AZ-delivery dev kitC

davidmarli
Posts: 2
Joined: Sun Oct 17, 2021 4:31 pm

ESP32-WROOM-32 - AZ-delivery dev kitC

Postby davidmarli » Sun Oct 17, 2021 4:36 pm

Hi,

this is the first time I own such a board. I purchase 1 azdelivery esp32 devKitC esp32-WROOM-32.

I try to programm it with vscode.

To upload a program with the usb cable : is it normla, that I have to press the boot button while uploading ?

2) I try to upload OTA feature. I can upload with usb calbe, but, once it is done, ota doesn't work : it stopp at 8%. I don't know why.

Here is my code :

Here is platformIO.ino (I don't know if it's the right board !)
  1. ; PlatformIO Project Configuration File
  2. ;
  3. ;   Build options: build flags, source filter
  4. ;   Upload options: custom upload port, speed and extra flags
  5. ;   Library options: dependencies, extra library storages
  6. ;   Advanced options: extra scripting
  7. ;
  8. ; Please visit documentation for the other options and examples
  9. ; https://docs.platformio.org/page/projectconf.html
  10.  
  11. [env:az-delivery-devkit-v4]
  12. platform = espressif32
  13. ;board = az-delivery-devkit-v2
  14. board = esp32dev
  15. framework = arduino
  16. monitor_speed = 115200
  17. upload_protocol = esptool
  18. upload_port = 192.168.1.117
  19. ;lib_deps = https://github.com/tzapu/WiFiManager.git

main.cpp
  1. #include <OTA.h>
  2.  
  3. //const char * ssid = "Routeur24";
  4. //const char* password = "Da41ma64";
  5.  
  6. #define CONNECTION_TIMEOUT 10
  7.  
  8. void setup() {
  9.   // put your setup code here, to run once:
  10.    Serial.begin(115200);
  11.    Serial.println("Booting");
  12.     //***********************************
  13.     //************* Connexion au WIFI
  14.     //***********************************
  15.  
  16.   IPAddress ip(192, 168, 1, 117);
  17.   IPAddress dns(192, 168, 1, 1);
  18.   IPAddress gateway(192, 168, 1, 1);
  19.   IPAddress subnet(255, 255, 255, 0);
  20.   WiFi.config(ip, dns, gateway, subnet);
  21.   WiFi.begin(mySSID,myPASSWORD);
  22.   Serial.print("\nConnexion au WIFI");
  23.  
  24.  int timeout_counter = 0;
  25.  
  26.     while(WiFi.status() != WL_CONNECTED){
  27.         Serial.print(".");
  28.         delay(200);
  29.         timeout_counter++;
  30.         if(timeout_counter >= CONNECTION_TIMEOUT*5){
  31.         ESP.restart();
  32.         }
  33.     }
  34.  
  35.     Serial.println("\nConnected to the WiFi network");
  36.     Serial.print("Local ESP32 IP: ");
  37.     Serial.println(WiFi.localIP());
  38.  
  39.     //***********************************
  40.     //************* OTA Setup
  41.     //***********************************
  42.  
  43.     setupOTA("TemplateSketch", mySSID, myPASSWORD);
  44.  
  45.  
  46. }
  47.  
  48. void loop() {
  49.   // put your main code here, to run repeatedly:
  50. //#ifdef defined(ESP32_RTOS) && defined(ESP32)
  51. //#else // If you do not use FreeRTOS, you have to regulary call the handle method.
  52.   ArduinoOTA.handle();
  53. //#endif
  54. Serial.println("Test");
  55. }
And the OTA.h file :
  1. #ifdef ESP32
  2. #include <WiFi.h>
  3. #include <ESPmDNS.h>
  4. #else
  5. #include <ESP8266WiFi.h>
  6. #include <ESP8266mDNS.h>
  7. #endif
  8.  
  9. #include <WiFiUdp.h>
  10. #include <ArduinoOTA.h>
  11.  
  12. #if defined(ESP32_RTOS) && defined(ESP32)
  13. void ota_handle( void * parameter ) {
  14.   for (;;) {
  15.     ArduinoOTA.handle();
  16.     delay(3500);
  17.   }
  18. }
  19. #endif
  20.  
  21. void setupOTA(const char* nameprefix, const char* ssid, const char* password) {
  22.   // Configure the hostname
  23.   uint16_t maxlen = strlen(nameprefix) + 7;
  24.   char *fullhostname = new char[maxlen];
  25.   uint8_t mac[6];
  26.   WiFi.macAddress(mac);
  27.   snprintf(fullhostname, maxlen, "%s-%02x%02x%02x", nameprefix, mac[3], mac[4], mac[5]);
  28.   ArduinoOTA.setHostname(fullhostname);
  29.   delete[] fullhostname;
  30.  
  31.   // Configure and start the WiFi station
  32.   WiFi.mode(WIFI_STA);
  33.   WiFi.begin(ssid, password);
  34.  
  35.   // Wait for connection
  36.   while (WiFi.waitForConnectResult() != WL_CONNECTED) {
  37.     Serial.println("Connection Failed! Rebooting...");
  38.     delay(5000);
  39.     ESP.restart();
  40.   }
  41.  
  42.   // Port defaults to 3232
  43.   // ArduinoOTA.setPort(3232); // Use 8266 port if you are working in Sloeber IDE, it is fixed there and not adjustable
  44.  
  45.   // No authentication by default
  46.   // ArduinoOTA.setPassword("admin");
  47.  
  48.   // Password can be set with it's md5 value as well
  49.   // MD5(admin) = 21232f297a57a5a743894a0e4a801fc3
  50.   // ArduinoOTA.setPasswordHash("21232f297a57a5a743894a0e4a801fc3");
  51.  
  52.   ArduinoOTA.onStart([]() {
  53.     //NOTE: make .detach() here for all functions called by Ticker.h library - not to interrupt transfer process in any way.
  54.     String type;
  55.     if (ArduinoOTA.getCommand() == U_FLASH)
  56.       type = "sketch";
  57.     else // U_SPIFFS
  58.       type = "filesystem";
  59.  
  60.     // NOTE: if updating SPIFFS this would be the place to unmount SPIFFS using SPIFFS.end()
  61.     Serial.println("Start updating " + type);
  62.   });
  63.  
  64.   ArduinoOTA.onEnd([]() {
  65.     Serial.println("\nEnd");
  66.   });
  67.  
  68.   ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
  69.     Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
  70.   });
  71.  
  72.   ArduinoOTA.onError([](ota_error_t error) {
  73.     Serial.printf("Error[%u]: ", error);
  74.     if (error == OTA_AUTH_ERROR) Serial.println("\nAuth Failed");
  75.     else if (error == OTA_BEGIN_ERROR) Serial.println("\nBegin Failed");
  76.     else if (error == OTA_CONNECT_ERROR) Serial.println("\nConnect Failed");
  77.     else if (error == OTA_RECEIVE_ERROR) Serial.println("\nReceive Failed");
  78.     else if (error == OTA_END_ERROR) Serial.println("\nEnd Failed");
  79.   });
  80.  
  81.   ArduinoOTA.begin();
  82.  
  83.   Serial.println("OTA Initialized");
  84.   Serial.print("IP address: ");
  85.   Serial.println(WiFi.localIP());
  86.  
  87. #if defined(ESP32_RTOS) && defined(ESP32)
  88.   xTaskCreate(
  89.     ota_handle,          /* Task function. */
  90.     "OTA_HANDLE",        /* String with name of task. */
  91.     10000,            /* Stack size in bytes. */
  92.     NULL,             /* Parameter passed as input of the task */
  93.     1,                /* Priority of the task. */
  94.     NULL);            /* Task handle. */
  95. #endif
  96. }
Thank you for your help.

Who is online

Users browsing this forum: No registered users and 45 guests