Apparently, this combination of hardware won't accept anything other than WiFiEsp.h together with SoftwareSerial.h (if anyone knows something better/newer than these two, please let me know). Thing is: I can connect to wifi, send and receive data (to an apache server inside my home network) just fine. After my project was almost done, I decided to connect it to a real server on the internet only to discover that ESP-01 couldn't detect my gateway.
#include "WiFiEsp.h"
#include "SoftwareSerial.h"
int pinWifiRX = 6;
int pinWifiTX = 7;
char ssid[64] = "*****";
char pass[32] = "************";
SoftwareSerial Serial1(pinWifiRX, pinWifiTX);
int wifi_status;
void setup() {
Serial.begin(9600);
Serial1.begin(9600);
while(!Serial1) (true);
WiFi.init(&Serial1);
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println(F("No shield"));
while (true) {}
}
IPAddress localIp(192, 168, 1, 60);
IPAddress subnetMask(255, 255, 255, 0);
IPAddress gateway(192, 168, 1, 36);
WiFi.config(localIp); // <--- this line is accepted and works, but the other 3 gives compilation errors
// WiFi.config(localIp, gateway);
// WiFi.config(localIp, gateway, subnetMask);
// WiFi.config(localIp, gateway, subnetMask, gateway);
wifi_status = WiFi.begin(ssid, pass);
if (wifi_status == WL_CONNECTED) {
IPAddress ip;
ip = WiFi.localIP();
Serial.print(F("[WiFiEsp] IP Address: "));
Serial.println(ip);
ip = WiFi.subnetMask();
Serial.print(F("[WiFiEsp] Subnet Mask: "));
Serial.println(ip);
ip = WiFi.gatewayIP();
Serial.print(F("[WiFiEsp] Gateway: "));
Serial.println(ip);
// ip = WiFi.getDNS(); // <--- function doesn't exist
}
}
void loop() {}
Results in:
[WiFiEsp] Initializing ESP module
[WiFiEsp] Initilization successful - 2.2.1
[WiFiEsp] IP address set 192.168.1.60
[WiFiEsp] Connected to *****
[WiFiEsp] IP Address: 192.168.1.60
[WiFiEsp] Subnet Mask: 255.255.255.0
[WiFiEsp] Gateway: 192.168.1.0
As one can see, Subnet Mask is corret, but it "detects" Geteway 192.168.1.0 when it should be 192.168.1.36. This way, I can connect to any device in LAN, but cannot access any address on the internet.
I even tried to send some AT commands directly to SoftwareSerial.h, but I don't get any response.
Will I have to start the whole project over from scratch (using another hardware combination), or is there a way to change gateway by hand? Better yet, is there a way to make it detect the gateway's address correctly?
EDIT: could it be related to the firmware I installed to the ESP-01? I followed this tutorial and got it from this link.
Thanks in advance.
EDIT: in this example, i used the WiFi.config(localIp) function to set a fix IP. I don't really need that, it was just an attempt to make it get the correct Gateway address. Even if I comment that line, the Gateway is still wrong.