Hello, I’ve got a problem im not able to solve:
I want to connect my Photon to an Ad-Hoc WiFi network hosted by a raspberry pi 3b.
I collected some code snippets here and there on this forum, but I don’t get this to work.
As @ScruffR said, this call to setCredentials() does not contain information to set them for a network that is not currently in view. You need to pass all four arguments like this section from the doc:
// for hidden and offline networks on the Photon, the security cipher is also needed
// Cipher options are WLAN_CIPHER_AES, WLAN_CIPHER_TKIP and WLAN_CIPHER_AES_TKIP
WiFi.setCredentials(ssid, password, auth, cipher);
WiFi.setCredentials("SSID", "PASSWORD", WPA2, WLAN_CIPHER_AES);
You may also want to rethink the approach to unconditionally clear credentials and reprogramm the whole lot over and over.
All these settings are sticky, so they will stay with your device even after you remove power. Hence I’d store a “flag” in EEPROM once you had set everything up and don’t do it again, until you explicitly need to do it again, which can be initiated by clearing the flag.
Also if things are not working as expected, you can always let your phantasy play and consider what actions could change the behaviour. Assuming that a feature isn’t working as intended should be the last assumption - it’s much more likely that the way how a working feature is applied prevents it from working.
Having said this, one thing to creatively try would be to “power-cycle” the WiFi modem after you set it up.
Maybe my title is a bit misleading I’m not trying to say that a feature is not working correctly because of the way it’s implemented by the “creators”, I’m trying to say it’s not working because I’m not able to implement it correctly. Just to clear that up.
Maybe it can help that it’s an unsecured network.
An I tried to be creative, switched around some code here and there… But I’m not getting it to work and im getting frustrated…
// Connects to an unsecured network.
However, maybe try things step-by-step.
Go back to WiFi.useDynamicIP() and try to connect with your credentials.
Once you have established you can connect that way, then you can try out the static IP route.
I moved this post here, since it’s still the same issue and we don’t want to have orphaned/abandoned threads just because a new thread was started for no reason.
BTW, have you been through the threads that already dealt with similar issues.
You will only get the same answers that were given in those - especially when in these threads the “issue” was actually solved. https://community.particle.io/search?q=static%20ip
One tip I gave in one of these threads was to try WiFi.off()after you stored the settings, wait for 100ms and start with WiFi.on() again.
You may also need to use WiFi.setCredentials() the way you were told further up this thread.
And finally I repeat myself
Yes, you stated that your RPi has no DHCP enabled, but how about back-tracking even further and forget about the RPi for the moment and try to get the rest working with a “proper” WiFi AP which has DHCP, you can still use static IP on these devices to get a hang of how to do it correctly.
Just remove as many variables from your equation as you can.
Since - as already said - I consider it bad practice to unconditionally clear credentials on every startup, I have left that part out and you just need to clear the credentials by holding SETUP 10+ seconds to clear them manually in order to actually perform the setup procedure.
And it’s also only done once, unless you change the magic number, to re-enable the setup function.