TX/RX TCP WiFi Link, to TCPclient Flight Computer


I’m very new to this, but wonder if someone wouldn’t mind checking the following code while I wait (impatiently!) for my Photon to arrive.

Declaration: This code originated from hackbp’s Instructables post here: http://www.instructables.com/id/Sparkio-Remote-Serial-port/

My project mission is to broadcast flight parameters (GPS, Barometric, Airspeed) to a flight computer TCPclient. The flight computer is a hacked Kobo e-Reader (fantastic screen for sunlight viewing) with LK8000 software ( http://lk8000.it/ ) running on it. LK8000 normally uses the Kobo’s serial port for bringing the flight data in via wires. I however want my sensors to be remote from the Kobo and I achieved this already using wireless radio serial link modules. This however requires a module to be hacked into the Kobo. As the Kobo has wifi and LK8000 includes a TCPclient port, it makes a lot of sense to make the sensor comms wireless via wifi. Then no h/w mods need to be made to the Kobo.

As everything is literally in the air, the Cloud is not available when the flight computer system is in use. A number of the Lk8000 pilots have done exactly what I describe, using an ESP8266 module running ESP-LINK. Problem is the ESP8266 is power hungry (~200mA), whereas I’m hoping the Photon’s spec of 80mA (average) is accurate (because we are streaming sensor data continuously).

Below is the firmware, which compiles fine, but I don’t understand many of hackbp’s coding, so am flying blind to a large extent. The comments are mine - trying to understand the coding functionality.

Any thoughts, comments, suggestions would be greatly appreciated!

#define LISTEN_PORT 6000

TCPServer server = TCPServer(LISTEN_PORT);
// Creates a server that listens for incoming connections on the specified port (LISTEN_PORT in this case).

TCPClient client;
// Creates a client which can connect to a specified IP address and port.

void setup() {
	server.begin(); // Tells the server to begin listening for incoming connections (clients).
	RGB.control(true); // Tell the Photon RGB LED to turn on...
	RGB.color(255, 0, 0); // Colour Red > I'm waiting for an incoming connection.

void loop() {
	static Stream *usart = NULL;
	if (client.connected()) {
		if (usart == NULL) {
			if (!client.available()) { // Will only carry out branch if the client is available.
				RGB.color(255, 127, 0); // Colour Orange > I have an incoming connection.
			Serial1.begin(9600); // open serial over TX and RX pins (9600 Baudrate, 8 data bits, no parity, 1 stop bit (default))
			RGB.color(255, 255, 0); // Colour Yellow > UART is useable.
		forward_bytes(&client, usart);
		forward_bytes(usart, &client);
	} else {
		if (usart != NULL) {
			usart = NULL;
			RGB.color(255, 0, 0); // Colour Red > I'm back to waiting for an incoming connection.
		client = server.available(); // The variable "client" will now have the number of bytes available for reading (that is, the amount of data that has been written to the client by the server it is connected to)

void forward_bytes(Stream *from, Stream *to) {
	 while (from->available()) to->write(from->read());

void byte2hex(const byte src, char *dst) {
	const static char hexchars[17] = "0123456789ABCDEF";

    dst[0] = hexchars[src >> 4];
	dst[1] = hexchars[src & 0x0F];

Hmm, what’s the trick to better paste code into a post?

Sorry should have searched harder!

Unless your Kobo device acts as a Wi-Fi access point, or you have an AP in your plane, you can’t do this yet with a Photon. The reason is that while the Photon doesn’t require access to the Internet for local IP communication, it does currently require an access point. There are plans to implement Wi-Fi direct, which will allow exactly what I think you want to do, connecting two Wi-Fi devices directly together, but it’s not available yet.

That’s not what I wanted to hear!
Thanks @rickkas7 :cry:

Team, any guesstimates when wifi direct will be available?

1 Like