Hello OpenMQTTGateway Community,
I want to use OpenMQTTGateway to connect a BLE device to my Home Assistant installation. My usecase is that when I push a button in Home Assistant, I want to write a specific byte string to a specific characteristic of a specific device.
I installed OpenMQTTGateway on an ESP32 NodeMCU board and connected it to my WiFi and the Mosquitto MQTT Broker running on my Home Assistant. When using MQTT Explorer from my Laptop connected to my Mosquitto installation, I can see that the OpenMQTTGateway publishes a lot of BLE devices into MQTT - especially, it also publishes the device I want to use.
I then proceeded to try and write to a characteristic of my device. I used the examples given in BLE gateway | OpenMQTTGateway v0.9.9beta and adapted them for my device: The topic remains the same, but I substituted the MAC, Service UUID, Characteristic UUID and the data I want to send. I used MQTT Explorer to publish the message.
As you may have guessed by me posting here, it didn’t work. In trying to debug this, I looked at the serial console of OpenMQTTGateway. On the console, I can see messages whenever the BLE Scan finds a new device. I would expect the console to also show that a command was received from MQTT - but nothing.
At this point I did some more experimenting and found interesting things. You actually do have to adjust the topic! The examples state to use the Topic home/OpenMQTTGateway/commands/MQTTtoBT/config
. But what you actually need to do is to substitude the “OpenMQTTGateway” for the actual name of your Gateway device. I flashed the esp32dev-ble
configuration, where the default name is OpenMQTTGateway_ESP32_BLE
. So, publishing to home/OpenMQTTGateway_ESP32_BLE/commands/MQTTtoBT/config
, I can suddenly see the message N: Received json : <my payload>
appear on the serial console. No other messages regarding to my write command are shown. So that bit is sorted at least. I would suggest updating the documentation, though.
For reference, I publish the following (all values substituted for privacy, but I triple-checked what I am actually sending):
home/OpenMQTTGateway_ESP32_BLE/commands/MQTTtoBT/config
{
"ble_write_address":"FF:00:FF:00:FF:00",
"ble_write_service":"9184e8db-850c-4057-b0fc-d49a10738a1b",
"ble_write_char":"9184fd66-850c-4057-b0fc-d49a10738a1b",
"ble_write_value":"DEADBEEF",
"value_type":"HEX",
"ttl":4
}
As a second step, I started to debug my BLE device. It does produce serial output whenever someone wants to talk to it using BLE. For testing purposes, I whipped up a python script to write to the characteristic using the BLE adapter in my windows laptop. This works and the BLE device performs the expected action. On the serial console of the BLE device I can see the connection attempt, the write and the disconnect from the windows laptop.
However, when attempting the BLE write via OpenMQTTGateway, the serial console of my BLE device remains silent.
I initially tried this using v0.9.8. When I started to get down to more analysis, I moved over to v0.9.9beta. I have not run all tests on v0.9.8.
What can I do to make OpenMQTTGateway write to my BLE device?
Regards
Damian