-->
Page 1 of 1

ESP8266 3TCP connections

PostPosted: Mon Jul 20, 2015 5:49 am
by lampshade
Hey,

i just wanted to connect 3 ESP8266 (connected with temperature sensors) via TCP and send and receive the data from each of them. So every ESP should send and receive the temperature of every module.

Is it possible to run every of them as a TCP client and server and send the data step by step?

i use nodemcu for this. But first of all i wanted to know, if this is the right way to start this, or if there are simpler alternatives.
or ist it possible to receive data as a client? i read some posts, that the esp had to be a server to receive data.

thank you and regards
lampshade

Re: ESP8266 3TCP connections

PostPosted: Mon Jul 20, 2015 9:04 am
by kolban
You might want to consider using UDP as opposed to TCP. UDP allows you to broadcast ... so if you have more than 3 devices or some are down, they can all hear from each other. It would also allow you to have devices transmit to others without having to know the partner IP addresses.

Re: ESP8266 3TCP connections

PostPosted: Tue Jul 21, 2015 6:19 am
by lampshade
seems to be a great idea, but honestly i dont know how i can put this in a Lua code. So maybe someone could help me, or point me to the right direction.
a more precise explanaition of my problem:

i have
ESP1
ESP2
ESP3
every of them is connected to a sensor. i want ESP1 and ESP2 to send data to ESP3 and ESP3 should calculate the average of the data.

Now ESP2 and ESP3 should send theire data to ESP1 and ESP1 should calculate the average

Than ESP1 and ESP3 should send data to ESP2

your multicast idea is great so ESP1 sends data automaticly to ESP2 and ESP3 but i dont understand how i can realize this codewise(Lua) and how i can store the received data to a variable

Re: ESP8266 3TCP connections

PostPosted: Thu Jul 30, 2015 9:34 am
by rlettow
Have you considered using MQTT publish/subscribe? Nodemcu has builtin support for MQTT and is very easy to implement within lua code. The only downside is the requirement of running a MQTT Broker on a computer within the network.