I’ve read/found different topics (here in C# and this library) on the subject to find out what POST requests were to be sent to the Photon, but I cannot seem to set its WiFi credentials.
If I understood properly the flow, the way to set my Photon’s WiFi credentials would be:
put it in listening mode;
send a POST request to http://192.168.0.1/configure-ap, with a String following this pattern: “{“idx”:0,“ssid”:String,“pwd”:String,“sec”:int,“ch”:int}”, with “pwd” being the RSA encrypted version of my password;
send a second POST request to http://192.168.0.1/connect-ap with this String: “{“idx”:0}”.
So, I am following these steps and I am trying to send my requests through Postman. For both of my requests I am using a header {Content-Type;multipart/form-data} and a raw body with the strings described above. After each request, I get the response {“r”: 0}, with a status 200. My Photon then goes briefly to green, then back to breathing dark blue… but I’m not able to reach it any longer after that. I have to reset it, if I want to put it in listening mode again. And it’s definitely not connected to the new WiFi credentials that I tried to set.
Am I doing something wrong in these steps? or is it “just” my RSA encryption that’s wrong?
[Also, my version of the firmware is: 0.5.0-rc.1.]
Hey! Would be happy to help. Can you send me a little more info? What version of .net are you using? What HttpClient?
Can you confirm you are also getting a r: 0 response from configure-ap?
Posting to the Photon via SoftAP in windows seems to have a lot of issues. I recommend using a StreamSocket (and it’s what the Official Particle C# library will be using).
I am acutally not using C#. I just looked at different codes to see what was the procedure to configure the WiFi credentials with POST requests. Regarding my HttpClient, I tried Postman and Advanced REST client.
Yes, I also get a {“r”:0} response after my configure-ap request.
StreamSocket? Meaning that I should try with a TCP/IP client instead of an HttpClient?
@mdma I tried flashing the new firmware, but I still get the same behaviour. After failing to connect, my Photon goes back to breathing dark blue, but I can’t reach it anymore. (I have to reset it)
Yes, I’ve had much better luck with using TCP/IP. I have seen that in some cases if the data isn’t perfect, you’ll get r: 0 but I can’t remember what was wrong.
@justinmy: I have now tried sending the commands through TCP, with RealTerm and I still can’t make them work. :’(
My Photon answers to all the basic commands (scan-ap, device-id, public-key, version), but I still can’t configure its WiFi credentials. Two things happened:
the first time that I sent configure-ap, and then connect-ap, it answered {“r”:0} for both of the commands and went on blinking (not breathing) green… and nothing happened: it seemed not connected to anything as it still existed as an AP. So, I reset it, in case it needed that to connect properly, but it went on connecting to its old WiFi credentials. So, I tried again…
all the other times after that: since then I’ve never managed to get another response from my Photon with the commands configure-ap and connect-ap, not even {“r”: 0} with nothing happening. After sending those commands, I can’t reach it and it doesn’t answer the other basic commands (scan-ap, device-id, public-key, version), though it still shows as an AP.
Another weird thing: when I close my TCP connection with RealTerm, my Photon also crashes: it stops blinking dark blue, and I can’t reach it anymore (it doesn’t reset itself).
EDIT: after reading again the procedure, I noticed that I wasn’t doing it properly except for the first time apparently: I am now able to reproduce the first case, with my Photon blinking green after sending the connect-ap command and getting the response {“r”:0} after each command. Though I directly get a response after sending the number of bytes for the connect-ap command (I am not able to send data with this command). EDIT2: it seems that the Photon goes into blinking green after sending two LFs in a row when using the command connect-ap. Doing so when sending the command configure-ap doesn’t make it behave the same way, as I was able to send JSON data with this command.
Okay, so first configure-ap only sends data to the device, so there won’t be any interaction on the device. connect-ap will load the data from the same index and try to apply it.
I’m sending the data as separate blocks, so it probably explains why I can’t set its credentials, then.^^
Unfortunately I won’t be able to test that out until Tuesday, but I sure will get back to you when I do!
In any case, thanks a lot for your time and your help!
Thank you again!
It does work when I send each command as one block.
Just wondering though, is the router required to have access to the cloud? Because when I tried to connect my Photon to a router that didn’t have access to the cloud, it didn’t work; but trying the same commands with a router with an access to cloud did work…