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).
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.
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().
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.
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.
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(), ...
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?