@@ -114,6 +114,7 @@ class tTxEspWifiBridge
114114 private:
115115#ifdef ESP_STARTUP_CONFIGURE
116116 bool esp_read (const char * const cmd, char * const res, uint8_t * const len);
117+ void esp_wait_after_read (const char * const res);
117118 void esp_configure_baudrate (void );
118119 void esp_configure_wifiprotocol (void );
119120 void esp_configure_wifichannel (void );
@@ -136,6 +137,8 @@ class tTxEspWifiBridge
136137
137138 uint8_t dtr_rts_last;
138139 uint8_t boot0_last;
140+
141+ uint32_t version;
139142};
140143
141144
@@ -169,6 +172,8 @@ void tTxEspWifiBridge::Init(
169172 dtr_rts_last = 0 ;
170173 boot0_last = 0 ;
171174
175+ version = 0 ; // unknown
176+
172177#ifdef ESP_STARTUP_CONFIGURE
173178 run_configure ();
174179#endif
@@ -377,6 +382,20 @@ ESP_DBG(dbg.puts("!ENDE!");)
377382}
378383
379384
385+ void tTxEspWifiBridge::esp_wait_after_read (const char * const res)
386+ {
387+ if (version >= 10307 ){ // sends a '*' instead of a '+' if setting had been changed
388+ if (res[2 ] == ' +' ) { // no change, so no need to wait for long
389+ delay_ms (5 );
390+ return ;
391+ }
392+ }
393+
394+ // wait for save on esp to finish
395+ delay_ms (100 );
396+ }
397+
398+
380399void tTxEspWifiBridge::esp_configure_baudrate (void )
381400{
382401char s[ESP_CMDRES_LEN+2 ];
@@ -388,12 +407,12 @@ char cmd_str[32];
388407 remove_leading_zeros (baud_str);
389408 strcpy (cmd_str, " AT+BAUD=" );
390409 strcat (cmd_str, baud_str);
410+
391411 if (!esp_read (cmd_str, s, &len)) { // AT+BAUD sends response with "old" baud rate, when stores it, but does NOT change it
392412 return ;
393413 }
394414
395- // wait for save on esp to finish
396- delay_ms (100 );
415+ esp_wait_after_read (s);
397416}
398417
399418
@@ -417,8 +436,7 @@ char cmd_str[32];
417436 return ;
418437 }
419438
420- // wait for save on esp to finish
421- delay_ms (100 );
439+ esp_wait_after_read (s);
422440}
423441
424442
@@ -442,8 +460,7 @@ char cmd_str[32];
442460 return ;
443461 }
444462
445- // wait for save on esp to finish
446- delay_ms (100 );
463+ esp_wait_after_read (s);
447464}
448465
449466
@@ -466,8 +483,7 @@ char cmd_str[32];
466483 return ;
467484 }
468485
469- // wait for save on esp to finish
470- delay_ms (100 );
486+ esp_wait_after_read (s);
471487}
472488
473489
@@ -484,16 +500,14 @@ char cmd_str[32];
484500 return ;
485501 }
486502
487- // wait for save on esp to finish
488- delay_ms (100 );
503+ esp_wait_after_read (s);
489504}
490505
491506
492507void tTxEspWifiBridge::run_configure (void )
493508{
494509char s[ESP_CMDRES_LEN+2 ];
495510uint8_t len;
496- uint32_t ver;
497511
498512 if (ser == nullptr ) return ; // we need a serial
499513
@@ -502,7 +516,6 @@ uint32_t ver;
502516 delay_ms (500 ); // not so nice, but it starts up really slowly ...
503517
504518 bool found = false ;
505- ver = 0 ; // unknown
506519
507520 uint32_t bauds[7 ] = { ser_baud, 9600 , 19200 , 38400 , 57600 , 115200 , 230400 };
508521 uint8_t baud_idx = 0 ;
@@ -515,7 +528,7 @@ uint32_t ver;
515528 s[len-2 ] = ' \0 ' ;
516529 if (!strncmp (s, " OK+NAME=mLRS-Wireless-Bridge" , 28 )) { // correct name, it's her we are looking for
517530 found = true ;
518- if (strlen (s) > 32 ) ver = version_from_str (s + 28 );
531+ if (strlen (s) > 32 ) version = version_from_str (s + 28 );
519532 }
520533 cc = 128 ; // break also higher for loop, don't do 255 LOL
521534 break ;
@@ -538,11 +551,24 @@ esp_read("dAT+BINDPHRASE=?", s, &len);)
538551 esp_configure_wifiprotocol ();
539552 esp_configure_wifichannel ();
540553 esp_configure_wifipower ();
541- if (ver >= 10307 ) { // not available before v1.3.07
554+ if (version >= 10307 ) { // not available before v1.3.07
542555 esp_configure_bindphrase ();
543556 } else {
544557 // Houston, we have a problem. UDPCl is not available but we allow the user to select
545558 }
559+ if (version >= 10307 ) { // not available before v1.3.07
560+ // esp_read("AT+WIFIDEVICEID=?", s, &len);
561+ // if (len > 18) device_id = atoi(s + 16);
562+ esp_read (" AT+WIFIDEVICENAME=?" , s, &len);
563+ if (len > 22 ) {
564+ strcpy (info.wireless .device_name , s + 18 );
565+ info.wireless .device_name [strlen (info.wireless .device_name )-1 ] = ' \0 ' ; // strip off '\n'
566+ info.wireless .device_name [strlen (info.wireless .device_name )-1 ] = ' \0 ' ; // strip off '\r'
567+ }
568+ if (strlen (info.wireless .device_name ) > 9 && !strncmp (info.wireless .device_name , " mLRS-" , 5 )) {
569+ info.wireless .device_id = atoi (info.wireless .device_name + 5 );
570+ }
571+ }
546572
547573 if (esp_read (" AT+RESTART" , s, &len)) { // will respond with 'KO' if a restart isn't needed
548574 delay_ms (1500 ); // 500 ms is too short, 1000 ms is sometimes too short, 1200 ms works fine, play it safe
0 commit comments