Send data from Electron to my server directly


I am using Particle Electron and started learning on it recently.

I am looking for efficient way to send data from Electron directly to my server.

I tried to search through forum but could not understand the best way to do it.

Can someone advice me on this?


You can look at TCPServer, TCPClient or UDP objects, which can all be found in the docs

Let us know if you have any issues with the development, @MaheshGulavani

Thanks for your response.

@ScruffR, I did refer the docs, but was looking for some tutorial which guides on the steps required to achieve this.


Hi Will,

I didn’t get your question. Do you mean, Particle can support development services?



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

  // Make sure your Serial Terminal app is closed before powering your device
  // Now open your Serial Terminal, and hit any key to continue!
  while(!Serial.available()) Particle.process();
  for(int i=0;i<5;i++) {
        Serial.println("waiting... " + String(5 - i));

    Particle.subscribe("particle/", handler);

void loop()
  if (client.connected()) {
    // echo all available bytes back to the client
    while (client.available()) {
  } 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.

Thanks @rickkas7 for your reply.

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.


Hello @rickkas7.

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)


Yes, if you have a static IP address in your office and the firewall is configured to allow access, that should work just fine.


Thanks @rickkas7 for your kind help and valuable time on this.

I will proceed with these inputs.


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.

Hello @will,

Yes, we want to use Electron as the target system will be at a remote location away from office.


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.

Hello @antdem,

Thanks for your inputs.
This is new to me, I am searching for the information on this on internet.
Got this link->

Did an initial try and got stuck at setting up “Mosquitto” on my laptop :disappointed:
…working on solving it.

If you have any reference to any tutorial, kindly share.


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

Hi @antdem,

I am testing on Win7. I will go through the link you provided.


In windows there is some dependence on download (some dll) … such as pthreads and openssl …

Thanks @antdem,

I was able to test “Mosquitto” on my laptop :relaxed: with below commands->

mosquitto_sub -d -t hello/world


mosquitto_pub -d -t hello/world -m "Hello, MQTT. This is my first message."