MQTT doesn't like static IP address

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?

Have you updated the WAP DHCP address range to exclude 192.168.1.2 from the address pool? If not then you may have two devices with the .2 address.

I don't know how configurable your WAP is, but my own setup uses DHCP for everything with static IP/MAC assignments setup in the WAP. This allows you to manage all IP/MAC address combinations in one place rather than having a mix of DHCP and non-DHCP assignments.

From the RPI config files:

/etc/network/interfaces:

allow-hotplug wlan0
iface wlan0 inet static
  address 192.168.1.1
  netmask 255.255.255.240
##  14 usable addresses.  (Well 13, as this is one of them)
#  network 192.168.1.0
  network 192.168.0.0

/etc/dhcpcd.conf

interface eth0
inform 192.168.0.99/24
static routers=192.168.0.254/24
static domain_name_servers=192.168.0.254/24
static domain_search=192.168.0.254/24

static routers=192.168.0.254

denyinterfaces wlan0

/etc/hostpad/hostapd.conf

cat hostapd/hostapd.conf 
interface=wlan0
driver=nl80211
ssid=PiNet
hw_mode=g
channel=7
wmm_enabled=0
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=************
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP

The wpa_supplicant file is nothing special.

This is getting a bit more "Ras Pi" than Arduino.

But that is what is on the RPI.

I have (from the other thread) a ping test and when I connect the Arduino, it only connects one IP address.
via DHCP it is 7. Via static it is 2.
via DHCP the MQTT works. I get messages coming through and I can send messages to the board. All good.
via static, it pings. But MQTT just won't have a bar of it.

Anything else needed?

Just found this which I think is contributing to the problem:

WiFi config()

And it shows this bit of code:

#include <SPI.h>
#include <WiFi.h>

// the IP address for the shield:
IPAddress ip(192, 168, 0, 177);    

char ssid[] = "yourNetwork";    // your network SSID (name)
char pass[] = "secretPassword"; // your network password (use for WPA, or use as key for WEP)

int status = WL_IDLE_STATUS;

void setup()
{  
  // Initialize serial and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }

  // check for the presence of the shield:
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present");
    while(true);  // don't continue
  }

  WiFi.config(ip);

  // attempt to connect to Wifi network:
  while ( status != WL_CONNECTED) {
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:    
    status = WiFi.begin(ssid, pass);

    // wait 10 seconds for connection:
    delay(10000);
  }

  // print your WiFi shield's IP address:
  Serial.print("IP Address: ");
  Serial.println(WiFi.localIP());
}

void loop () {}

How ever, if I try to do that I get an error:

 WiFi.begin(ssid, password);

  // the IP address for the shield:
  IPAddress ip(192, 168, 1, 2);    


  WiFi.config(ip);
               ^
exit status 1
no matching function for call to 'ESP8266WiFiClass::config(IPAddress&)'

Anyone?

allow-hotplug wlan0
iface wlan0 inet static
  address 192.168.1.1
  netmask 255.255.255.240
##  14 usable addresses.  (Well 13, as this is one of them)
#  network 192.168.1.0
  network 192.168.0.0

The network value is definitely wrong. The commented out value is the right one.
I don't know how the Raspberry Pi interprets these conflicting values but you might have a misconfigured network interface, so the Arduino probably cannot reach the Raspi.