Assigning static IP for photon in listening mode

Hi, my ultimate goal is to have two photon boards to communicate with each other wirelessly, without the use of any other devices other than the two boards (e.g. no external AP).

My approach is to connect photon 1 to photon 2’s SoftAP, and have them communicate via TCP.

I encountered the problem that photon 2, while in listening mode (SoftAP mode), doesn’t have an IP address (WiFi.localIP() outputs 0.0.0.0), and without an IP address, there can’t be TCP communication.

It is now my goal to assign an IP address for photon 2, whilst it being in listening mode. I tried setStaticIP() and useStaticIP(), but they are for assigning static IP when you connect to another network, so they are not what I need.

How do I assign an IP for a photon in listening mode so that it can communicate with another photon via TCP? Or, what might be some work-arounds to achieve my ultimate goal?

Thank you.

WiFi.localIP() does only get set when the device connects to a network, not when the device itself establishes the network (acts as as AP).
SoftAP by default exposes an IP address 192.168.0.1 and that cannot be changed as it is part of the 3rd party WICED firmware.

Also raw TCP is not (fully) supported in SoftAP mode.

Hi @ScruffR, thanks for the response. To get a sense of what I should do next, I would like to ask a few more questions.

SoftAP by default exposes an IP address 192.168.0.1 and that cannot be changed as it is part of the 3rd party WICED firmware.

Does it mean I could configure photon 2 as a TCP client/server using this IP (192.168.0.1)?

Also raw TCP is not (fully) supported in SoftAP mode.

Could you elaborate a little here? I saw in your previous response to the old post Particle photon as an Access Point and web browser as a client! - #4 by jdsarode you said:

You might be able to run the loop() with SYSTEM_THREAD(ENABLED) but no guarantee that it’ll work reliably.

and

Yes, that’s the way how the SoftAP setup page does work to provide WiFi credentials, but you need to consider that you are in Listening Mode at that time, so you have some restrictions - for instance you have no cloud or internet connectivity at that time. And the Photon is also limited how many clients can be serviced concurrently.

I am ok with photon 2 not able to connect to the internet and I only need communication between two photons, but I am a bit worried about having SYSTEM_THREAD(ENABLED) may not work reliably. Could you give me some ideas of the pitfalls that comes with a photon in SoftAP being configured as a TCP server/client?

Thanks.

The WICED SoftAP implementation features its own HTTP server but does not (fully) service any concurrent TCP connections.
When you want to communicate between the two devices you may go via the HTTP route facilitating the stock HTTP implementation.

Unfortunately the "extended" SoftAP feature to allow connections aside from Listening Mode and raw TCP/UDP connections never materialized and is off the planned list.

@ScruffR It seems using the default implementation of the HTTP server is the only way of communicating between two photons when one is connected to the other’s SoftAP :frowning:. What I intend for my two photons to do is essentially that photon 1 will send sensor data to photon 2, which will send back responses based on the sensor data., but from what I read on the API, the HTTP server only allows the hosting of a website with the feature to set up wifi credentials.

I would like to ask for your opinion on the preferred way to implement my goal using Particle Photon boards, do I really need another AP? Could the HTTP server somehow work for my use case? By the way, I don’t want the boards to connect to cloud.

Thank you.

Not quite.
You can modify the hosted website and use these to communicated your custom data.
I've done exactly that in some example implementation quite some time ago.

1 Like

As another option, both Photons can connect to an existing Wi-Fi network and not connect to the cloud. You just need to only bring up Wi-Fi only (WiFi.connect()) instead of the cloud (Particle.connect()) and the devices will breathe green instead of cyan. Then both devices have the full ability to communicate locally using TCP and UDP. This also works across multiple APs on the same LAN.

For this implementation, what’s the code for the client photon to POST data to the HTTP server?

My feeling is that the SoftAP server only supports GET requests, but you still can send data to the server as GET parameters.

Thanks. What’s the code for the client photon to perform the GET request?

I saw an example of a GET request (https://www.digikey.com/en/maker/blogs/2019/how-to-post-data-using-the-particle-photon):

client.println("GET /dataValue.html HTTP/1.0");
client.println("Host: maker-io-iot.atwebpages.com");
client.println();

But I don’t know what should I fill in for the Host. When I am using my browser to access the index.html hosted by the SoftAP HTTP server I only needed to type in the IP address.

You can use the IP address

Or you use HTTPClient to care about the forming of the request for you :wink:

I tried the following code on the client but the server didn’t receive the request, what is wrong?

client.println("GET /index.html?str1=1 HTTP/1.0");
client.println("Host: 192.168.0.1");
client.println();

I tried HTTP/1.1 and 2 too. With the "Host: " I tried http://192.168.0.1 as well.

Actually, these three lines of code works when I changed the request to GET google.com, so it seems it's just having problem getting to the photon HTTP server.

I think the issue deserves a topic on its own, so I created a new topic here: