stanleyhuangyc / Freematics

Official source code repository for Freematics
https://freematics.com
433 stars 351 forks source link

Attempt to connect to list of known open Wifi Networks #29

Open DeathfireD opened 7 years ago

DeathfireD commented 7 years ago

It would be nice to have some code for the wifi module that would attempt to connect to any wifi networks that it finds that are not secure. This way as you are driving the device would continuously connect, send data, lose connection, connect again, send the next set of data...etc.

I'd do it but I don't know how to code for it. Here's some pseudo-code though.

//An array of all open wifi networks that don't need passwords that the device has found //You need to check this periodically. Maybe every 5-20 seconds because moving car, duh $connection = false; $insecureWifiArray = {wifi,wifi2,wifi3,wifi3}

//if we have some wifi addressed then start the process of sending data if ($insecureWifiArray) { //attempt to connect to the first one. if it fails then attempt to connect to the next foreach($insecureWifiArray as $wifiAddress){ $connection = connectToWifi($wifiAddress); if($connection) { //we made a connection. Now we need to see if we can actually send and receive data or if this is an open network that requires us to open a web browser to accept some agreement to use. //If you know a way to auto accept these types of open networks then write some code. I don't, so for right now we don't want networks like this. //To check this we can do it one of two ways. Attempt to connect to a website like google and see if it's actual headers are return to us. The second, send actual data somewhere and see if we get an expected response back. $getHTMLHeaderFromSite = getHeader(http://google.com); if($getHTMLHeaderFromSite){ //we successfully got google's headers so now we send our payload to an address of our choosing $sendData = sendPayload(http://MYWEBSERVER.com,$payload); //we have to make sure it was actually sent. If it failed then we need to try again. if($sendData){ //Yay data was set now we can check to see if we still have connection with the current wifi network. //If we don't then start the whole process over again. If we do then send the next payload. }else{ //data failed to send, try again } } } } }