BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

More than one TCP connection

#1

I have been pouring over the various pages and links all day - all very impressive.

I have tried a few things out, have LEDs switching on and off and I have also been able to switch them using the HTTP restful API.

In my project I am hoping to be able to receive commands directly from software I have written running on a PC on my network. I could send out HTTP requests to the Blynk cloud server, and have it call back into my network to pass it onto my device. I also understand I could install a local server and send HTTP commands to that, in order to reduce latency, but I will need to find another PC to do that.

Within my sketch, if I could listen for TCP or UDP connections, I could receive commands, parse them and then call the Blynk stuff as needed, without the heavy payload of HTTP GET operations. Then my other software could connect directly and pass in the data needed.

So now my two questions:

  1. Is there any existing Blynk supported data flow I can use (other than via HTTP or the Blynk app)?
  2. Failing that, can these ESP8266 type devices handle multiple TCP connections (small amounts of traffic)? I understand that the device will already have a connection open to a Blynk server, so can I also listen for, and open, a second connection on another port? If so, I could create a small module that listens and connects, parses commands, and optionally sends data back.

I am think in terms of overall architecture at this stage.

Background: The other software is a model train control system. When simulating sunset, I need to send commands to my ESP8266 to set the room lighting brightness accordingly, and bring up the lighting behind mountain ranges. I like the idea of using Blynk so that I can use the phone app to control the room lighting when I am not running the train control software.

0 Likes

#2

I don’t believe the ESP can share it’s one WiFi connection with multiple sources, short of complicated hoop jumping like disconnect, then using the WiFi for intern use, and then back to Blynk via reconnect.

But if your other software can work with other forms of a link, Serial, hard wired, i2c, BT/BLE, RF, etc. then you could use the applicable module connected to the ESPs GPIO.

But basically, existing Webhook and API are the more tried and true methods, as I understand them, for most cross IoT application communication… So no real reason to reinvent that wheel :smiley:

0 Likes

#3

Yes, Node-Red and MQTT.

MQTT is a messaging service developed by IBM for exactly this situation. It requires a broker (server) and the common approach is to use a Raspberry Pi running the Mosquitto broker along with the Node-Red server software, although there are versions that run on a PC instead.

Node-Red is a graphical programming/wiring tool that has community developed plug-ins that provide integration with 3rd party products, including Blynk. It also has a powerful script I gotta language, which is very similar to C++, that can be used to write functions and nodes to create an extremely powerful system.

I was reluctant to introduce another programming tool into my architecture at first, but Node-Red actually simplifies integration with other products in a way that makes it well worthwhile.

I started this thread about the way that I use Node-Red and MQTT (plus Blynk, Amazon Alexa, Ikea TRÅDFRI etc) in my home automation projects:

The thread has become a bit messy now, and I’m overdue making another post about other elements of my home automation system, but the first three posts from me in the the thread explain what the system can do and give some examples of how I use it for real-life home automation projects.

Pete.

1 Like

#4

Oh, yes… and that way :blush: One of these days I will get around to trying out Node-Red

1 Like

#5

By the way, @lichtsignaal (one of the regulars here) is also a model railway enthusiast.

Pete.

1 Like

#6

Thanks Pete, I will check out Node-Red. I have looked at MQTT and that is also probably more complex than what I am looking for. Even Websockets start off with HTTP stuff which is superfluous IMHO. If MQTT can be opening ports at the same time as staying connected to Blynk, then I suspect that an ESP8266 can in fact have multiple ports open at the same time.

0 Likes

#7

yes I noticed @lichtsignaal was a train guy ! Thanks again. He might like an ESP8266 based RemoteSign

1 Like

#8

MQTT is actually very simple. It only uses one port (1883 by default).
The simplest method of visualising how MQTTworks is to think of it as a series of windows drop folders. Devices can subscribe (monitor a folder) or write to a folder (or both if you wish).
The message written to the folder can be a simple 1/0 for on/off, or complex strings of data representing floating point data or delimited collections of data.

Pete.

0 Likes

#9

well the answer is most clearly a YES, it is possible to have multiple TCP ports operating simultaneously.

The result of this project is documented here:

It talks to three TCP connections at a time:
Blynck
HTTP for OTA update checks
RemoteSign TCP connection which remains open

0 Likes

#10

Yup, rereading this now, I think my exhaustion befuddled brain was mixing up SSID and TCP… I have no other explanation, considering I actually use OTA and other API & Web links within some of my own Blynk sketches :stuck_out_tongue:

1 Like