TheThingsProducts / gateway

The Things Kickstarter Gateway
https://www.thethingsindustries.com/docs/gateways/models/thethingskickstartergateway
54 stars 20 forks source link

Fix/keep existing wifi config #38

Closed KrishnaIyer closed 6 years ago

KrishnaIyer commented 6 years ago

Copy of commit message:

The previous WiFi patch that restricted AP mode to only when there is no WiFi config causes issues with gateways with exisiting WiFi config.
Though the two are not directly related, the patch seems to have uncovered an existing problem.
In the current code, the WiFi ping timeout is 8s (4x2 tries). But practically, it takes 10-15s to re-connect. So, after 8s, we go to WAIT_FOR_NETWORK state where the WiFi module is restarted.
This causes a loop since everytime the pings timeout at 8s and restart the WiFi module.
By increasing the ping timeout to a higher value of 120s (60x2 tries), this issue is not observed since the WiFi connects after roughly after 15-20s.

This issue was not observed in gateways where the WiFi config was erased since the initial wait for connection already takes into account the extra time needed to establish a connection.

Two things to be considered in the future
- Select an appropriate value for the timeout based on testing instead an arbitirarily chosen value.
- Solve the actual problem of the WiFi driver (which is beyond the scope of the Application code)

Together with #26 this fixes #33, fixes #10 and may be related to #8 and #24

htdvisser commented 6 years ago

So the only actual change here, was to change the PING_TIMEOUT?

Removing wifiConnectStartTick seems unrelated, but if it wasn't used, then I think it's fine to clean it up.

KrishnaIyer commented 6 years ago

Yes PING_TIMEOUT was the only change. The variable was unnecessary and in the same context so I removed it.

martinichka commented 6 years ago

@KrishnaIyer have you tested it with a router without internet (so it will receive DHCP but ping will fail) and then recover internet? Does it recover the connection?

KrishnaIyer commented 6 years ago

@martinichka : I'll test that today and let you know.

KrishnaIyer commented 6 years ago

@martinichka : I tested this and the connection recovers. Procedure