Multiple esp8266 boards talking to each other
Multiple esp8266 boards talking to each other
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.
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.
Re: Multiple esp8266 boards talking to each other
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
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
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Multiple esp8266 boards talking to each other
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.
It seems to me that the application is trying to achieve ad-hoc connectivity in infrastructure mode.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: Multiple esp8266 boards talking to each other
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.
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Multiple esp8266 boards talking to each other
OK, I hadn't appreciated that. So perhaps a mesh network is feasible?
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: Multiple esp8266 boards talking to each other
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.
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.
Re: Multiple esp8266 boards talking to each other
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.
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.
Re: Multiple esp8266 boards talking to each other
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
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
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Multiple esp8266 boards talking to each other
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.markxr wrote:...I think maybe it would be better to use a different radio protocol...
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: Multiple esp8266 boards talking to each other
Thank you all for your priceless hints and links!
markxr
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.
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
pythoncoder
markxr
Scanning is unreliable, for sure -- it only shows 4 APs in esp8266, as far as I remember.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.
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'd prefer lora, but esp8266 is so affordable and range is ok for the price (~300 meters esp to esp https://youtu.be/3bhuAxYp6tw)!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.
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
Sounds really interesting. I'll drop you a couple of lines.We have build ad hoc networks up to 1024 nodes just to show that it works w/o any form of network management.
pythoncoder
But its range is pretty limited, though (~100 meters)?I'd consider the officially supported NRF24L01+ which works well
Last edited by jumasheff on Thu Aug 04, 2016 9:30 am, edited 1 time in total.