TCP Sockets in SoftAP


#1

I want to use the Photon for an ‘offline’ project. Basically I want to use a GPIO to turn on SoftAP, open a socket, listen for some configuration commands, then run the bulk of the time with WiFi off.

I’ve played around with some options for enable/disable softAP (they all seem to work fine), but I can’t get TCPServer to listen on softAP.

With the code below, HTTP, and port 5609 are listening, but 23 never seems to get bound (timing issue since I try to bind before SoftAP is online?).

I can hack on the SoftAP.cpp code, but would prefer to write in the user block code if possible.

Here is some sample source:

#include "application.h"
SYSTEM_THREAD(ENABLED);

int ledPin = D7;
TCPServer server = TCPServer(23);
TCPClient client;

void setup()
{
	System.set(SYSTEM_CONFIG_SOFTAP_PREFIX, "MySSID");
    pinMode(ledPin, OUTPUT);
	server.begin();
}

void loop()
{
  if (client.connected()) {
	  // echo all available bytes back to the client
	  digitalWrite(ledPin, HIGH);

	  while (client.available()) {
		  server.write(client.read());
	  }
  }
  else {
	  digitalWrite(ledPin, LOW);

	  // if no client is yet connected, check for a new connection
	  client = server.available();
  }

}

#2

I just tried a similar thing today with a similar no result. Did you ever figure out how to do this?

My situation was:

  1. Photon in SoftAP mode, e.g. blue light blinking and not joined to a wifi
  2. I had virtually the same “telnet echo” program running.
  3. Connected to the Photon IP address and tried to telnet. Telnet never connected.

When I told photon to join my home Wifi (with my laptop on the same network), the telnet echo app worked just fine.

TCPServer does not seem to respond at all. I’ll theorize all ports except 80 are blocked while in SoftAP mode.