painlessMesh and Android


Source code (Open Source, MIT license)

App on Google Play

App on F-DROID (pending)



Some time ago I got interested in painlessMesh for ESP8266 and ESP32.
painlessMesh is a mesh network for ESP8266 and ESP32 and it is quite easy to implement in your ESP projects. The advantage of a mesh network is that your sensor and actuator nodes are not depending on a connection to your home WiFi network. There are several different possibilities to build up a mesh network. For ESP a possibility is the ESP Mesh framework from Espressif itself, but unfortunately that isn’t integrated into the ESP-Arduino framework yet. ESP Mesh is implemented on a low level of the WiFi communication protocols and specific for ESP chips.
painlessMesh works on a higher level using TCP communication. For the connection each node in the mesh network opens a WiFi access point in AP mode and connects the the strongest AP belonging to the mesh network it can find. Each node offers a TCP server for the communication between the nodes. A full description of the communication can be found in the Wiki pages of painlessMesh. painlessMesh is open source and the sources can be found in the Gitlab repository.

Why painlessMesh for Android?

After building up a test network with a mix of ESP8266 and ESP32 devices I soon realized that I cannot check the status of the network without having at least one of the devices connected over USB to my computer. Of course I could setup one of the devices as a gateway between the mesh network and my home WiFi, but that would mean additional setup work and one node dedicated to work as this gateway. And I would need to write an Android program anyway to connect to the gateway.

So I looked for a different solution. In the Gitlab painlessMesh group is an example for a painlessMesh listener, but that is based on a programming language that I never heard of before (Did you know there is a language called “D”?). The code didn’t look too complicated, but as I have already some experience in writing programs for Android I decided to go the “JAVA” way. In addition to know how to do it, it gives in addition the comfort that I can connect to the painlessMesh network from any point in my house.


  • The app is still in testing status, but I can connect to a painlessMesh network, send and receive the routing information, send and receive broadcast and single messages (if they are addressed to the applications nodeId).
  • Same as on an ESP8266 or ESP32 the nodeID is created from the MAC address of the device.
  • Received messages can be filtered by nodeId to focus on a specific node.
  • What is not implemented is the time sync functionality of the painlessMesh network. But even without that the app works quite well.


  • For now the application is tested only on Android Oreo (Android 8 – SDK 26), but should work on any Android version down to Android Lollipop (Android 5 – SDK 21).
  • Due to new security features since Android Marshmallow (Android 6 – SDK 23), on the first start the application is asking the user for permission to get the devices location. This permission is required to start a WiFi scan for access points. (Don’t ask me what the location has to do with a WiFi scan. Same restriction applies if you write a Bluetooth application and want to scan for advertising Bluetooth devices.)
  • On some devices Android will complain that the network you connected to (the mesh network) has no internet connectivity and asks you to change to a different WiFi network. Of course you have to say NO here to keep connected to the mesh network.
  • Even worse, my Huawei tablet has a function that switches automatically to a known WiFi AP if that AP has a better signal or internet connectivity. Usually a very good thing, but not if you want to monitor your painlessMesh network. Luckily on my device I could disable this function.
  • Still from time to time the Android device gets disconnected from the mesh network. Still investigating why this happens.

Principle function

On first start the application will ask for the permission to access the device location. As explained this is a security feature since Android Marshmallow.

After entering the painlessMesh credentials (Mesh name, Mesh password and Mesh port) a connection can be started by pushing the Connect button.
The app will then add the painlessMesh AP to the list of known WiFi APs and try to connect to it.

If successful connected the received messages will be displayed in a scrollable text window.
If not successful the user has to abort the connection TODO ==> Add a timeout function

The received message list can be cleared by pushing the Delete button.

At any time when connected it is possible to send a message into the painlessMesh network. The message can be either a broadcast message (send to all known nodes) or a single message (send to one node).
During the sending process, first a list of known nodes is displayed, with BROADCAST as first option. Once a receiver is selected a dialog box will open where either a predefined control message (Time sync request or Node sync request) can be send or a user message can be entered and send.

Source code

The complete source code is available on Gitlab. Feel free to use it or clone and change it if you  want to build the app by yourself or use parts of it to adapt it to your own painlessMesh setup. The source codes are freely usable under the MIT license

Some code snippets

Get WiFi MAC address of the Android device

Create painlessMesh node ID

Send a Node Sync Request

Send a user message

Build list of connected nodes, requires recursive calls of subfunction, because the routing information is a nested JSON object

I hope this helps someone to get his painlessMesh setup under control.


Leave a Reply

Your email address will not be published. Required fields are marked *

Free Link Directory