Particle Photon as Serial UART

I haven’t been able to find a clear path for this question I am seeing so I am just going to ask it and hope not to get flamed…

Is there a way to remotely (WiFi Locally, IP Based, or Dashboard???) connect to the Photon and get the Serial UART like you can with a USB device and a Com port? For instance Putty to a remote IP Connection (the photon)?

If that doesn’t exist, for 19 dollars that would make a completely sick UART device for like a watchdog… If you had a project that ran on an AVR and needed to debug it, but its on lets say MARS, using the Photon as a Serial UART to see the debugging and/or interact with it would be awesome. Add a “Lights Out” setup to it and it would be even more awesome.

Using it as a remote serial port, puts the Photon into a large of very expensive IP based devices for Serial Port debugging. (75 to 500 dollars) At 19 dollars, even with a Shield added on, it kills for the price.

@FlaredElectronics, Is your question “Can I get a SSH like service to connect to my Photon wirelessly?”, or is your question "Can I use my Photon to record the Serial output of other devices and publish it with Spark.publish()?".

I don’t think the first is possible, but I think the second is definitely possible.

@FlaredElectronics, the answer is yes and no. The “yes” part is that I have code that allows two-way serial-over-tcp on the Photon which can be enabled/disabled by a Spark.function. The “no” part is that the TCP traffic is not encrypted. :smile:

Encryption isn’t a worry of mine, I just know SSH seems to be more prevalent than the base RS232 serial telnet.

Would you mind sharing that code? I am not sure where to begin as I am a newbie when it comes to Cloud based uCs. I have an evolving understanding for my project and a few Simon Monk books (including the one for the Photon), but combining Host and child based code is new for me as I am a hardware engineer.

@FlaredElectronics, SSH is encrypted! What I have is telnet (TCP port 23) which is basically wide open and unencrypted.

I’d really like to do that Telnet over Wifi as well.
I can’t see a Library function for it, but would gratefully receive hints or code.

@peekay123 could you share your code?

@mossytrees, this code implement telnet to serial on the Photon. It’s older code that was written before the latest fixes to TCPClient were made to correctly indicate a closed connection. The idea is to no leave the socket open if the telnet client drops the connection. To get around this, I had implemented a timeout to automatically do a stop() to close the connection. I also correctly handled the connected() status returning false anticipating the fix in the future. The code below is culled from a greater piece of code and I haven’t compiled or tested it as of this posting :blush:

#include "application.h"
#include "elapsedMills.h";


// socket parameters
int serverPort = 23;

elapsedMillis connect_timeout = 0;		// TCPClient connection timeout

// start TCP servers
TCPServer tServer = TCPServer(serverPort);
TCPClient tClient;

enum tnetState {DISCONNECTED, CONNECTED};
int telnetState = DISCONNECTED;

void setup() {
	Serial.begin(9600); // open serial communications

        Particle.connect();
	while(!Particle.connected()) Particle.process();  // Wait for cloud connection
	
	IPAddress myIP = WiFi.localIP();
	sprintf(myIpString, "%d.%d.%d.%d", myIP[0], myIP[1], myIP[2], myIP[3]);
	Particle.variable("devIP", myIpString, STRING);  // Var used to get IP for telnet client.

	tServer.begin(); // begin listening for TCP connections
}

void loop()
{
	if (tClient.connected()) {
		telnetState = CONNECTED;
		// echo all available bytes back to the client
		int incomingByte = 0;
		while (tClient.available()) {
			incomingByte = tClient.read();
			activity_timeout = 0;		//char received, reset the timeout counter
			Serial.write(char(incomingByte));
		}
		if (incomingByte != 0) {
			Serial.flush();
		}
		else if (activity_timeout >= 60000UL) {	// No data received so check 1 minute inactivity timeout
			tServer.stop();
			tClient.stop();
			telnetState = DISCONNECTED;
		}
		
		while (Serial.available() > 0) { 	//If data has been received from the serial connection
			incomingByte = Serial.read();
			tClient.write((char)incomingByte); 	// print the char data back to the client
		}
	}
	else {
		// if no client is yet connected, check for a new connection
		if (telnetState == CONNECTED) {
			tClient.stop();
			telnetState = DISCONNECTED;
		}
		tClient = tServer.available();
	}
}
1 Like