Beacon MQTT [Android]

Hello! I would like to introduce my first android application for notifying MQTT server when iBeacon is in range or lost.

Beacon MQTT will be useful for Home Assistant users and interacts with HA through the MQTT Device Tracker module.

Main screen | New beacon | Timing settings | MQTT settings

Installation

Since v0.2 Beacon MQTT is available on Google play.

Get it on Google Play

Before adding the first beacon

The detecting process is time critical. You have to disable any application activity restrictions in your android. Without this action you will have lots of false beacon losses.

Beacons database

Great! You are ready to add your first beacon. Press “ADD NEW BEACON” button and wait some time. You will see all beacons in the range. You can differ beacons by the distance. Tap on beacon which you want to add. In dialog write the name of beacon and click save.

Note for HA users: you should enter the same name as the name of corresponding zone. See MQTT Device Tracker for more details.

Also you can add beacons that are not in range. Click on plus button of action bar and fill fields manually.

Scan in process | New beacon | Context menu | Delete beacon | Edit beacon

To modify or delete the beacon just use long press on it to show context menu.

Discovery timings

I suggest next timings:

  • 1000 … 2000ms for scan
  • 9000 … 15000ms pause between scans
  • 180000 … 300000ms loss timeout

This allows you to have a small discovery time and save battery power. Anyway you can play with timings.

MQTT

You have to configure the parameters of your MQTT server. Toasts will help you with connection state. Beacon MQTT will reconnect to the MQTT server in case of network problems automatically. MQTT messages will be stored in buffer and delivered after reconnect will be done.

I’ve made templating subsystem for MQTT topic and payload. %mac% - is my WiFi mac. %beacon% - is the name of beacon in saved beacon’s database. These keywords will be changed by actual values before sending.

To be compatible with MQTT Device Tracker module use next:

  • %beacon% - for enter payload
  • not_home - for lost payload
  • location/%mac% - for both topics

Events journal

The log screen shows last 1k lines. It helps you with debugging of interaction. You can clear journal by pressing clear button.

Limitations

  • Only iBeacon is supported now
  • Just 4 beacons can be added
  • You shouldn’t have overlapped beacons

Known issues

Please visit my github page to list known issues. Do not hesitate to open new ones. Thanks in advance for your feedback, guys!

For details please visit my project page.

3 Likes

Hi Simon! It looks like you have more complex behavior then I can handle in version 0.1. The first look was concluded in lonely spaced (non-overlapping) beacons. You offer “exit_%beacon%”. It is not a problem for Beacon MQTT. But unfortunately it can’t be processed properly in HA. I can explain in details if you want. For v0.1 you can use such workaround: change exit topic to “locaton/dummy”. So, you will move between your beacons and never leave home.

I see the possible solution in this way. We may add new feature named “beacon group”. Several beacons should be attached to group. While we see one of a beacons from a group we shouldn’t send exit message at all. We still is in range of a gorup. But should pass messages frpm any of beacons from our group. It will allow to track your movement between home’s locations. The solution will work only with overlapped beacons. I hope you understand the mechanics. Let me know if it isn’t clear.

What do you think about this idea? Will it be suitable in your case? I have similar requirement. I wanna meke some kind of notification. I coming back home I want to notify my family that I ready to have a dinner :)))

I’ll think about additional solutions. I’ll return soon.
Simon, thank you very much for any feedback on your side. I’m going to make about page in my app. You will be on the first line for my acknowledgments.

Rigth now I’m preparing v0.2. I’ve already added new beacons discovery functionality. I hope it will be useful. Besides that I solved about ten minor issues. In general it was regarded to old versions of Android. Which version of android do you use?

I am using Android 9, security patch level 2019-03-01 on a Huawei P30 Pro. I can add beacons, manually, and they are recognised and are sending MQTT messages. If I click on any configured beacon all four fields show as empty (but the beacon still works).

Simon, it was the bug.

Hi @Turbo,

I’m using your app together with ESPHome! Wonderful UX and works like a charm. Good work!

Ronald

Changelog for v0.2:

  • Added an activity for scanning and adding new beacons
  • Added the context menu for beacons.
  • Added “edit beacon” dialog
  • Added dependency of margin and padding to screen size
  • Added sending MQTT messages after startup and after add beacons if they will in range.
  • Cleaned up unwanted styles
  • Fix dismissal of dialogs on rotate.
  • Fix crash while preparing new beacon dialog
  • Fix work of button home in settings activity
  • Fix wrong applicationId
  • Fix crash on publush MQTT

Since v0.2 Beacon MQTT is available on Google play.

Get it on Google Play

Hi @rdehuyss can you please explain the application of this app, ESPHome and ibeacon itself in your system? I.e. the main use?

Many thanks

The version 2 of the app seems to be working well. I am getting iBeacon alerts thru to my MQTT Broker. Still an issue at my end of overlapping zones, am trying to reduce output power of beacons to try and reduce range at which I pick them up.
Biggest issue now is how to configure hassio tracker to show which room I am in.

Simon,

MQTT Device Tracker always writes the name of beacon (zone in HA terms) to state of your Huawei P30 Pro. Without any conditions. Even if such a zone is absent in the configuration of HA. It is not an issue. In my opinion it’s clear.

As I told you before in case of overlapped beacons we should have more complex logic in app. May be we should publish only the beacon with a maximum signal level.

I see it to do too based presence detection.

I’m now trying it with one room: the kitchen. There I have an ESP32 which emits a Bluetooth beacon. Using this app, once the beacon comes in range, I know I’m near the kitchen. The idea is that the one with the strongest signal, is the room where I’m at.

1 Like

Hi can you share the code used on the ESP32?

I’m not behind my PC today but it’s really easy using esphome.

Here you can find it: https://esphome.io/components/esp32_ble_beacon.html

The important thing is to create different UUID’s for each room.

I’m now waiting on my PCB’s to be delivered. I’d like to create a multi sensor fire alert with the BLE beacon.
See ESPHome based Smoke Alarm

Ronald,
There is a simpler way. Just 1,5USD.

Your setup is so similar to Simon’s. You also should have overlapped beacons. Do you have any difficulties?

1 Like

Hi,
Great App~ Thank you so much.
Do you have a plan to include a TLS security for MQTT connection like the Owntracks?
I have used a Ibeacon and Owntracks to open my front gate.
When I come up to my beacon, I am in LTE network. So, I need powerful security.
Today, I uninstalled the Owntracks and installed your app. I am so satisfied with it.(it is the one that I have desired for a long time)
Thank you again~

Hi @af950833! I’ll implement TLS option soon. Thanks for a feedback.

Did you manage to use more then one and get a per room presence?

Fantastic app!

I’d love if we could mimic Geofencys webhook feature.
It basically allows you to send a POST or GET request to your server everytime you enter or exit the beacon area.

It also has a home assistant component so we don’t have to expose our mqtt server.

1 Like

So does that mean you have to have your bluetooth on your phone turned on every time ?

My Bluetooth is indeed always on, already for years.

1 Like