Not able to connect to Photon over Telnet

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];

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 =;
            if (inbyte == 'x')
                digitalWrite(LED, 1);          // Flashes the LED
                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;
            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()
            telnetState = DISCONNECTED;

        // 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()
            telnetState = DISCONNECTED;
        client = server.available();        //Update TCP client status - "client" is declared globally

What are you seeing? Note that telnet is not a bare byte stream - you’re likely to see some extraneous traffic where things like the window size (ie 80x24) is communicated to the server on connection open.

If you want a raw stream, try using netcat (nc).


I tried to connect to it with netcat but it still timed out.

I still can’t get it to work.

What exactly is not working? I ran your code on a Photon and when I telnet to the IP address and hit x then Return I get back the data that I would expect from looking at the code.

Connected to
Escape character is '^]'.

Mine just says trying and they says it timed out. I know I have the right ip address.

telnet: connect to address Operation timed out
telnet: Unable to connect to remote host

What am I doing wrong? :confused: