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();
}
}