Any OTA Gurus out there?

I’m starting to collect a small family of ESP32 boards monitoring different sensors. Each sensor has its own ESP32 and I’m successfully able to Update a Sketch Over The Air (OTA).

Management of these should be easier than keeping a paper chart. Where in the Arduino Environment does the “Host Name” (?) get set to “Esp32 Dev Module”? I would like to assign each device a unique name so I don’t inadvertently FLASH the wrong one.

Please see attached.

Have you tried Using WiFi.h

const char* hname = "ESP32RMETZ1";

void setup () {
  WiFi.disconnect(); // just in case
  WiFi.setHostname(hname); // call before begin
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
...

You might have the old name in the cache of the router so do clean the dhcp cache or renew lease or reboot the router if you don’t see it. It’s important to set the hostname before calling begin

None of that has anything to do with the name that appears in the PORTS menu though. Yes, I can get my router to report the name with the IP address. That wasn't the question.

The Arduino IDE Menu echoes the Board Type from Boards Manager's choices. Why does it stick that in next to the IP address and how to change it? Sorry if I was unclear.

Here is my entire Setup();

// Initialize I/O Matrix, Serial Class 
void setup() {
  pinMode(ENABLE, OUTPUT);                 // ENA/PWM to Motor
  digitalWrite(ENABLE,_ON);                 // do FIRST so motor doesn't spike
  Serial.begin(115200);
  Serial.println("Booting");
  ScanI2C();
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  // Address 0x3C for 128x64
  PCF8574.begin();                            // start the IO expander object
  PCF8574.pinMode(CAT_PRESENT, INPUT);        // IR Cat Present Sensor
  PCF8574.pinMode(AT_HOME, INPUT);            // Returned prox
  PCF8574.pinMode(FWD, OUTPUT);               // Motor EXTEND
  PCF8574.pinMode(REV, OUTPUT);               // Motor RETURN
  pinMode(PCFIO_INT, INPUT_PULLUP);           // IO chip IRQ pin
  pinMode(CPU_HOME, INPUT_PULLUP);            // 
  WiFi.disconnect();
  delay(2000);
  WiFi.setHostname(hname); // call before begin
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);                         //connect to WiFi
  Serial.print("Connecting to WiFi Network: ");
  Serial.println(ssid);
  while (WiFi.status() != WL_CONNECTED) {
      delay(1000);
      Serial.print("**");
  }
  Serial.println(" ");
  Serial.print("CONNECTED to ");
  Serial.print(ssid);
  Serial.print(" using Local IP address: ");
  Serial.println(WiFi.localIP());  
  TelnetStream.begin(); 
  TelnetStream.print  ("Booting ** Version ");
  TelnetStream.println(ver);
  TelnetStream.println(WiFi.localIP());  
  beginOTA();
  Serial.println("Done with Setup");
  digitalWrite(ENABLE,_OFF);
  digitalWrite(FWD,_OFF);                  // 00 = BRAKE
  digitalWrite(REV,_OFF);
  PState = PWRUP;
  display.clearDisplay();
  display.setTextSize(2); // Draw 2X-scale text
  display.setTextColor(SSD1306_WHITE);
  display.display();      // Show initial text
}//------------------------------------------------------------------------

Look at about 3:15 in this video ESP32 OTA tutorial

Is that what you are looking for ?

Sorry misread the question.

Indeed probably need to call this

Maybe I posted this in the wrong forum? The question has to do with the Arduino IDE, not OTA per se.

Please look at my attachment in the first post named "ports.png".

You can clearly see Arduino grabs the MAC address and IP address of the board in question.
What it does NOT do is provide the correct HOST NAME.

Thus my question if the IDE knows about Mac address and IP address why can't it display the Host Name instead of the Board Type from Boards Manager???

Everything works as it should with WiFi and OTA.

“esp32-” is the default host name set by the OTA library, you can change it if you want.

guix:
“esp32-” is the default host name set by the OTA library, you can change it if you want.

https://github.com/espressif/arduino-esp32/blob/master/libraries/ArduinoOTA/src/ArduinoOTA.cpp#L121

But it does this only if you did not initialize the String yourself (testing if it’s length is non nul) as this is in begin you need to call the ArduinoOTAClass’ setHostname method before calling begin.

I would like to assign each device a unique name so I don't inadvertently FLASH the wrong one.

Like this ?

Exactly like that! Where is it done?

rmetzner49:
Exactly like that! Where is it done?

See reply #3

Thanks, I did see that but I had things out of order when I tried it. Obvious to me now, you have to set the Host Name before you begin OTA. :smiley: :smiley:

Now that I understand it, I'll try to set the Host Name based on Mac Address. That way, I won't have to maintain a different copy of the program if the boards are the same.

rmetzner49:
Thanks, I did see that but I had things out of order when I tried it.

yes - as pointed out in #7