A mesh network for use with ESP8266 and MQTT



  • I'm sorry if this doesn't belong here as it is not strictly mysensors related...

    While I have a bunch of RFM69 mysensors around my house, I decided t buy some Sonoff POW relays (with the intention to run Espurna on them) as their price is very good and they had the capabilities I needed. I was disappointed by the range compared to my RFM69 sensors though, and didn't have strong enough wireless to get them everywhere I needed them.

    I decided to try to build a mesh network which could extend the range by allowing nodes to forward data through each other. I found a few toy projects, but nothing that seems like it would meet my needs, so I wrote my own. What resulted was my ESP8266MeshNetwork.

    It is built around MQTT messaging. Nodes use a simple TCP protocol between themselves, but can also act as a gateway to publish/subscribe to messages from the MQTT broker on the wireless network. subscribed messages are forwarded to all nodes, whereas published messages are forward upstream until they reach the MQTT broker.

    Each node creates a hidden access point (this is just to reduce the number of networks that appear visible, not for security). Each node has a list of known nodes (identified by MAC) and will connect to the best available node or the primary wireless network if possible. The MQTT broker maintains the list of all nodes on the network via persistent messages, so it is necessary for a node to connect directly to the wireless network at least once to know about existing nodes. After that, a node will automatically connect to the best node in the mesh, and will keep its list of nodes up to date by receiving MQTT notifications.

    The nodes can each run their own firmware, as long as they all use the ESP8266MeshNetwork library for communication). OTA updates are supported via MQTT, and can be targeted to a specific node, or to all nodes running a given firmware.

    I've only had it in operation for a couple of weeks, but it seems to be working well for me so far.

    I'd like to use the mysensors library for the Sonoff POW, but it really wants to fully manage the connection, which won't work well for me. Perhaps I could implement the mesh as a Transport, but I don't think there is much likelyhood of my having such a patch accepted.

    Anyhow, here is a link to the github repo:
    https://github.com/PhracturedBlue/ESP8266MQTTMesh


  • Mod

    Actually mysensors it is not meant to be run over ip connection, so I don't think you would get any benefit given that is already working with your system. I personally would have not taken your route to make a mesh network, but I would have used a WiFi repeater (or an access point over powerline like I currently have)


  • Admin

    Interesting concept @PhracturedBlue!



  • I agree that mysensors isn't designed to be run over IP, but it has a well formed API for a variety of sensors. It would be ideal (for me) if the messaging API was independent of the backbone. I did actually start with Wifi repeaters, but they were expensive and I needed several. Then I thought I could make one using ESP8266 modules cheaply, then I figured I might as well go with something that was tailored to my needs...and then I got where I am now. I hadn't thought about X10 or a powerline AP...Not sure they would have worked for me due to my setup, but maybe I should have considered it. Oh well...in any case, I now have a useful mesh library I can play around with I guess.


  • Mod

    without knowing your project/setup it is difficult to give an appropriate answer.



  • @gohan
    I'm not sure I was asking a question. Just stating my solution in case anyone else ever encounters something similar since my searching didn't uncover anything.

    Unless you are specifically talking about trying to use mysensors solely as a messaging API. I don't know that there is much point in discussing it since mysensors is designed as a complete system (which I really appreciate since I'm very satisfied using it with my RFM69 sensors). I guess I could emulate the mysensors gateway protocol via my MQTT setup (or as I mentioned try to write a Transport that could interface to my mesh library), but in the end, I'm feeding Home-Assistant, and it is configurable enough not to matter.


Log in to reply
 

Looks like your connection to MySensors Forum was lost, please wait while we try to reconnect.