Doodle3D / doodle3d-firmware

The API of the Doodle3D WiFi box. This can for example talk to print3d, save settings, update the firmware etc.
www.doodle3d.com
GNU General Public License v2.0
13 stars 9 forks source link

should open accesspoint when fails connecting to network ssid #41

Open arneboon opened 9 years ago

arneboon commented 9 years ago

see this line here:

https://github.com/Doodle3D/doodle3d-firmware/blob/master/src/main.lua#L104

if connectWith then
        local rv,msg = netconf.associateSsid(connectWith,nil,nil)
        if rv then
            return true, "autowifi: associated -- client mode with ssid '" .. connectWith .. "'"
        else
            return nil, "autowifi: could not associate with ssid '" .. connectWith .. "' (" .. msg .. ")"
        end

in the else it should open up the accesspoint again

arneboon commented 9 years ago

tested the scenario of changing to wifi network with incorrect password. cannot connect (obviously) and then it doesn't create an accesspoint either.

http://192.168.5.1/d3dapi/network/status

{
data: {
bssid: "",
channel: "",
mode: "sta",
noise: -86,
quality_max: 70,
ssid: "",
status: "-1",
statusMessage: "Could not associate with network (incorrect password?)",
txpower: 18
},
msg: "Could not associate with network (incorrect password?)",
status: "success"
}

wifibox log

07-01 14:30:31 (info)     =======rest api (api debugging)=======
07-01 14:30:31 (info)     received request of type POST for network/associate
07-01 14:30:31 (info)     remote IP/port: 10.0.0.102/54570
01-07 14:30:31  [IPC] command: [>>getState]
01-07 14:30:31  [IPC] command: [<<ok]
07-01 14:30:31 (info)     netconfig:associateSsid: werkplaats, true
07-01 14:30:31 (info)     network:setStatus: 1 | Connecting...
07-01 14:30:31 (info)     start wifi scan
07-01 14:30:31 (info)     =======rest api (api debugging)=======
07-01 14:30:31 (info)     received request of type GET for info/status
07-01 14:30:31 (info)     remote IP/port: 10.0.0.102/54526
07-01 14:30:32 (info)     =======rest api (api debugging)=======
07-01 14:30:32 (info)     received request of type GET for network/status
07-01 14:30:32 (info)     remote IP/port: 10.0.0.102/54571
07-01 14:30:32 (info)     network:getStatus
07-01 14:30:32 (info)     =======rest api (api debugging)=======
07-01 14:30:32 (info)     received request of type GET for info/status
07-01 14:30:32 (info)     remote IP/port: 10.0.0.102/54571
07-01 14:30:32 (info)     =======rest api (api debugging)=======
07-01 14:30:32 (info)     received request of type GET for info/status
07-01 14:30:32 (info)     remote IP/port: 10.0.0.102/54571
07-01 14:30:32 (info)     =======rest api (api debugging)=======
07-01 14:30:32 (info)     received request of type GET for info/status
07-01 14:30:32 (info)     remote IP/port: 10.0.0.102/54526
07-01 14:30:33 (info)     =======rest api (api debugging)=======
07-01 14:30:33 (info)     wifi scan done
07-01 14:30:33 (info)     received request of type GET for network/status
07-01 14:30:33 (info)     remote IP/port: 10.0.0.102/54571
07-01 14:30:33 (info)     network:getStatus
07-01 14:30:33 (debug)     reconfiguring component 'wwwredir' (rm)
07-01 14:30:33 (debug)     reconfiguring component 'dnsredir' (rm)
07-01 14:30:33 (debug)     reconfiguring component 'staticaddr' (rm)
07-01 14:30:33 (debug)     reconfiguring component 'wifiiface' (add)
07-01 14:30:33 (debug)     reconfiguring component 'dhcppool' (rm)
07-01 14:30:33 (info)     committing component 'dhcp'
07-01 14:30:33 (info)     committing component 'network'
07-01 14:30:33 (info)     committing component 'uhttpd'
07-01 14:30:33 (info)     reloading component 'dnsmasq'
07-01 14:30:34 (debug)       result reloading component 'dnsmasq' (cmd: '/etc/init.d/dnsmasq reload'):

07-01 14:30:34 (info)     reloading component 'network'
07-01 14:30:34 (info)     =======rest api (api debugging)=======
07-01 14:30:34 (info)     received request of type GET for network/status
07-01 14:30:34 (info)     remote IP/port: 10.0.0.102/54571
07-01 14:30:34 (info)     network:getStatus
07-01 14:30:34 (debug)       result reloading component 'network' (cmd: '/etc/init.d/network reload'):

07-01 14:30:34 (info)     reloading component 'uhttpd'
07-01 14:30:35 (debug)       result reloading component 'uhttpd' (cmd: '/etc/init.d/uhttpd reload'):

07-01 14:30:36 (debug)     associated check 0/5
07-01 14:30:38 (debug)     associated check 1/5
07-01 14:30:40 (debug)     associated check 2/5
07-01 14:30:42 (debug)     associated check 3/5
07-01 14:30:44 (debug)     associated check 4/5
07-01 14:30:44 (info)     network:setStatus: -1 | Could not associate with network (incorrect password?)
07-01 14:30:44 (info)     failed to associate to wifi: werkplaats (Could not associate with network (incorrect password?))
07-01 14:31:49 (info)     =======rest api (api debugging)=======
07-01 14:31:49 (info)     =======rest api (api debugging)=======
07-01 14:31:49 (info)     received request of type GET for sketch/list
07-01 14:31:49 (info)     remote IP/port: 192.168.5.2/54641
07-01 14:31:49 (error)     calling function 'list' in API module 'sketch' somehow failed ('/usr/share/lua/wifibox/rest/api/api_sketch.lua:52: cannot open /root/sketches: No such file or directory')
07-01 14:31:49 (debug)     Response:error (call to function 'sketch/list' failed)
07-01 14:31:49 (info)     received request of type GET for info/status
07-01 14:31:49 (info)     remote IP/port: 192.168.5.2/54642
07-01 14:31:49 (info)     =======rest api (api debugging)=======
07-01 14:31:49 (info)     received request of type GET for printer/listall
07-01 14:31:49 (info)     remote IP/port: 192.168.5.2/54641
07-01 14:31:49 (info)     =======rest api (api debugging)=======
07-01 14:31:49 (info)     =======rest api (api debugging)=======
07-01 14:31:49 (info)     =======rest api (api debugging)=======
07-01 14:31:49 (info)     received request of type GET for config/all
07-01 14:31:49 (info)     remote IP/port: 192.168.5.2/54642
07-01 14:31:49 (info)     received request of type GET for update/status
07-01 14:31:49 (info)     remote IP/port: 192.168.5.2/54641
07-01 14:31:49 (info)     received request of type GET for network/scan
07-01 14:31:49 (info)     remote IP/port: 192.168.5.2/54643
07-01 14:31:49 (info)     start wifi scan
07-01 14:31:49 (debug)     Downloading file 'http://doodle3d.com/updates/images/wifibox-image.index'
07-01 14:31:49 (debug)     error: could not obtain available versions (could not download image index file (1: Generic error))
07-01 14:31:49 (debug)     Response:fail (could not download image index file (1: Generic error))
07-01 14:31:49 (info)     =======rest api (api debugging)=======
07-01 14:31:49 (info)     =======rest api (api debugging)=======
07-01 14:31:49 (info)     received request of type GET for network/status
07-01 14:31:49 (info)     remote IP/port: 192.168.5.2/54644
07-01 14:31:49 (info)     network:getStatus
07-01 14:31:51 (info)     wifi scan done
07-01 14:31:51 (debug)     getSubstitutedSsid unformattedSsid:'Doodle3D-%%MAC_ADDR_TAIL%%' baseApSsid:'nil' cachedApSsid:'nil
07-01 14:31:51 (debug)     getMacAddress
07-01 14:31:51 (debug)       macText: '10:fe:ed:4c:c2:8c
'
07-01 14:31:51 (debug)       macTail:'4CC28C
07-01 14:31:51 (debug)     getSubstitutedSsid unformattedSsid:'Doodle3D-%%MAC_ADDR_TAIL%%' baseApSsid:'Doodle3D-%%MAC_ADDR_TAIL%%' cachedApSsid:'Doodle3D-4CC28C
07-01 14:31:51 (debug)     getSubstitutedSsid unformattedSsid:'Doodle3D-%%MAC_ADDR_TAIL%%' baseApSsid:'Doodle3D-%%MAC_ADDR_TAIL%%' cachedApSsid:'Doodle3D-4CC28C

excerpt from logs:

07-01 14:30:31 (info)     netconfig:associateSsid: werkplaats, true
07-01 14:30:31 (info)     network:setStatus: 1 | Connecting...
07-01 14:30:31 (info)     start wifi scan
07-01 14:30:33 (info)     wifi scan done
07-01 14:30:44 (info)     network:setStatus: -1 | Could not associate with network (incorrect password?)
07-01 14:30:44 (info)     failed to associate to wifi: werkplaats (Could not associate with network (incorrect password?))
arneboon commented 9 years ago

there is a constant M.CONNECTING_FAILED = -1 https://github.com/Doodle3D/doodle3d-firmware/blob/master/src/network/netconfig.lua#L25

but this never leads to creating a hotspot again. why not?

in the earlier hostmodule project such a fallback was implement in place such as the function M.setStatus(code,msg) https://github.com/Doodle3D/doodle3d-firmware/blob/master/src/network/netconfig.lua#L436

pseudo: if CONNECTING_FAILED then M.setupAccessPoint(ssid)

arneboon commented 9 years ago

mind the timing issues... can not be or attempt to be client & accesspoint at same time

peteruithoven commented 9 years ago

I don't think we use these constants to check if something went wrong, it's main usage is communicating the status over the REST API. I think we mostly use the return value of functions to check if something went wrong.

companje commented 9 years ago

I can confirm this issue also happens with version 0.10.5. When entering a wrong password the only way to regain access to the wifibox is by connecting a UTP cable.

peteruithoven commented 9 years ago

Please, please think trough how this is going to work though. There is a big change that when you use our current "start a accesspoint" logic it will never try to connect to that WiFi network again. Because from then on the accesspoint config is the preferred (top) wireless config.

companje commented 9 years ago

Is there some way to detect that it failed to connect to a network (ie wrong password?), if so we should delete that network from /etc/config/wireless. You don't need to 'start a accesspoint' because 'it' should do it automatically if that's the next interface in the configfile.

peteruithoven commented 9 years ago

I don't think we could, not back then anyway. I think we check if it worked by checking ip address and whether the ssid is filled in.

peteruithoven commented 9 years ago

Also see: https://github.com/Doodle3D/doodle3d-client/issues/209