It would seem problems are going to keep happening to me.
I have got the PING issue resolved.
Moving on from that, with the NodeMCU arduino and the next problem arises.
As it was originally - and only for testing - I used DHCP.
Now I am wanting to move on to FIXED IP addresses so it is easier to find/see machines/states.
The other quirk is that I am using MQTT as well. I say quirk only because something is happening that I don't understand HOW it is happening.
Status quo, the sketch works. The Arduino/ModeMCU connects to my WAP.
It gets an IP and it talks to my MQTT quite happily. Sending the dummy test messages which for now are ok.
But when I make it a STATIC IP address, the MQTT fails.
This is the wifi-setup part of the code.
void setup_wifi()
{
delay(10);
// We start by connecting to a WiFi network
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
// With these lines as they are: It works.
// If I make them active and set the IP address, MQTT won't talk.
// IPAddress ip(192,168,1,2);
// IPAddress gateway(192,168,1,1);
// IPAddress subnet(255,255,255,240);
// WiFi.config(ip, gateway, subnet);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println("=================");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
Serial.println("=================");
connected();
}
I've added comments in the code, but here is the story:
The network is 192.168.1.x/28
The WAP is .1, I want the Arduino thingy to be .2 and the broadcast address is .15
With the lines active this is what I see in the serial window:
Connecting to PiNet
.=================
WiFi connected
IP address:
192.168.1.2
=================
Done
Attempting MQTT connection...failed, rc=-2 try again in 5 seconds
Attempting MQTT connection...failed, rc=-2 try again in 5 seconds
Attempting MQTT connection...failed, rc=-2 try again in 5 seconds
Attempting MQTT connection...failed, rc=-2 try again in 5 seconds
Attempting MQTT connection...failed, rc=-2 try again in 5 seconds
But it is being PINGed as .2
How is changing the IP from DHCP to static changing the fact MQTT won't talk?