Copyright © https://mongoose-os.com

Mongoose OS Forum

frame

Wifi Scan returns null result

I am trying to do a wifi scan using mJS invoked via an RPC call. The scan seems to complete by the log output, but the result is returned.

Here is the RPC handler code.

RPC.addHandler('WIFI.Scan', function(args){
    Wifi.scan(function(results){
        if(results === undefined) {
            return;
        } else {
          print(results);
          for (let i = 0; i < results.length; i++) {
            print(results[i].ssid);
          }
         return JSON.stringify(results);
        }
    });
});

And here are the results from calling it from the mos web gui.

Feb 13 02:30:02.407] E0213 02:30:02.407807   14955 ui.go:563] Call complete, success
[Feb 13 02:30:03.661] E0213 02:30:03.661413   14955 ui.go:537] Calling: WIFI.Scan
[Feb 13 02:30:03.915] E0213 02:30:03.915238   14955 stream.go:203] [streamConnectionCodec to /dev/ttyUSB0]: failed to parse frame: "{\"id\":1343941912823,\"src\":\"esp8266_3C843B\",\"dst\":\"mos\",\"result\":}b44ee1c8" invalid character '}' looking for beginning of value
[Feb 13 02:30:06.744] scandone
[Feb 13 02:30:06.748] mgos_wifi_dev_scan_c WiFi scan done, num_res 3
[Feb 13 02:30:06.757] <array> 
[Feb 13 02:30:06.763] DSHAP 
[Feb 13 02:30:06.770] V32H7 
[Feb 13 02:30:06.776] xfinitywifi 

It completes, but Im not seeing the result in the console.

I was thinking it was due to the error being thrown by stream.go

Any help would be appreciated

dhall@arcadia:~/repos/franks-heater-controller-js$ mos version
The Mongoose OS command line tool, v. 20180208-184624/1.26@ab7f50e1+.
Update channel: "release". Checking updates... Up to date.

Comments

  • The results are there:

    [Feb 13 02:30:06.757] <array> 
    [Feb 13 02:30:06.763] DSHAP 
    [Feb 13 02:30:06.770] V32H7 
    [Feb 13 02:30:06.776] xfinitywifi 
    

    return JSON.stringify(results); does nothing because the callback's type is void.

    BTW, 'Wifi.Scan' is already handled by rpc:

    curl http://192.168.0.35/rpc/Wifi.Scan
    {"results": [{"ssid": "guest", "auth": 0, "channel": 1, "rssi": -61}, {"ssid": "apb", "auth": 4, "channel": 1, "rssi": -69}, {"ssid": "naser", "auth": 3, "channel": 6, "rssi": -80}, {"ssid": "ASUS-Home", "auth": 3, "channel": 1, "rssi": -95}]}
    
     mos --port ws://192.168.0.35/rpc call Wifi.Scan
    {
      "results": [
        {
          "ssid": "guest",
          "auth": 0,
          "channel": 1,
          "rssi": -60
        },
        {
          "ssid": "apb",
          "auth": 4,
          "channel": 1,
          "rssi": -68
        },
        {
          "ssid": "naser",
          "auth": 3,
          "channel": 6,
          "rssi": -80
        },
        {
          "ssid": "ASUS-Home",
          "auth": 3,
          "channel": 1,
          "rssi": -93
        }
      ]
    }
    
    Thanked by 1jdhall75
Sign In or Register to comment.