Connection between 2 WeMos D1 on Intranet and Internet
Posted: Thu Jan 30, 2020 10:47 am
Hello there!
I am having 2 WeMos D1's which are communicating normally thru Server/Client with 2 different local routers with IP setup on both.
I want one of those to stop broadcasting on the local IP channel, connect thru the Internet on the router send the data and come back to the normal broadcasting.
So, far I was not able do shut down the initial WiFi(IP channel) and initialize the new one.
Any idea or suggestion about how that can be done?
Here is the portion where I am trying to disconnect the previous connection and create a new one.
I am having 2 WeMos D1's which are communicating normally thru Server/Client with 2 different local routers with IP setup on both.
I want one of those to stop broadcasting on the local IP channel, connect thru the Internet on the router send the data and come back to the normal broadcasting.
So, far I was not able do shut down the initial WiFi(IP channel) and initialize the new one.
Any idea or suggestion about how that can be done?
Here is the portion where I am trying to disconnect the previous connection and create a new one.
Code: Select all
WiFi.mode(WIFI_STA);
ThingSpeak.begin(client2);
//disconnect the previous connection
WiFi.disconnect(true);
WiFi.mode(WIFI_OFF);
WiFi.forceSleepBegin(); //I am not sure if this is necessary
delay(5000);
if(WiFi.status() != WL_CONNECTED){
Serial.print("Attempting to connect to SSID: ");
WiFi.begin(ssid, pass);
while(WiFi.status() != WL_CONNECTED){
Serial.print("> ");
delay(300);
};
Serial.println("\nConnected.");
Serial.print("IP: "); Serial.println(WiFi.localIP()); // I am getting the initially defined IP on the router for the local broadcast
Serial.print("SSID: "); Serial.println(WiFi.SSID());
Serial.print("Signal: "); Serial.println(WiFi.RSSI());
};
int x = ThingSpeak.writeField(myChannelNumber, 1, distance, myWriteAPIKey);
// Check the return code
if(x == 200){
Serial.println("Channel update successful.");
}
else
{
Serial.println("Problem updating channel. HTTP error code " + String(x));
};