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