We have upgraded the community system as part of the upgrade a password reset is required for all users before login in.

Omega2+ Wifi API



  • @crispyoz said in Omega2+ Wifi API:

    The UCI method of disabling the interface seems like a hack to me.

    Hack???
    For example @Lazar-Demin also said in Really Bad Lag on 6 Nov 2019:

    @Nate are the Omegas connected to a WiFi network?
    If not and the WiFi client interface is active, it will scan for valid networks on a <10 second interval. This scanning kills the network throughput momentarily, forcing it to always be in catch-up mode.

    Sounds like this might be your issue from what you've described.

    To avoid this, just disable the wifi client interface:

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


  • @György-Farkas I respect your right to have an opinion, my opinion is different to yours and @Lazar-Demin on this point

    IMHO is should not be necessary to disable an interface in order to disconnect from a WiFi AP. All that should be required is to "forget" the WiFi credentials, disconnect (stop the network) then when the network restarts the WiFi should not reconnect.

    Calling network stop bring down all interfaces, by definition they should no longer be reconnected to anything. When you bring an interface back up it should read the configuration, that configuration will no longer contain the wifi credentials so the interface should be unable to connect.

    Disabling the interface may work, but in my opinion it is a hack since AP association is an OSI L2 function.



  • @crispyoz said in Omega2+ Wifi API:

    @Pavel-Negrobov if you post the JSON response I can see what the issue is. Error 3 doesn't seem correct.

    Here full output without any reduction (Wifi Connection is active at start):

    root@Omega-3079:/# curl -d '{ "jsonrpc":"2.0", "id":1, "method": "call", "params
    ": [ "00000000000000000000000000000000", "session", "login", { "username":"root"
    , "password":"redhat" } ] }' http://localhost/ubus
    {"jsonrpc":"2.0","id":1,"result":[0,{"ubus_rpc_session":"213ac1e069ca85b390c70570a6a58197","timeout":300,"expires":299,"acls":{"access-group":{"onion-os":["read","write"],"superuser":["read","write"],"unauthenticated":["read"]},"cgi-io":{"*":["write"],"upload":["write"]},"file":{"*":["*"]},"ubus":{"*":["*"],"file":["list","read","exec","write","stat"],"i2c_exp":["pwm-exp","relay-exp","oled-exp"],"iwinfo":["assoclist"],"network.device":["status"],"network.interface":["dump"],"network.interface.wwan":["status"],"onion":["wifi-scan","oupgrade","wifi-setup","omega-led","gpio"],"onion-console":["app-list"],"onion-helper":["*"],"onion-os":["app-list"],"rpc-sys":["reboot","password_set"],"service":["list"],"session":["access","login"],"system":["info","hostname","board"],"uci":["*"]},"uci":{"*":["read","write"],"commit":["write"],"delete":["read","write"],"get":["read","write"],"mjpg-streamer":["read","write"],"network":["read","write"],"onion":["read","write"],"rpcd":["read","write"],"set":["write"],"system":["read","write"],"wireless":["read","write"]}},"data":{"username":"root"}}]}root@Omega-3079:/#
    root@Omega-3079:/#
    root@Omega-3079:/#
    root@Omega-3079:/# curl -d '{"jsonrpc": "2.0", "id": 1, "method": "call", "param
    s": ["213ac1e069ca85b390c70570a6a58197", "uci", "delete", {"config": "wireless",
     "type": "wifi-config", "values": {"ssid": "ZyXEL_GIGA_III" } }] }' http://local
    host/ubus
    {"jsonrpc":"2.0","id":1,"result":[0]}root@Omega-3079:/#
    root@Omega-3079:/#
    root@Omega-3079:/# curl -d '{"jsonrpc": "2.0", "id": 1, "method": "call", "param
    s": ["213ac1e069ca85b390c70570a6a58197", "uci", "commit", {"config": "wireless"}
    ]}' http://localhost/ubus
    {"jsonrpc":"2.0","id":1,"result":[0]}root@Omega-3079:/#
    root@Omega-3079:/# curl -d '{"jsonrpc": "2.0", "id": 1, "method": "call", "param
    s": ["213ac1e069ca85b390c70570a6a58197", "network", "restart", {}]}' http://loca
    lhost/ubus
    [  916.850259] br-wlan: port 1(ra0) entered disabled state
    [  916.869218] device ra0 left promiscuous mode
    [  916.873758] br-wlan: port 1(ra0) entered disabled state
    [  916.922481] br-wlan: port 1(ra0) entered blocking state
    [  916.927796] br-wlan: port 1(ra0) entered disabled state
    [  916.933541] device ra0 entered promiscuous mode
    [  916.977410] br-wlan: port 1(ra0) entered blocking state
    [  916.982786] br-wlan: port 1(ra0) entered forwarding state
    {"jsonrpc":"2.0","id":1,"result":[0]}root@Omega-3079:/#
    root@Omega-3079:/# [  928.118990] br-wlan: port 1(ra0) entered disabled state
    [  928.132213] device ra0 left promiscuous mode
    [  928.136762] br-wlan: port 1(ra0) entered disabled state
    [  928.220242] IPv6: ADDRCONF(NETDEV_UP): br-wlan: link is not ready
    [  935.131816] br-wlan: port 1(ra0) entered blocking state
    [  935.137170] br-wlan: port 1(ra0) entered disabled state
    [  935.142880] device ra0 entered promiscuous mode
    [  935.147650] br-wlan: port 1(ra0) entered blocking state
    [  935.153001] br-wlan: port 1(ra0) entered forwarding state
    [  935.159845] IPv6: ADDRCONF(NETDEV_CHANGE): br-wlan: link becomes ready
    
    root@Omega-3079:/# curl -d '{"jsonrpc": "2.0", "id": 1, "method": "call", "param
    s": ["213ac1e069ca85b390c70570a6a58197", "network", "stop", {}]}' http://localho
    st/ubus
    {"jsonrpc":"2.0","id":1,"result":[3]}root@Omega-3079:/#
    root@Omega-3079:/# curl -d '{"jsonrpc": "2.0", "id": 1, "method": "call", "param
    s": ["213ac1e069ca85b390c70570a6a58197", "network", "start", {}]}' http://localh
    ost/ubus
    {"jsonrpc":"2.0","id":1,"result":[3]}root@Omega-3079:/#
    root@Omega-3079:/#
    

    My router is ZyXEL Keenetic GIGA 3



  • @crispyoz
    After these commands
    uci set wireless.sta.disabled='1'; uci commit wireless; wifi
    only the option disabled '0' line will change to option disabled '1' in the config wifi-iface 'sta' section of the /etc/config/wireless file.
    So after these commands
    uci set wireless.sta.disabled='0'; uci commit wireless; wifi
    Omega2 will be able to reconnect to that WiFi network.

    Please check it (before and after) with
    cat /etc/config /wireless
    or
    uci show wireless
    wireless.sta.disabled='1' vs. wireless.sta.disabled='0'



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

    You can look at what ubus methods are available using the command ubus -v list network



  • @György-Farkas Obviously I understand what it does, I just don't agree with the approach.


  • administrators

    @crispyoz We're open to suggestions on this, what kind of approach would you prefer?



  • @Lazar-Demin This thread has got a little off track and in fact there is no change required. My point was that disabling the interface in order to reconfigure the network may work but the correct approach is to utilise the network restart or reload approach since this is how linux networking was designed to function. Disabling the interface may work today but in the future there may be side effects of this approach.



  • @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.