42
42
43
43
#define UNUSED (x ) (void)(x)
44
44
45
- #ifndef RELEASE
46
- #define jsDebug (format , ...) jsWarn(format, ## __VA_ARGS__)
47
- #else
48
- #define jsDebug (format , ...) do { } while(0)
49
- #endif
50
-
51
45
static void sendWifiCompletionCB (
52
46
JsVar * * g_jsCallback , //!< Pointer to the global callback variable
53
47
char * reason //!< NULL if successful, error string otherwise
@@ -233,7 +227,7 @@ static char *wifiReasonToString(uint8_t reason) {
233
227
case WIFI_REASON_UNSUPP_RSN_IE_VERSION :
234
228
return "REASON_UNSUPP_RSN_IE_VERSION" ;
235
229
}
236
- jsDebug ( "wifiReasonToString: Unknown reason %d" , reason );
230
+ jsDebug (DBG_INFO , "wifiReasonToString: Unknown reason %d" , reason );
237
231
return "Unknown reason" ;
238
232
} // End of wifiReasonToString
239
233
@@ -413,7 +407,7 @@ static JsVar *getWifiModule() {
413
407
static int s_retry_num = 0 ;
414
408
415
409
static char * wifiGetEvent (uint32_t event ) {
416
- jsDebug ( "wifiGetEvent: Got event: %d" , event );
410
+ jsDebug (DBG_INFO , "wifiGetEvent: Got event: %d" , event );
417
411
switch (event ) {
418
412
case SYSTEM_EVENT_AP_PROBEREQRECVED :
419
413
return "#onprobe_recv" ;
@@ -442,7 +436,7 @@ switch(event) {
442
436
case SYSTEM_EVENT_WIFI_READY :
443
437
break ;
444
438
}
445
- jsDebug ( "Unhandled wifi event type: %d" , event );
439
+ jsDebug (DBG_INFO , "Unhandled wifi event type: %d" , event );
446
440
return NULL ;
447
441
} // End of wifiGetEvent
448
442
@@ -488,12 +482,12 @@ static esp_err_t event_handler(void *ctx, system_event_t *event)
488
482
* * bssid
489
483
* * reason
490
484
*/
491
- jsDebug ("Wifi: Event(%d):SYSTEM_EVENT_%s\n" ,event -> event_id ,wifiEventToString (event -> event_id ));
485
+ jsDebug (DBG_INFO , "Wifi: Event(%d):SYSTEM_EVENT_%s\n" ,event -> event_id ,wifiEventToString (event -> event_id ));
492
486
493
487
if (event -> event_id == SYSTEM_EVENT_STA_DISCONNECTED ) {
494
488
if (-- s_retry_num > 0 ) {
495
489
esp_wifi_connect ();
496
- jsDebug ("retry to AP connect" );
490
+ jsDebug (DBG_INFO , "retry to AP connect" );
497
491
return ;
498
492
}
499
493
g_isStaConnected = false; // Flag as disconnected
@@ -578,7 +572,7 @@ static esp_err_t event_handler(void *ctx, system_event_t *event)
578
572
jsvObjectSetChildAndUnLock (jsDetails , "netmask" , jsvNewFromString (temp ));
579
573
sprintf (temp , IPSTR , IP2STR (& event -> event_info .got_ip .ip_info .gw ));
580
574
jsvObjectSetChildAndUnLock (jsDetails , "gw" , jsvNewFromString (temp ));
581
- jsDebug ("Wifi: About to emit connect!" );
575
+ jsDebug (DBG_INFO , "Wifi: About to emit connect!" );
582
576
sendWifiEvent (event -> event_id , jsDetails );
583
577
// start mDNS
584
578
const char * hostname ;
@@ -642,7 +636,7 @@ static esp_err_t event_handler(void *ctx, system_event_t *event)
642
636
sendWifiCompletionCB (& g_jsAPStartedCallback , NULL );
643
637
return ESP_OK ;
644
638
}
645
- jsDebug ("Wifi: event_handler -> NOT HANDLED EVENT: %d" , event -> event_id );
639
+ jsDebug (DBG_INFO , "Wifi: event_handler -> NOT HANDLED EVENT: %d" , event -> event_id );
646
640
return ESP_OK ;
647
641
} // End of event_handler
648
642
@@ -658,7 +652,7 @@ void esp32_wifi_init() {
658
652
ESP_ERROR_CHECK (esp_wifi_init (& cfg ));
659
653
ESP_ERROR_CHECK (esp_wifi_set_storage (WIFI_STORAGE_RAM ));
660
654
661
- jsDebug ("esp32_wifi_init complete" );
655
+ jsDebug (DBG_INFO , "esp32_wifi_init complete" );
662
656
663
657
} // End of esp32_wifi_init
664
658
@@ -674,7 +668,7 @@ static void sendWifiCompletionCB(
674
668
JsVar * * g_jsCallback , //!< Pointer to the global callback variable
675
669
char * reason //!< NULL if successful, error string otherwise
676
670
) {
677
- jsDebug ("sendWifiCompletionCB" );
671
+ jsDebug (DBG_INFO , "sendWifiCompletionCB" );
678
672
// Check that we have a callback function.
679
673
if (!jsvIsFunction (* g_jsCallback )){
680
674
return ; // we have not got a function pointer: nothing to do
@@ -699,7 +693,7 @@ static void sendWifiCompletionCB(
699
693
* Perform a soft initialization of ESP32 networking.
700
694
*/
701
695
void jswrap_esp32_wifi_soft_init () {
702
- jsDebug ("jswrap_esp32_wifi_soft_init()" );
696
+ jsDebug (DBG_INFO , "jswrap_esp32_wifi_soft_init()" );
703
697
JsNetwork net ;
704
698
networkCreate (& net , JSNETWORKTYPE_ESP32 ); // Set the network type to be ESP32
705
699
networkState = NETWORKSTATE_ONLINE ; // Set the global state of the networking to be online
@@ -724,7 +718,7 @@ void jswrap_wifi_disconnect(JsVar *jsCallback) {
724
718
g_jsDisconnectCallback = jsvLockAgainSafe (jsCallback );
725
719
726
720
// Call the ESP-IDF to disconnect us from the access point.
727
- jsDebug ("Disconnecting....." );
721
+ jsDebug (DBG_INFO , "Disconnecting....." );
728
722
// turn off auto-connect
729
723
esp_wifi_set_auto_connect (false);
730
724
s_retry_num = 0 ; // flag so we don't attempt to reconnect
@@ -758,7 +752,7 @@ void jswrap_wifi_stopAP(JsVar *jsCallback) {
758
752
}
759
753
err = esp_wifi_set_mode (mode );
760
754
if (err != ESP_OK ) {
761
- jsDebug ("jswrap_wifi_stopAP: esp_wifi_set_mode rc=%d(%s)" , err ,wifiErrorToString (err ));
755
+ jsDebug (DBG_INFO , "jswrap_wifi_stopAP: esp_wifi_set_mode rc=%d(%s)" , err ,wifiErrorToString (err ));
762
756
}
763
757
764
758
if (jsvIsFunction (jsCallback )) {
@@ -772,7 +766,7 @@ void jswrap_wifi_connect(
772
766
JsVar * jsCallback
773
767
) {
774
768
775
- jsDebug ("jswrap_wifi_connect: entry" );
769
+ jsDebug (DBG_INFO , "jswrap_wifi_connect: entry" );
776
770
777
771
// Check that the ssid value isn't obviously in error.
778
772
if (!jsvIsString (jsSsid )) {
@@ -821,7 +815,7 @@ jsDebug("jswrap_wifi_connect: entry");
821
815
}
822
816
jsvUnLock (jsPassword );
823
817
} // End of we had options
824
- jsDebug ("jswrap_wifi_connect: SSID, password, Callback done" );
818
+ jsDebug (DBG_INFO , "jswrap_wifi_connect: SSID, password, Callback done" );
825
819
826
820
// At this point, we have the ssid in "ssid" and the password in "password".
827
821
// Perform an esp_wifi_set_mode
@@ -851,7 +845,7 @@ jsDebug("jswrap_wifi_connect: entry");
851
845
jsError ( "jswrap_wifi_connect: esp_wifi_set_mode: %d(%s), mode=%d" , err ,wifiErrorToString (err ), mode );
852
846
return ;
853
847
}
854
- jsDebug ("jswrap_wifi_connect: esi_wifi_set_mode done" );
848
+ jsDebug (DBG_INFO , "jswrap_wifi_connect: esi_wifi_set_mode done" );
855
849
856
850
// Perform a an esp_wifi_set_config
857
851
wifi_config_t staConfig ;
@@ -861,17 +855,17 @@ jsDebug("jswrap_wifi_connect: entry");
861
855
memcpy (staConfig .sta .password , password , sizeof (staConfig .sta .password ));
862
856
staConfig .sta .bssid_set = false;
863
857
esp_wifi_set_auto_connect (true);
864
- jsDebug ("jswrap_wifi_connect: esp_wifi_set_autoconnect done" );
858
+ jsDebug (DBG_INFO , "jswrap_wifi_connect: esp_wifi_set_autoconnect done" );
865
859
866
860
err = esp_wifi_set_config (ESP_IF_WIFI_STA , & staConfig );
867
861
if (err != ESP_OK ) {
868
862
jsError ( "jswrap_wifi_connect: esp_wifi_set_config: %d(%s)" , err ,wifiErrorToString (err ));
869
863
return ;
870
864
}
871
- jsDebug ("jswrap_wifi_connect: esp_wifi_set_config done" );
865
+ jsDebug (DBG_INFO , "jswrap_wifi_connect: esp_wifi_set_config done" );
872
866
873
867
// Perform an esp_wifi_start
874
- jsDebug ("jswrap_wifi_connect: esp_wifi_start %s" ,ssid );
868
+ jsDebug (DBG_INFO , "jswrap_wifi_connect: esp_wifi_start %s" ,ssid );
875
869
err = esp_wifi_start ();
876
870
if (err != ESP_OK ) {
877
871
jsError ( "jswrap_wifi_connect: esp_wifi_start: %d(%s)" , err ,wifiErrorToString (err ));
@@ -1307,15 +1301,15 @@ JsVar *jswrap_wifi_getAPDetails(JsVar *jsCallback) {
1307
1301
} // End of jswrap_wifi_getAPDetails
1308
1302
1309
1303
void jswrap_wifi_save (JsVar * what ) {
1310
- jsDebug ("Wifi.save" );
1304
+ jsDebug (DBG_INFO , "Wifi.save" );
1311
1305
JsVar * o = jsvNewObject ();
1312
1306
if (!o ) return ;
1313
1307
1314
1308
if (jsvIsString (what ) && jsvIsStringEqual (what , "clear" )) {
1315
1309
JsVar * name = jsvNewFromString (WIFI_CONFIG_STORAGE_NAME );
1316
1310
jswrap_storage_erase (name );
1317
1311
jsvUnLock (name );
1318
- jsDebug ("Wifi.save(clear)" );
1312
+ jsDebug (DBG_INFO , "Wifi.save(clear)" );
1319
1313
return ;
1320
1314
}
1321
1315
@@ -1353,16 +1347,16 @@ void jswrap_wifi_save(JsVar *what) {
1353
1347
jswrap_storage_write (name ,o ,0 ,0 );
1354
1348
jsvUnLock2 (name ,o );
1355
1349
1356
- jsDebug ("Wifi.save: write completed" );
1350
+ jsDebug (DBG_INFO , "Wifi.save: write completed" );
1357
1351
}
1358
1352
1359
1353
void jswrap_wifi_restore (void ) {
1360
- jsDebug ("jswrap_wifi_restore" );
1354
+ jsDebug (DBG_INFO , "jswrap_wifi_restore" );
1361
1355
1362
1356
JsVar * name = jsvNewFromString (WIFI_CONFIG_STORAGE_NAME );
1363
1357
JsVar * o = jswrap_storage_readJSON (name , true);
1364
1358
if (!o ) { // no data
1365
- jsDebug ("jswrap_wifi_restore: No data - Starting default AP" );
1359
+ jsDebug (DBG_INFO , "jswrap_wifi_restore: No data - Starting default AP" );
1366
1360
esp_wifi_start ();
1367
1361
jsvUnLock2 (name ,o );
1368
1362
return ;
@@ -1458,7 +1452,7 @@ void jswrap_wifi_restore(void) {
1458
1452
return ;
1459
1453
}
1460
1454
} else {
1461
- jsDebug ( "Wifi: Both STA AND APSTA are off" );
1455
+ jsDebug (DBG_INFO , "Wifi: Both STA AND APSTA are off" );
1462
1456
}
1463
1457
} // End of jswrap_wifi_restore
1464
1458
@@ -1533,7 +1527,7 @@ void jswrap_wifi_setHostname(
1533
1527
) {
1534
1528
char hostname [256 ];
1535
1529
jsvGetString (jsHostname , hostname , sizeof (hostname ));
1536
- jsDebug ("Wifi.setHostname: %s\n" , hostname );
1530
+ jsDebug (DBG_INFO , "Wifi.setHostname: %s\n" , hostname );
1537
1531
tcpip_adapter_set_hostname (TCPIP_ADAPTER_IF_STA ,hostname );
1538
1532
1539
1533
// now update mDNS
0 commit comments