Omega2+ Wifi API



  • @crispyoz said in Omega2+ Wifi API:

    @Pavel-Negrobov Use network reload instead of restart, the methods stop and start don't exist, hence the error 3 response.

    Restart has no effect:

    # curl -d '{"jsonrpc": "2.0", "id": 1, "method": "call", "params": ["3f116f85f4e1ad269f7b22ac539443b3", "uci", "delete", "config": "wireless",  "type": "wifi-config", "values": {"ssid": "ZyXEL_GIGA_III" } }] }' http://localhost/ubus
    {"jsonrpc":"2.0","id":1,"result":[0]}
    # curl -d '{"jsonrpc": "2.0", "id": 1, "method": "call", "params": ["3f116f85f4e1ad269f7b22ac539443b3", "uci", "commit", {"config": "wireless"}]}' http://localhost/ubus
    {"jsonrpc":"2.0","id":1,"result":[0]}
    # curl -d '{"jsonrpc": "2.0", "id": 1, "method": "call", "params": ["3f116f85f4e1ad269f7b22ac539443b3", "network", "reload", {}]}' http://localhost/ubus
    {"jsonrpc":"2.0","id":1,"result":[0]}
    

    Thats all. Wifi restart process does not started.
    My firmware version is 0.3.2 b240. Today I will try to set the last 242 build.



  • @Pavel-Negrobov If you examine your /etc/config/wireless you will see the ssid and key are still present on the sta interface section so the device will still be associated with the ap.



  • No, /etc/config/wireless is clean:

    # cat /etc/config/wireless
    
    config wifi-device 'radio0'
            option type 'ralink'
            option variant 'mt7628'
            option country 'US'
            option hwmode '11g'
            option htmode 'HT40'
            option channel 'auto'
            option disabled '0'
            option device_mode 'apsta'
            option op_mode 'preference'
    
    config wifi-iface 'ap'
            option device 'radio0'
            option mode 'ap'
            option network 'wlan'
            option ifname 'ra0'
            option encryption 'psk2'
            option key '12345678'
            option disabled '0'
            option ssid 'Omega-3079'
    
    config wifi-iface 'sta'
            option device 'radio0'
            option mode 'sta'
            option ifname 'apcli0'
            option encryption 'psk2'
            option ssid 'YourSsidHere'
            option key 'YourPasswordHere'
            option network 'wwan'
            option disabled '1'
            option led 'omega2p:blue:wifi'
    

    okay, I can call

    uci set wireless.sta.disabled='1'; uci commit wireless; wifi
    uci set wireless.sta.disabled='0'; uci commit wireless; wifi
    

    as György Farkas said.

    PS.
    On latest 242 build all the same.



  • @Pavel-Negrobov sta shows as disabled so I'm not sure how it would be associated with anything. If @György-Farkas solution works for you you should go with that.



  • @Pavel-Negrobov
    Omega2 connects to a new WiFi network:
    wifisetup add -ssid <ssid> -encr <encryption type> -password <password>

    Omega2 disconnects from that WiFi network (and clears all saved network configuration / all saved credentials):
    wifisetup clear

    Yes, this is so ugly and maybe this is too simple. 😉



  • Thanks to all. I put all of this to my Python soft and write results here.



  • Hi, guys again.
    One question stay unresolved. If I am trying to add AP with invalid password, all commands finished successfully, but connection process is

    root@Omega-3079:~# curl -d '{"jsonrpc": "2.0", "id": 1, "method": "call", "param
    s": ["03ca3d0dd751363549c11eb3aabe2f58", "network", "restart", {}]}' http://loca
    lhost/ubus
    [  369.968407] br-wlan: port 1(ra0) entered disabled state
    [  369.998913] device ra0 left promiscuous mode
    [  370.003511] br-wlan: port 1(ra0) entered disabled state
    [  370.042661] br-wlan: port 1(ra0) entered blocking state
    [  370.047976] br-wlan: port 1(ra0) entered disabled state
    [  370.053844] device ra0 entered promiscuous mode
    [  370.088398] br-wlan: port 1(ra0) entered blocking state
    [  370.093775] br-wlan: port 1(ra0) entered forwarding state
    {"jsonrpc":"2.0","id":1,"result":[0]}root@Omega-3079:~# [  381.118681] br-wlan: port 1(ra0) entered disabled state
    [  381.131892] device ra0 left promiscuous mode
    [  381.136358] br-wlan: port 1(ra0) entered disabled state
    [  381.211446] IPv6: ADDRCONF(NETDEV_UP): br-wlan: link is not ready
    [  386.173252] br-wlan: port 1(ra0) entered blocking state
    [  386.178567] br-wlan: port 1(ra0) entered disabled state
    [  386.184303] device ra0 entered promiscuous mode
    [  386.189068] br-wlan: port 1(ra0) entered blocking state
    [  386.194420] br-wlan: port 1(ra0) entered forwarding state
    [  386.201707] IPv6: ADDRCONF(NETDEV_CHANGE): br-wlan: link becomes ready
    [  388.425631] Interface apcli0 link up! (WPA2PSK AES)
    [  403.545858] Interface apcli0 link up! (WPA2PSK AES)
    [  418.665958] Interface apcli0 link up! (WPA2PSK AES)
    [  434.426001] Interface apcli0 link up! (WPA2PSK AES)
    [  444.430108] Interface apcli0 link up! (WPA2PSK AES)
    [  449.148040] Interface apcli0 link up! (WPA2PSK AES)
    [  464.027064] Interface apcli0 link up! (WPA2PSK AES)
    ..................
    

    This is сontinues endlessly until I am shuts down wifi or delete AP.

    How to check Wifi connection errors?



  • @Pavel-Negrobov I don't know any way of actually checking the WiFi is successfully connected since UCI just changes the configuration. I just try to programatically open a connection to a known good host and check the response code.



  • @crispyoz said in Omega2+ Wifi API:

    @Pavel-Negrobov I don't know any way of actually checking the WiFi is successfully connected since UCI just changes the configuration. I just try to programatically open a connection to a known good host and check the response code.

    I think to call something like '/bin/ubus call network.interface.wwan status' and check result during some timeout. For example 30 sec.



  • @Pavel-Negrobov assuming you are using dhcp could check if you have a valid ip on that interface with ubus call network.interface.wwan status and examine the "ipv4-address.address"


Log in to reply
 

Looks like your connection to Community was lost, please wait while we try to reconnect.