Multiple esp8266 boards talking to each other

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
jumasheff
Posts: 14
Joined: Tue Mar 01, 2016 6:00 pm

Multiple esp8266 boards talking to each other

Post by jumasheff » Fri Jul 29, 2016 8:24 pm

Hi,

There is problem I want to solve: there are multiple esp8266 nodes in constant movement (a group of animals with esp boards), one of them is "Alpha". That is, the Alpha node gathers info on other nodes (info on their visibility is enough).

Question: what is the best way to inform a main (alpha) node that all nodes can see each other? My current (theoretical) solution looks like this:
0) All the nodes know how to connect to each other (know AP name, password).
1) Every node scans wireless network and saves results to a file (scan_results.txt)
2) Every node which sees Alpha node sets a flag (say, creates an empty file named 'see_alpha.txt' in its file system).
3) All nodes connect to each other and write (append) info from their own scan_results.txt to scan_results.txt of host nodes (don't know if it's possible at all)
4) The ones seeing Alpha send contents of their scan_results.txt to Alpha.
5) Alpha removes duplicated records and send info to remote server.

Alternatively, we can run http server on each node: when wifi connection is established, the connectee can send info via http to the connected node etc.

yolk
Posts: 5
Joined: Wed Jul 20, 2016 6:47 am

Re: Multiple esp8266 boards talking to each other

Post by yolk » Sat Jul 30, 2016 5:33 am

Hi!

I guess that's a classical problem in distributed systems. There's one more technical aspect which is how the nodes discover each other and communicate when they're within range. Probably it makes sense that each node runs an AP which can be discovered with a network scan. The other problem is how and when nodes exchange what data. One classical and reasonable approach is to use logical clocks or version numbers for the data collected per node. When nodes communicate and one has more recent data (ie, higher version), it brings the other one up to date. That approach avoids removing duplicates afterwards altogether.
See https://en.wikipedia.org/wiki/Vector_clock and https://en.wikipedia.org/wiki/Lamport_timestamps.

Hope this helps.


Thanks,

yolk

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Multiple esp8266 boards talking to each other

Post by pythoncoder » Sat Jul 30, 2016 10:01 am

I'm no network guru so don't hesitate to tell me if I'm talking nonsense ;) But my understanding of the ESP8266 is that it supports infrastructure mode only, and then either in station mode or access point mode; not concurrently. If scanning is to work, doesn't this imply that all nodes are AP's? In which case can AP nodes intercommunicate?

It seems to me that the application is trying to achieve ad-hoc connectivity in infrastructure mode.
Peter Hinch
Index to my micropython libraries.

User avatar
deshipu
Posts: 1388
Joined: Thu May 28, 2015 5:54 pm

Re: Multiple esp8266 boards talking to each other

Post by deshipu » Sat Jul 30, 2016 11:52 am

ESP8266 supports Station and Access Point modes concurrently -- that is, it can act as AP and at the same time be connected to an existing network. It can also do scanning while acting as AP and being connected to a network.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Multiple esp8266 boards talking to each other

Post by pythoncoder » Sat Jul 30, 2016 4:14 pm

OK, I hadn't appreciated that. So perhaps a mesh network is feasible?
Peter Hinch
Index to my micropython libraries.

jms
Posts: 108
Joined: Thu May 05, 2016 8:29 pm
Contact:

Re: Multiple esp8266 boards talking to each other

Post by jms » Sat Jul 30, 2016 6:39 pm

Mesh would need Ad-Hoc mode which I don't believe is supported.

The other thing about Ad-Hode mode is the vastly increased power consumption to keep the radio on which might be about 300mA for the ESP8266.

markxr
Posts: 62
Joined: Wed Jun 01, 2016 3:41 pm

Re: Multiple esp8266 boards talking to each other

Post by markxr » Sat Jul 30, 2016 9:10 pm

The capabilities in Micropython on the esp are not very good for what you want. Micropython does not give access to the mesh functionality of the esp library. The device doesn't support adhoc (I think).

It's possible that you could implement it, by having "alpha" just scan continuously, and all the others act as accesspoints. As long as you don't want much information from them (or you can encode it into the AP name), then that might work.

However, scanning is notoriously unreliable, and I've had a lot of problems with unreliability of scan. I don't think this is the fault of Micropython, I think it's the esp firmware / libraries. In particular, there's no way to stream a scan, it needs the whole results in ram, so if there are too many access points then you either get a truncated list, a MemoryError, or a crash.

Micropython does provide udp protocol however, so you could just have only "alpha" run an accesspoint, and any time they're in range, the others can connect and send status packets to a well-known address.

There is a limit of the number of stations on ESP however, so if many devices are nearby, they can't all connect.

I think maybe it would be better to use a different radio protocol (zigbee or similar? lora?) and use a device which can speak that protocol. Some of those are super-low-power, especiially if you don't need much functionality.

User avatar
roland_vs
Posts: 89
Joined: Tue Dec 08, 2015 8:28 pm
Location: Netherlands
Contact:

Re: Multiple esp8266 boards talking to each other

Post by roland_vs » Sun Jul 31, 2016 7:12 am

Depending on the number of nodes and required data throughput I would yield to something like MyriaNed.

https://en.m.wikipedia.org/wiki/MyriaNed

Http://www.devlab.nl

We have build ad hoc networks up to 1024 nodes just to show that it works w/o any form of network management.

Let me know...


Verzonden vanaf mijn iPhone met Tapatalk

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Multiple esp8266 boards talking to each other

Post by pythoncoder » Sun Jul 31, 2016 7:22 am

markxr wrote:...I think maybe it would be better to use a different radio protocol...
I'd consider the officially supported NRF24L01+ which works well. Official driver https://github.com/micropython/micropyt ... s/nrf24l01. A couple of libraries providing simple point to point linkshttps://github.com/peterhinch/micropython-radio.
Peter Hinch
Index to my micropython libraries.

jumasheff
Posts: 14
Joined: Tue Mar 01, 2016 6:00 pm

Re: Multiple esp8266 boards talking to each other

Post by jumasheff » Thu Aug 04, 2016 7:14 am

Thank you all for your priceless hints and links!

markxr
However, scanning is notoriously unreliable, and I've had a lot of problems with unreliability of scan. I don't think this is the fault of Micropython, I think it's the esp firmware / libraries. In particular, there's no way to stream a scan, it needs the whole results in ram, so if there are too many access points then you either get a truncated list, a MemoryError, or a crash.
Scanning is unreliable, for sure -- it only shows 4 APs in esp8266, as far as I remember.
How about attempting to connect to AP's directly? Say, I have a list of 10 APs, I try to connect to each AP from Alpha (loop with try/catch?). Suppose I failed to connect to 5 nodes out of 10, so I memorize failed APs and pass their names to all nodes I could connect (this is not optimal, as I need to connect to all visible APs once again). Then all nodes memorize their senders, set a flag that they are contracted already (to avoid multiple contracts), try to connect to given APs and pass them a list of wanted APs. And the process goes recursively. Sender info will help to pass data back all the way to initial nodes, contracted by Alpha. Alpha should poll these nodes to get updates (expensive option, needs revision).
I'll try to work this out. Hopefully, I'll update on my progress here.
I think maybe it would be better to use a different radio protocol (zigbee or similar? lora?) and use a device which can speak that protocol.
I'd prefer lora, but esp8266 is so affordable and range is ok for the price (~300 meters esp to esp https://youtu.be/3bhuAxYp6tw)!
My initial plan was to use LoPy (with GPS) as Alpha and esp8266 as nodes. I don't think my target audience has budget for LoPy+GPS per one animal.

roland_vs
We have build ad hoc networks up to 1024 nodes just to show that it works w/o any form of network management.
Sounds really interesting. I'll drop you a couple of lines.

pythoncoder
I'd consider the officially supported NRF24L01+ which works well
But its range is pretty limited, though (~100 meters)?
Last edited by jumasheff on Thu Aug 04, 2016 9:30 am, edited 1 time in total.

Post Reply