WIFIO is a dual Arduino WIFI module (ESP8266+ATMEGA328P) FCC approve-able with transferable licence. Can use the 328P for I/O expansion also...

Moderator: igrr

User avatar
By Craigbear
#93790 Hi all i got some code and want the create a portable miner so when i get to a location my miner will automatically connect to the wifi. can anyone help.. i have downloaded the miner code just not sure how to create this. i have also looked at a repeater but thats another miner taken up. i was hoping todo this in the code.. if this is successful im looking at making 4 module system..

i will include my steps and progress on here

Code: Select all#include <ESP8266WiFi.h>
#include <FirebaseArduino.h>
#include <ESP8266Ping.h>



const char *ssid1 = "candyxt";// X
const char *password1 = "candyxt123";

const char *ssid2 = "candyasus";
const char *password2 = "candyasus123";

//#define TCP_MSS whatever
//#define LWIP_IPV6 whatever
//#define LWIP_FEATURES whatever
//#define LWIP_OPEN_SRC whatever

#define led D1

const IPAddress remote_ip(208, 80, 153, 224);
//const IPAddress remote_ip(8, 8, 8, 8); //Google

void setup() {
  Serial.begin(9600);
  while (WiFi.status() == WL_DISCONNECTED) {
    myNetwork();
  }
  Serial.println("Successfully Connected ");

}
void myNetwork() {
  int flag = 1;
  Serial.println("Searching Wifi......");
  int network = WiFi.scanNetworks();          //5
  for (int i = 0 ; i < network; i++) {
    switch (flag) {
      case 1: 
        flag =2;
        if (WiFi.SSID(i) == ssid1) {
          WiFi.begin(ssid1, password1);
          Serial.println("/n Wifi Found");
          delay(2000);
          Serial.println("Connecting with candyxt Please Wait ");
          delay(8000);
          break;
        }
        case 2:
           flag =1;
           if (WiFi.SSID(i) == ssid2) {
          WiFi.begin(ssid2, password2);
          Serial.println("/n Wifi Found");
          delay(2000);
          Serial.println("Connecting with candyasus Please Wait ");
          delay(8000);
          break;
        }
    }
  }

}


void loop() {
  if (!Ping.ping(remote_ip)) {
    Serial.println("No Internet");
    myNetwork();
  } else {
    Serial.println("Internet Access");
 

  }
}

//im wanting to add the mining code here. after the wifi connection is made.
User avatar
By Inq720
#94229 Are you asking for it to work like your cell phone or laptop WiFi? (As you move it to a new location AND have already put in the password for that location previously it'll automatically connect up)?

My InqPortal library does it with up to five configured routers. Unfortunately, it is not based on the Arduino Core libraries #include <ESP8266WiFi.h>. I've never tried it, but trying to compile InqPortal and Arduino Core together will probably blow chunks. But here is the procedure I did to mimic that WiFi behavior. I'm sure it's possible with the Arduino Core version as well.

  1. Keep an array of your routers credentials
  2. I keep it ordered by the most recently connected.
  3. When it boots, try to connect to the first one.
  4. If it fails, scan for available routers
  5. Find the strongest one that is also in your list.
  6. Connect to it.
  7. If you plan on moving it with it still powered, you'll need to catch the disconnect event and jump to step (4).

Or if you're just want a brute force method with what you already have... and not deal with the scanning, you could just start with your first connection. If it fails try the second, so-forth and so-on till you get one.