I am trying to connect to the Photon using telnet. I have port scanned the Photon and it shows that port 23 on the Photon is open.
// socket parameters
int serverPort = 23;
char inbyte;
int counter = 0;
int simulate_temp = 21;
// start TCP servers
TCPServer server = TCPServer(serverPort);
TCPClient client;
char myIpString[24];
char outmsg[50];
enum tnetState {DISCONNECTED, CONNECTED};
int telnetState = DISCONNECTED;
unsigned long activity_timeout = 0;
void out(const char *s) {server.write( (const uint8_t*)s, strlen(s) );}
int LED = D7; // LED is connected to D7
void setup()
{
//Serial.begin(serialBaud); // open serial communications
server.begin(); // begin listening for TCP connections
IPAddress myIP = WiFi.localIP();
sprintf(myIpString, "%d.%d.%d.%d", myIP[0], myIP[1], myIP[2], myIP[3]);
Spark.variable("devIP", myIpString, STRING);
pinMode(LED, OUTPUT); // sets LED pin as output
}
void loop()
{
if (client.connected())
{
telnetState = CONNECTED;
// echo all available bytes back to the client
inbyte = 0; //set to 0 so can detect when a char is received
while (client.available())
{ //Read incoming TCP data if available and copy to Serial port
inbyte = client.read();
if (inbyte == 'x')
{
digitalWrite(LED, 1); // Flashes the LED
delay(500);
digitalWrite(LED, 0); // Flashes the LED
IPAddress myIP = WiFi.localIP();
sprintf(outmsg, "%d.%d.%d.%d,%d,2,%d,3,4/e", myIP[0], myIP[1], myIP[2], myIP[3],counter,simulate_temp);
counter = counter + 1;
out(outmsg);
}
activity_timeout = millis();
}
if ( inbyte == 0 && (millis() - activity_timeout > 60000UL) )
{
// No data received so check 1 minute inactivity timeout
//Serial.println("client.stop"); //Check for new connection on next loop()
client.stop();
telnetState = DISCONNECTED;
}
}
else
{
// if no client is yet connected, check for a new connection
if (telnetState == CONNECTED)
{
//If client WAS connected before, so stop() to close connection
//Serial.println("client.stop"); //Check for new connection on next loop()
client.stop();
telnetState = DISCONNECTED;
}
client = server.available(); //Update TCP client status - "client" is declared globally
}
}