OK, I am trying to make my Electron as TCPServer and want to write an App on my laptop as TCPClient.
To do this, as a first step, I have made following code on Electron.
By this I am getting Public IP of Electron which it sends over to serial port.
When I get the Public IP, I try to ping it from my laptop but it gives request timed out.
Also I tried doing telnet using Putty, it is also returning network time out error.
Can someone help me here?
// telnet defaults to port 23
TCPServer server = TCPServer(23);
TCPClient client;
void handler(const char *topic, const char *data) {
Serial.println("received " + String(topic) + ": " + String(data));
}
void setup()
{
// start listening for clients
server.begin();
// Make sure your Serial Terminal app is closed before powering your device
Serial.begin(9600);
// Now open your Serial Terminal, and hit any key to continue!
while(!Serial.available()) Particle.process();
//Serial.println(Cellular.localIP());
for(int i=0;i<5;i++) {
Serial.println("waiting... " + String(5 - i));
delay(1000);
}
Particle.subscribe("particle/", handler);
Particle.publish("particle/device/ip");
}
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();
}
}`
You essentially cannot use TCPServer on an Electron.
The problem is that the public IP address provided by your mobile provider does not dedicate that IP address to your Electron; it’s shared with many people using port mapping (NAT). There is no way to configure an incoming listening port mapping with your mobile provider, so basically it won’t work.
Can you advise on how do I achieve the direct communication between my remote laptop to and fro Electron without using Particle Cloud?
This is because I have to send more than 255 bytes of data/second to my remote server from Electron.
You’ll likely run into a similar problem in the reverse direction, depending on the network your laptop is connected to. Actually, there are three problems: one is that the public IP address of your network may change, which is common for home networks. Another is that network address translation (NAT) is used so the router must be configured to port forward incoming connection to your laptop. And the third is that there may be one or more firewalls preventing any off this from working. These problems can be worked around, but they’re situation dependent and not specific to the Particle. It’s the generic problem of running an Internet accessible server on your own computer. Also, there are some security issues when you do this.
The other solutions include using a server on the Internet, or a data ingestion service, like Amazon lambda, maybe also Amazon kinesis, which is designed for this sort of thing.
Understand the server side requirement and thank you for helping me get insight in this.
I will be able to arrange a server with static IP in my office.
In that case do you think, I will be able to communicate with Electron directly, where Electron is configured as TCPclient? (with TCPserver application running on server at my office)
Hey @MaheshGulavani – is there are a reason you aren’t using the Photon for this project, if it’s indoors and communicating with a server in your office?
I think this might be accomplished much more easily over Wi-Fi.
For communication between servers or other devices (behind NAT) I do use MQTT protocol. With photon modules works well. It should be equal for Electron.
On what operating system you’re testing? Mosquitto (message broker) after the start should be reached on the standard tcp port 1883. There are also sandboxes for testing of MQTT, such iot.eclipse.org … http://iot.eclipse.org/getting-started