Local Network Mode?

I’m trying to run my Photon on a wifi network not connected to the internet.
It seems to be giving me trouble (I assume because it cannot connect to the cloud).

Is there any solution to this?

For context, I’m passing data over WIFI using OSC (UDP packets).

Yes - what you want to explore are system modes.

I found a couple other forum posts answering the question.

Currently I have:
Set system mode to semi_automatic (SYSTEM_MODE(SEMI_AUTOMATIC):wink:
and connect to wifi (WiFi.connect():wink:

Both these work but the problem is now I am not getting a proper IP address (address returns 0.0.0.0 when I print it).

Any ideas?

Are you checking WiFi.ready() before you get the local IP address?

https://docs.particle.io/reference/firmware/photon/#wifi-ready-

Yup.
WiFi.ready() returns 1.

Basics of the program are:

Serial.begin(115200);

WiFi.setCredentials("mifi"); //my router SSID (no password)
WiFi.connect();

Serial.print("Wifi Ready: ");
Serial.println(WiFi.ready());

udp.begin(inPort);

Serial.print(F("ip : ")); Serial.println(WiFi.localIP());
Serial.print(F(" : ")); Serial.print(inPort);

To avoid flash wear you might want to check WiFi.hasCredentials()before you do WiFi.setCredentials() since your credentials will be stored across power cycles anyway.

Next if you want to use WiFi, you should wait for it like this

  ...
  WiFi.connect();

  while (!WiFi.ready())
    Particle.process();
  Particle.process();  // once more to allow for IP being transfered
                      // from WiFi module to user space 
  ...

BTW: You can drop the F() macro - it’s not needed on ARM Cortex processors.

Thanks for the heads up. This is just example code and it will change in the final application.
Any ideas on the IP address issue?

Have you tried my suggested code?

This at least did solve the IP 0.0.0.0 on the Core.

If this doesn’t do the trick, you could add a WiFi.ping(WiFi.gatewayIP()); too.

In truth, I didn’t try you suggestion. Primarily because the documentation says:

Particle.process() checks the Wi-Fi module for incoming messages from the Cloud, and processes any messages that have come in.

and I am specifically avoiding connecting to the cloud (especially since it’s all WLAN and no internet connection). I apologize for being rude but given the context of the documentation it didn’t seem like your suggestion was going to help.

Ah @sabjorn - you’re totally right. The docs aim to keep things simple, but even when disconnected from the cloud, Particle.process() will help with fetching the IP details, since they are only fetched after connecting and on the next call to Particle.process().

1 Like

Sometimes people do know some background the docs might “omit” (for one reason or the other) and trying out doesn’t hurt either :wink:

So here’s an update:

Particle.process() (any way that info can be added to the docs?) works. But, it turns out part of my problem is WiFi.setCredentials() does not work the way I expected it to. I ended up having to add the router I wanted to use to the Photon using the Particle Setup.

Any ideas on the WiFi.setCredentials() part?

If you tell me what’s wrong, I can try to help - in what way did WiFi.setCredentials() not work for you?

Attempted to use setCredentials() to connect to a wifi network (which I had not previously setup using Particle Setup). Network would not connect.

I will point out that setCredentials() (with the SSID and password) was in the setup() loop. Is it possible having it always in the setup loop prevented it from connecting?

If you were in AUTOMATIC mode then the system tries to connect before running setup() so it wouldn’t have worked.

You could try SEMI_AUTOMATIC mode, where setup() is run before the connection is made. Also STARTUP(WiFi.setCredentials()) can be used to set the credentials early on.

Radical.
SEMI_AUTOMATIC mode is the one i’m in.
I’ll try STARTUP().

Is any of this documented?

The docs have a search function so it’s easy to find out if this is documented. :wink:

https://docs.particle.io/reference/firmware/core/#semi-automatic-mode

https://docs.particle.io/reference/firmware/core/#startup-

1 Like

That’s not exactly what I mean. I can see that all of these components are documented but it seems that they are lacking significant detail.

For example, that Particle.process() is required to acquire an IP address even if not connecting to the Cloud.

Also, is there any intention to add some markers to indicate which setting are stored in flash and therefore persistent after reset?

You mean like this?

https://docs.particle.io/reference/firmware/core/#wifi-setcredentials-

or
https://docs.particle.io/reference/firmware/photon/#storing-data-in-backup-ram

or
https://docs.particle.io/reference/firmware/photon/#eeprom

or what info are you missing?


BTW, this is not quite true

The IP address is acquired without Particle.process(), but since you are dealing with asynchronous tasks here, you need some means to allow for the one task (by the WiFi module) to sync its works with your application task and one possible means for that is Particle.process() another one would be a delay(1000) or dropping out of setup()/loop(), …

For persistent data storage:

I am more meaning an overt/obvious tag (e.g. large orange icon saying ‘uses flash’ or ‘persists after powercycle’) to indicate which firmware functionality is dealing with flash memory behind the scenes. Perhaps behind the scenes flash access does not happen as much as I expect so it might not be such a big deal. WiFi.useStaticIP()/WiFi.useDynamicIP() are persistent and although stated in the documentation, a visual cue would be helpful (in the same way that it’s helpful for code to get it’s own formatting box.


Second, for the IP address, why didn’t you give this level of detail initially?