Does the TCPServer actually work on the Electron

I am wondering if the TCPServer as documented in the Electron reference documents is actually implemented/working.
We have the Electron connected to a third party MVNO which actually lets us access the Electrons via a VPN connection. So the normal problem with the Electron being behind a NAT (as discussed in this topic) should not be an issue.

So far I am able to ping the Electron by it’s IP address. Then I setup a port echo server on the Electron and tried to connect to it. But up till now I have no success in connecting to the opened port on the Electron.

Did anybody get the TCPServer working? Or maybe the awesome people from Particle can answer this question.
The idea was to run the FTPino server on the Electron to browse through the SD card contents.

The Electron code:

// -----------------------------------
// Controlling LEDs over the Internet
// -----------------------------------
#include "cellular_hal.h"
#include "HardwareDefines.h"
STARTUP(cellular_credentials_set("EM", "", "", NULL));

TCPServer server = TCPServer(1124);
TCPClient client;

void setup()
{
   Serial.begin(115200);
   InitSystem();
   server.begin();
   Particle.process();
}


void loop()
{
  if (client.connected()) {
  // echo all available bytes back to the client
  while (client.available()) {
    server.write(client.read());
  }
  } else {
    // if no client is yet connected, check for a new connection
    client = server.available();
  }
}


void InitSystem(void){
  Particle.keepAlive(30);
  Serial.begin(115200);
  Particle.function("restart", restartParticle);
}

The server commands used:

    ~ # ping 10.194.216.7
PING 10.194.216.7 (10.194.216.7) 56(84) bytes of data.
64 bytes from 10.194.216.7: icmp_seq=1 ttl=60 time=1562 ms
64 bytes from 10.194.216.7: icmp_seq=2 ttl=60 time=750 ms
64 bytes from 10.194.216.7: icmp_seq=3 ttl=60 time=119 ms
^C
--- 10.194.216.7 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2024ms
rtt min/avg/max/mdev = 119.745/810.730/1562.169/590.417 ms, pipe 2
~ # nc -zvvn 10.194.216.7 1124
(UNKNOWN) [10.194.216.7] 1124 (?) : Connection refused
 sent 0, rcvd 0

It took over 2 seconds to send three 64-byte ICMP echo packets with 1.5 seconds for the first packet, presumable to route all the way. Maybe you are getting some sort of network timeout? Have you tried adding the -w flag to nc?

nc -zvvn -w 30 10.194.216.7 1124

You could also try a commercial port scanning tool instead of netcat.

2 Likes

Insightfull idea. I tested your assumption, but it sadly was not the solution. The connection was not timed out, but actively refused by the Electron (or more probably the modem inside).
Thanks for the suggestion anyway.

~ # nc -zvvn -w 30 10.194.216.7 1124
(UNKNOWN) [10.194.216.7] 1124 (?) : Connection refused
 sent 0, rcvd 0
~ # nc -zvvn -w 30 10.194.216.29 1124
(UNKNOWN) [10.194.216.29] 1124 (?) : Connection timed out
 sent 0, rcvd 0
~ #

FIY, I looked through the source code on Github and sadly the server port portion is not implemented in the Electron firmware.

1 Like