diff --git a/src/core/serialcmds.cpp b/src/core/serialcmds.cpp index e561da61..477b13a1 100644 --- a/src/core/serialcmds.cpp +++ b/src/core/serialcmds.cpp @@ -347,7 +347,7 @@ bool processSerialCommand(String cmd_str) { //Serial.print("frequency:"); //Serial.println(frequency); String r = ""; - if(cmd_str.startsWith("subghz rx_raw")) + if(cmd_str.startsWith("subghz rx_raw") || cmd_str.startsWith("subghz rx raw")) r = RCSwitch_Read(frequency, 10, true); // true -> raw mode else r = RCSwitch_Read(frequency, 10, false); // false -> decoded mode diff --git a/src/modules/bjs_interpreter/interpreter.cpp b/src/modules/bjs_interpreter/interpreter.cpp index 6789a41b..f9ef14bc 100644 --- a/src/modules/bjs_interpreter/interpreter.cpp +++ b/src/modules/bjs_interpreter/interpreter.cpp @@ -94,14 +94,85 @@ static duk_ret_t native_getBoard(duk_context *ctx) { } // Wifi Functions -static duk_ret_t native_wifiConnect(duk_context *ctx) { +static duk_ret_t native_wifiConnectDialog(duk_context *ctx) { wifiConnectMenu(); return 0; } + +static duk_ret_t native_wifiConnect(duk_context *ctx) { + // usage: wifiConnect(ssid : string ) + // usage: wifiConnect(ssid : string, timeout_in_seconds : number) + // usage: wifiConnect(ssid : string, timeout_in_seconds : number, pwd : string) + String ssid = duk_to_string(ctx, 0); + int timeout_in_seconds = 10; + if(duk_is_number(ctx, 1)) timeout_in_seconds = duk_to_number(ctx, 1); + + bool r = false; + + Serial.println("Connecting to: " + ssid); + + if(duk_is_string(ctx, 2)) { + String pwd = duk_to_string(ctx, 2); + WiFi.begin(ssid, pwd); + } else { + WiFi.begin(ssid); + } + + int i=0; + do { + delay(1000); + i++; + if(i>timeout_in_seconds) { + Serial.println("timeout"); + break; + } + } while (WiFi.status() != WL_CONNECTED); + + if(WiFi.status() == WL_CONNECTED) { + r = true; + wifiIP = WiFi.localIP().toString(); // update global var + } + + duk_push_boolean(ctx, r); + return 1; +} + +static duk_ret_t native_wifiScan(duk_context *ctx) { + // Example usage: `print(wifiScan()[0].SSID)` + wifiDisconnect(); + WiFi.mode(WIFI_MODE_STA); + Serial.println("Scanning..."); + int nets = WiFi.scanNetworks(); + duk_push_array(ctx); + int arrayIndex = 0; + duk_idx_t obj_idx; + for(int i=0; i