Hi @lakshan if I set the static IP address in case of disconnection, the rpcWiFi library no longer carries out the re-connection remaining in an idle state even if I try to reset the RTL8720 with the command:
pinMode(RTL8720D_CHIP_PU, OUTPUT);
digitalWrite(RTL8720D_CHIP_PU, LOW);
delay(500);
digitalWrite(RTL8720D_CHIP_PU, HIGH);
delay(500);
Do you have any suggestions?
Hi @Gianfry60,
You need to initialize the Wi-Fi libraries again after resetting the RTL8720.
Best Regards,
Lakshantha
Hi @lakshan, I tried to run a simplified sketch to test what you told me but unfortunately the result is always the same after a disconnection the WIFi does not reconnect anymore. I am attaching the complete sketch so you can see if I’m doing something wrong or if the library needs to be modified.
Thank you
Click to see the code
#include <rpcWiFi.h>
#include “Credentials.h”
IPAddress local_IP(192, 168, 0, 87);
IPAddress gateway(192, 168, 0, 1);
IPAddress subnet(255, 255, 255, 0);
IPAddress primaryDNS(8, 8, 8, 8); //optional
IPAddress secondaryDNS(8, 8, 4, 4); //optional
void setup()
{
Serial.begin(115200);
while (!Serial)
{
};
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, pass);
if (WiFi.status() == WL_CONNECTED)
{
if (!WiFi.config(local_IP, gateway, subnet, primaryDNS, secondaryDNS))
{
Serial.println("STA Failed to configure");
}
Serial.println("");
Serial.println("WiFi connected!");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
Serial.print("ESP Mac Address: ");
Serial.println(WiFi.macAddress());
Serial.print("Subnet Mask: ");
Serial.println(WiFi.subnetMask());
Serial.print("Gateway IP: ");
Serial.println(WiFi.gatewayIP());
Serial.print("DNS: ");
Serial.println(WiFi.dnsIP());
}
else
{
Serial.println("WiFi Connection failed");
}
}
void loop()
{
if (WiFi.status() == WL_CONNECTED)
{
Serial.println("WiFi Connect");
}
else
{
Serial.println("WiFi disconnect, try to reconnected");
pinMode(RTL8720D_CHIP_PU, OUTPUT);
digitalWrite(RTL8720D_CHIP_PU, LOW);
delay(500);
digitalWrite(RTL8720D_CHIP_PU, HIGH);
delay(500);
WiFi.begin(ssid, password);
if (WiFi.status() == WL_CONNECTED)
{
if (!WiFi.config(local_IP, gateway, subnet, primaryDNS, secondaryDNS))
{
Serial.println("STA Failed to configure");
}
Serial.println("");
Serial.println("WiFi connected!");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
Serial.print("ESP Mac Address: ");
Serial.println(WiFi.macAddress());
Serial.print("Subnet Mask: ");
Serial.println(WiFi.subnetMask());
Serial.print("Gateway IP: ");
Serial.println(WiFi.gatewayIP());
Serial.print("DNS: ");
Serial.println(WiFi.dnsIP());
}
else
{
Serial.println("WiFi Connection failed");
}
}
delay(1000);
}
Hello @Gianfry60,
I had a working solution for static Ip.
-https://github.com/RoSchmi/AzureDataSender_Wio_Terminal/blob/master/src/main.cpp
I think that you will find it in the code.
Hi @Gianfry60,
I have tested on my end and found out that you need to have the code like this:
pinMode(RTL8720D_CHIP_PU, OUTPUT);
digitalWrite(RTL8720D_CHIP_PU, LOW);
delay(500);
digitalWrite(RTL8720D_CHIP_PU, HIGH);
delay(500);
tcpip_adapter_init();
WiFi.begin(ssid, password);
Best Regards,
Lakshantha
Hi @lakshan, I tried to insert the line tcpip_adapter_init (); but on my end it doesn’t work. Can you send me a complete sketch you are testing so I can do the same?
Thank you
Sure. Here is my simple test code. It keeps on disconnecting and reconnecting to Wi-Fi in a loop.
#include "rpcWiFi.h"
const char* ssid = "SSID";
const char* password = "Password";
void setup() {
Serial.begin(115200);
while(!Serial);
}
void loop() {
WiFi.begin(ssid, password);
Serial.println("Connected to the WiFi network");
Serial.print("IP Address: ");
Serial.println(WiFi.localIP());
pinMode(RTL8720D_CHIP_PU, OUTPUT);
digitalWrite(RTL8720D_CHIP_PU, LOW);
delay(500);
digitalWrite(RTL8720D_CHIP_PU, HIGH);
delay(500);
tcpip_adapter_init();
WiFi.begin(ssid, password);
Serial.println("Connected to the WiFi network");
Serial.print("IP Address: ");
Serial.println(WiFi.localIP());
}
Here is my output
Hope it works for you.
Best Regards,
Lakshantha
hi @lakshan, thank you for your help but this example uses DHCP and up to here I got there too. Problems arise when I want to set a fixed IP address. I noticed that the WiFi card config needs to be set after initializing the card. I thought that if I reset the WiFi card at Hardware level it was enough to re-initialize the card and reset the configuration of the fixed IP. Despite being a work arround I hoped it would work, but unfortunately it doesn’t. My aim is to set the WiFi card with a fixed address and recover any lost connection (for example the AP is turned off or reset). I was unable to do a configuration that could do these operations. With the library with AT commands all this worked perfectly just simply re-initialize the WiFi card, without even resetting the fixed IP address. How can we solve?
Thanks again for the support.
Gianfranco
Hi @Gianfry60,
Could you try this example please? It is with Static IP. I have tested on my end and it works.
#include <rpcWiFi.h>
const char* ssid = "SSID";
const char* password = "Password";
IPAddress local_IP(192, 168, 1, 167);
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 255, 0);
IPAddress primaryDNS(8, 8, 8, 8);
IPAddress secondaryDNS(8, 8, 4, 4);
void setup()
{
Serial.begin(115200);
while(!Serial);
}
void loop()
{
WiFi.begin(ssid, password);
if (!WiFi.config(local_IP, gateway, subnet, primaryDNS, secondaryDNS)) {
Serial.println("STA Failed to configure");
}
Serial.println("WiFi connected!");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
pinMode(RTL8720D_CHIP_PU, OUTPUT);
digitalWrite(RTL8720D_CHIP_PU, LOW);
delay(500);
digitalWrite(RTL8720D_CHIP_PU, HIGH);
delay(500);
tcpip_adapter_init();
WiFi.begin(ssid, password);
if (!WiFi.config(local_IP, gateway, subnet, primaryDNS, secondaryDNS)) {
Serial.println("STA Failed to configure");
}
Serial.println("WiFi connected!");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
}
This is the output:
Best Regards,
Lakshantha
Hi @lakshan, Something is not working because if I use your sketch and try to turn off the A.P. the serial monitor keeps writing:
Click to see the serial monitor
17: 38: 45.710 -> WiFi connected!
17: 38: 45.710 -> IP address: 192.168.0.87
17: 38: 50.875 -> WiFi connected!
17: 38: 50.875 -> IP address: 192.168.0.87
Obviously this is an error as the connection cannot be active. The absurd is that if I start the sketch when the AP is off it continues to write:
Click to see the serial monitor
17: 41: 21.360 -> WiFi connected!
17: 41: 21.360 -> IP address: 192.168.0.87
As a counter check I tried to change your code by inserting a connection check (I’ll post the code below)
and in this case you can see that the serial monitor returns me that it is always disconnected:
Click to see the serial monitor
18: 05: 31.092 -> IP address: 192.168.0.87
18: 05: 35.324 -> WiFi connected!
18: 05: 35.359 -> IP address: 192.168.0.87
18: 05: 42.449 -> WiFi not connected !!!
18: 05: 46.604 -> WiFi not connected !!!
18: 05: 53.727 -> WiFi not connected !!!
18: 05: 57.847 -> WiFi not connected !!!
18: 06: 04.985 -> WiFi not connected !!!
18: 06: 09.146 -> WiFi not connected !!!
But the interface, after AP reset, is connected and responds to ping.
Click to see the command console
Reply from 192.168.0.87: bytes = 32 time = 8ms TTL = 255
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Reply 192.168.0.101: Destination host not reachable.
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Reply from 192.168.0.87: bytes = 32 time = 4ms TTL = 255
Request timed out.
Request timed out.
Reply from 192.168.0.87: bytes = 32 time = 7ms TTL = 255
Reply from 192.168.0.87: bytes = 32 time = 4ms TTL = 255
Request timed out.
Request timed out.
Reply from 192.168.0.87: bytes = 32 time = 5ms TTL = 255
Reply from 192.168.0.87: bytes = 32 time = 4ms TTL = 255
Sure something is wrong with the WiFi.status () == WL_CONNECTED function.
Is there a different command?
I await your considerations
Thank you
Gianfranco
Click to see the code
#include “rpcWiFi.h”
const char *ssid = “***********”;
const char password = "***********";
IPAddress local_IP(192, 168, 0, 87);
IPAddress gateway(192, 168, 0, 1);
IPAddress subnet(255, 255, 255, 0);
IPAddress primaryDNS(8, 8, 8, 8);
IPAddress secondaryDNS(8, 8, 4, 4);
void setup()
{
Serial.begin(115200);
while (!Serial)
{
};
}
void loop()
{
WiFi.begin(ssid, password);
if (WiFi.status() == WL_CONNECTED)
{
Serial.println("WiFi connected!");
}
else
{
Serial.println("WiFi not connected!!!!!");
}
if (!WiFi.config(local_IP, gateway, subnet, primaryDNS, secondaryDNS))
{
Serial.println("STA Failed to configure");
}
if (WiFi.status() == WL_CONNECTED)
{
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
}
delay(2000);
pinMode(RTL8720D_CHIP_PU, OUTPUT);
digitalWrite(RTL8720D_CHIP_PU, LOW);
delay(500);
digitalWrite(RTL8720D_CHIP_PU, HIGH);
delay(500);
tcpip_adapter_init();
WiFi.begin(ssid, password);
if (WiFi.status() == WL_CONNECTED)
{
Serial.println("WiFi connected!");
}
else
{
Serial.println("WiFi not connected!!!!!");
}
if (!WiFi.config(local_IP, gateway, subnet, primaryDNS, secondaryDNS))
{
Serial.println("STA Failed to configure");
}
if (WiFi.status() == WL_CONNECTED)
{
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
}
}
Hi @Gianfry60,
I will look into this and get back to you after testing. Please wait patiently.
Best Regards,
Lakshantha