Connect to internet without connecting to cloud

Hi All,

I’ve trying to connect my photon to my router and then internet without doing Particle.connect(). So, I use WiFi.on() and WiFi.connect() as mentioned in this link: Photon operation w/o cloud connection

I did the trick explained in the “Running with Wi-Fi but no cloud” section but so far I was getting the blinking red LED’s after the device went to blinking green (there was no glowing green at all).

After WiFi.connect(), I do have a bunch of processes that needs TCP and internet connection but not necessarily the Photon/Particle cloud.

Anyone has any idea?

P.S. The code works if I do Particle.connect() and then do the rest of the processes.

What you want is easy to do with semi-automatic mode so you should read the doc on system modes here:

https://docs.particle.io/reference/firmware/photon/#system-modes

Thanks for the insight but I am already on semi-automatic mode. Currently, I am controlling the connection through Particle.connect(), but this forces me to connect to the cloud. What I want to do is just WiFi.on() then WiFi.connect(). If I do this and the WiFi actually has internet connection, this should be an acceptable mode of operation for PHOTON right? Basically I want to connect to some cloud but NOT Photon/Particle’s cloud.
Currently I am having the error (LED blinking red) right after connecting to the WiFi and trying to connect to my cloud server.

You didn’t mention it in your OP, but do you wait for WiFi.ready() before you try to use anything that actually requires an readily established connection?
Failing to do so might well explain the SOS panic you describe.

Just as a heads-up, there used to be some race condition between WiFi.ready() reporting true and the local IP actually being set. If you want to be on the safe side, you may also want to check WiFi.localIP() for validity.

1 Like

What ScruffR said. But, yes, running with Wi-Fi only is a supported setup. I have a dozen Photons running that way and it works fine.

Are you using SYSTEM_THREAD(ENABLED)? And are you using TCP server or client? And which system firmware version?

1 Like

Thanks ScruffR and rickkas7! I am using TCPClient and the firmware version is 0.7.0. And SYSTEM_THREAD(ENABLED) is also used. The error is somewhere caused by my code. Bottomline is this does not happen if I use Particle.connect() that gives glowing blue LED, but it happens (SOS code as ScruffR mentioned) when I am just connecting to WiFi that gives glowing green LED.
I will look deeper into my code, but any more insights are appreciated. Thanks everyone!

As mentioned, the most likely suspect is some kind of race condition.
Just add this after your WiFi.connect() statement

  waitUntil(WiFi.ready);
  Particle.process();  // allow IP to propagate from radio module to µC RAM.

Optionally you could have a loop that waits for WiFi.localIP() to return a valid IP (not 0.0.0.0)

Cool! I could only think of the following loop. Is there a better way to wait for a valid IP?

while(WiFi.localIP().toString().equals("0.0.0.0")) { }

Actually there is an operator bool() overload in IPAddress that lets you just check for if (WiFi.localIP())

And if you want to loop I’d do this

  for (uint32_t ms = millis(); !WiFi.localIP() && millis() - ms < 20000; Particle.process());

This will wait up to 20 seconds for the IP to become valid but allows for the background process to do the housekeeping.