Wifi.localIP() returns 0.0.0.0

When I use the below with the Photon

TCPClient client;

client.println(WiFi.localIP());

it sends 0.0.0.0

This worked correctly with the CORE

TJ

@tjtrolinger, Look at this thread, your answer may be in here: Long Term Photon Connection Stability

If the above thread is TL;DR

I’m assuming that you’re not in SYSTEM_MODE(AUTOMATIC). In this case your code might be running ahead of your WiFi connection.
In this case you might want to check for WiFi.connected() WiFi.ready() first and once it becomes true allow for one more Spark.process().
After that you should get a correct IP.

Just for checks you could also add some other means of sending localIP() (Serial, publish, …)

test.cpp:35:25: error: ‘class spark::WiFiClass’ has no member named 'connected’
test.cpp:35:25: error: ‘class spark::WiFiClass’ has no member named ‘Connected’

Sorry, my bad - I thought of WiFi.ready() but typed WiFi.connected() :flushed:

Thanks for the help
The following works:
Wait WiFi.Ready
Spark.process
Wifi.localIP() = Good IP
However, I dont want to connect to the cloud. I simply want to send some data, including the IP address to my own server.

SYSTEM_MODE(MANUAL);
WiFi.on();
WiFi.connect();
Wait for WiFi.Ready
Spark.process
.....
void Indentify(){
    client.print("DeviceID,");
    client.println(ClientID);
    client.print("IPAddress,");
    client.println(WiFi.localIP());
    client.println("DeviceType,MultiSensor");
    client.println("PowerSource,Battery");
    client.print("SignalStrength,");
    client.println(WiFi.RSSI());    
}

This should work just fine too

Try this

SYSTEM_MODE(MANUAL);
...
void setup()
{
  WiFi.on();
  WiFi.connect();

  while(!WiFi.ready())
  {
    Spark.process();
    delay(100);                 // give us some slack ;-)
  }
  Spark.process();

  WiFi.ping(WiFi.gatewayIP());  // just to make sure ;-)
}
...
void Indentify()
{
  client.print("DeviceID,");
  client.println(ClientID);
  client.print("IPAddress,");
  client.println(WiFi.localIP());
  client.println("DeviceType,MultiSensor");
  client.println("PowerSource,Battery");
  client.print("SignalStrength,");
  client.println(WiFi.RSSI());    
}

This does not connect to the cloud.

Im confused. The reference documentation says:

Spark.process() checks the Wi-Fi module for incoming messages from the Cloud, and processes any messages that have come in. It also sends keep-alive pings to the Cloud, so if it’s not called frequently, the connection to the Cloud may be lost.

Thanks for the quick replies :smile:
TJ

1 Like

I guess this is some remainder of the time when there was SPARK_WLAN_Loop() and Spark.process(), which led to some confusion back then and meanwhile got unified into one.
Fact is, Spark.process() checks if the cloud connection is established, if so, it does the above, if not, it just does the WiFi stuff, when WiFi is there, and if not, it doesn’t do a lot at all :wink:

1 Like

Ok Thank You,
TJ