Github Boards Devices Community Docs Blog

ESP32 with OMG (0.9.6) as Mi Flora (3.3.1) gateway

Hi there,

first of all, thank you for the great project. I am using current OMG 0.9.6 on a Wemos Lolin32 ESP32-Board. I build it myself but also used the prebuild binary esp32-lolin32lite-ble-firmware. In my setup there are 4 Mi Flora sensors with current firmware 3.3.1.

All sensor where found by OMG, but not all attributes are push to the broker. I would expect something like

{"model": "HHCCJCY01HHCC","id": "<MAC>","tempc":<...>,"tempf":<...>,"moi":<...>,"fer":<...>,"hum":<...>,"batt":<...>}

but get only

{"model": "HHCCJCY01HHCC","id": "<MAC>","batt": 46}

I thought, there are probably multiple messages with different attributes, but there aren’t. Any idea what could be wrong?

Thanks a lot
Björn

Hi,

The battery is published just after the other data, did you checked the history of messages with a tool like MQTT Explorer?

A msg looks like this:
{“id”:“C4:7C:XXXXXXX63”,“rssi”:-74,“model”:“HHCCJCY01HHCC”,“moi”:1}

Morning,

yes, I checked the history with MQTT-Explorer. After starting the device there is one message with a random attribute per device. After that there are only battery messages.

[07:00:02]N: Scan begin
[07:00:02]N: Device detected: 20:00:FE:44:1C:F2
[07:00:02]N: Subject: /BTtoMQTT/2000FE441CF2
[07:00:02]N: Received json : {"id":"20:00:FE:44:1C:F2","rssi":-52}
[07:00:03]N: Device detected: 7D:32:8D:C4:03:D3
[07:00:03]N: Subject: /BTtoMQTT/7D328DC403D3
[07:00:03]N: Received json : {"id":"7D:32:8D:C4:03:D3","rssi":-75,"servicedata":"0ac2106ffbdc0733866a4c2dc0e4a21963e0783c"}
[07:00:03]N: Device detected: DF:5A:89:90:74:52
[07:00:03]N: Subject: /BTtoMQTT/DF5A89907452
[07:00:03]N: Received json : {"id":"DF:5A:89:90:74:52","name":"Mi Smart Band 5","manufacturerdata":"570102ffffffffffffffffffffffffffffffff02df5a89907452","rssi":-75,"model":"MIBAND","steps":61}
[07:00:04]N: Device detected: C4:7C:8D:6B:05:DE
[07:00:04]N: Filtered connectable device
[07:00:04]N: Device detected: C4:7C:8D:6A:EF:3C
[07:00:04]N: Filtered connectable device
[07:00:05]N: Device detected: 20:00:FE:44:1C:F2
[07:00:05]N: Subject: /BTtoMQTT/2000FE441CF2
[07:00:05]N: Received json : {"id":"20:00:FE:44:1C:F2","rssi":-53}
[07:00:05]N: Device detected: C4:7C:8D:6B:05:5F
[07:00:05]N: Filtered connectable device
[07:00:06]N: Device detected: 7D:32:8D:C4:03:D3
[07:00:06]N: Subject: /BTtoMQTT/7D328DC403D3
[07:00:06]N: Received json : {"id":"7D:32:8D:C4:03:D3","rssi":-77,"servicedata":"0ac2106ffbdc0733866a4c2dc0e4a21963e0783c"}
[07:00:07]N: Device detected: C4:7C:8D:6B:05:91
[07:00:07]N: Filtered connectable device
[07:00:10]N: Device detected: C4:7C:8D:6B:05:DE
[07:00:10]N: Filtered connectable device
[07:00:12]N: Found 7 devices, scan number 9 end
[07:01:08]N: Scan begin
[07:01:08]N: Device detected: 20:00:FE:44:1C:F2
[07:01:08]N: Subject: /BTtoMQTT/2000FE441CF2
[07:01:08]N: Received json : {"id":"20:00:FE:44:1C:F2","rssi":-52}
[07:01:08]N: Subject: /SYStoMQTT
[07:01:08]N: Received json : {"uptime":606,"version":"version_tag","freemem":110812,"freestack":3492,"rssi":-73,"SSID":"wifinetwork","ip":"192.168.XXX.XXX","mac":"8C:AA:B5:8C:XX:XX","lowpowermode":0,"btqblck":0,"btqsum":40,"btqsnd":40,"btqavg":1,"interval":55555,"scanbcnct":10,"scnct":9,"modules":["BT"]}
[07:01:09]N: Device detected: C4:7C:8D:6B:05:91
[07:01:09]N: Filtered connectable device
[07:01:09]N: Device detected: 7D:32:8D:C4:03:D3
[07:01:09]N: Subject: /BTtoMQTT/7D328DC403D3
[07:01:09]N: Received json : {"id":"7D:32:8D:C4:03:D3","rssi":-75,"servicedata":"0ac2106ffbdc0733866a4c2dc0e4a21963e0783c"}
[07:01:10]N: Device detected: C4:7C:8D:6B:05:DE
[07:01:10]N: Filtered connectable device
[07:01:10]N: Device detected: C4:7C:8D:6B:05:5F
[07:01:10]N: Filtered connectable device
[07:01:15]N: Device detected: DF:5A:89:90:74:52
[07:01:15]N: Subject: /BTtoMQTT/DF5A89907452
[07:01:15]N: Received json : {"id":"DF:5A:89:90:74:52","name":"Mi Smart Band 5","manufacturerdata":"570102ffffffffffffffffffffffffffffffff02df5a89907452","rssi":-69,"model":"MIBAND","steps":61}
[07:01:17]N: Device detected: C4:7C:8D:6A:EF:3C
[07:01:17]N: Filtered connectable device
[07:01:18]N: Found 7 devices, scan number 10 end
[07:01:18]N: BLE Connect begin
[07:01:20]N: Subject: /BTtoMQTT/C47C8D6B0591
[07:01:20]N: Received json : {"model":"HHCCJCY01HHCC","id":"C4:7C:8D:6B:05:91","batt":47}
[07:01:22]N: Subject: /BTtoMQTT/C47C8D6B055F
[07:01:22]N: Received json : {"model":"HHCCJCY01HHCC","id":"C4:7C:8D:6B:05:5F","batt":34}
[07:01:26]N: Subject: /BTtoMQTT/C47C8D6AEF3C
[07:01:26]N: Received json : {"model":"HHCCJCY01HHCC","id":"C4:7C:8D:6A:EF:3C","batt":54}
[07:01:29]N: Subject: /BTtoMQTT/C47C8D6B05DE
[07:01:29]N: Received json : {"model":"HHCCJCY01HHCC","id":"C4:7C:8D:6B:05:DE","batt":100}
[07:01:29]N: BLE Connect end
[07:16:25]ets Jun  8 2016 00:22:57
[07:16:25]
[07:16:25]rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
[07:16:25]configsip: 0, SPIWP:0xee
[07:16:25]clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
[07:16:25]mode:DIO, clock div:2
[07:16:25]load:0x3fff0018,len:4
[07:16:25]load:0x3fff001c,len:1044
[07:16:25]load:0x40078000,len:10124
[07:16:25]load:0x40080400,len:5828
[07:16:25]entry 0x400806a8
[07:16:26]N: 
[07:16:26]************* WELCOME TO OpenMQTTGateway **************
[07:16:26]N: OpenMQTTGateway Version: version_tag
[07:16:28]N: WiFi ok with manual config credentials
[07:16:30]N: BLE scans interval: 55555
[07:16:30]N: BLE scans number before connect: 10
[07:16:30]N: Publishing only BLE sensors: false
[07:16:30]N: minrssi: 100
[07:16:30]N: Low Power Mode: 0
[07:16:30]N: OpenMQTTGateway modules: ["BT"]
[07:16:30]N: ************** Setup OpenMQTTGateway end **************
[07:16:30]W: MQTT connection...
[07:16:31]N: Connected to broker
[07:16:31]N: Received json : ["BT"]
[07:16:31]N: Received json : ["BT"]
[07:16:31]N: Received json : ["BT"]
[07:16:32]N: Received json : ["BT"]
[07:16:32]N: Received json : ["BT"]
[07:16:32]N: Received json : ["BT"]
[07:16:32]N: Received json : ["BT"]
[07:16:32]N: Received json : ["BT"]
[07:16:32]N: Received json : ["BT"]
[07:16:32]N: Received json : ["BT"]
[07:16:32]N: Received json : ["BT"]
[07:16:32]N: Received json : ["BT"]
[07:16:32]N: Received json : ["BT"]
[07:16:32]N: Received json : ["BT"]
[07:16:32]N: Received json : ["BT"]
[07:16:32]N: Received json : ["BT"]
[07:16:32]N: Subject: /SYStoMQTT
[07:16:32]N: Received json : {"uptime":5,"version":"version_tag","freemem":105744,"freestack":3500,"rssi":-76,"SSID":"wifinetwork","ip":"192.168.XXX.XXX","mac":"8C:AA:B5:8C:XX:XX","lowpowermode":0,"btqblck":0,"btqsum":0,"btqsnd":0,"btqavg":0,"interval":55555,"scanbcnct":10,"scnct":0,"modules":["BT"]}
[07:16:32]N: Scan begin
[07:16:32]N: Device detected: 71:80:B7:76:B7:17
[07:16:32]N: Subject: /BTtoMQTT/7180B776B717
[07:16:32]N: Received json : {"id":"71:80:B7:76:B7:17","rssi":-82,"servicedata":"de9a81143cd7079a09651ca36baa0ec585e0d2be"}
[07:16:32]N: Device detected: 0C:F0:1F:1C:8B:E6
[07:16:32]N: Subject: /BTtoMQTT/0CF01F1C8BE6
[07:16:32]N: Received json : {"id":"0C:F0:1F:1C:8B:E6","rssi":-38}
[07:16:32]N: Device detected: C4:7C:8D:6B:05:5F
[07:16:32]E: Semaphore NOT taken
[07:16:32]N: Subject: /BTtoMQTT/C47C8D6B055F
[07:16:32]N: Received json : {"id":"C4:7C:8D:6B:05:5F","name":"Flower care","rssi":-86,"model":"HHCCJCY01HHCC","tempc":23.9,"tempf":75.02}
[07:16:33]N: Device detected: C4:7C:8D:6B:05:DE
[07:16:33]E: Semaphore NOT taken
[07:16:33]N: Subject: /BTtoMQTT/C47C8D6B05DE
[07:16:33]N: Received json : {"id":"C4:7C:8D:6B:05:DE","name":"Flower care","rssi":-73,"model":"HHCCJCY01HHCC","fer":176}
[07:16:34]N: Device detected: C4:7C:8D:6A:EF:3C
[07:16:34]E: Semaphore NOT taken
[07:16:34]N: Subject: /BTtoMQTT/C47C8D6AEF3C
[07:16:34]N: Received json : {"id":"C4:7C:8D:6A:EF:3C","name":"Flower care","rssi":-80,"model":"HHCCJCY01HHCC","moi":7}
[07:16:36]N: Device detected: C4:7C:8D:6B:05:91
[07:16:36]E: Semaphore NOT taken
[07:16:36]N: Subject: /BTtoMQTT/C47C8D6B0591
[07:16:36]N: Received json : {"id":"C4:7C:8D:6B:05:91","name":"Flower care","rssi":-74,"model":"HHCCJCY01HHCC","moi":19}
[07:16:39]N: Device detected: DF:5A:89:90:74:52
[07:16:39]E: Semaphore NOT taken
[07:16:39]N: Subject: /BTtoMQTT/DF5A89907452
[07:16:39]N: Received json : {"id":"DF:5A:89:90:74:52","name":"Mi Smart Band 5","manufacturerdata":"570102ffffffffffffffffffffffffffffffff02df5a89907452","rssi":-45,"model":"MIBAND","steps":61}
[07:16:42]N: Found 7 devices, scan number 1 end
[07:16:42]N: BLE Connect begin
[07:16:45]N: Subject: /BTtoMQTT/C47C8D6B055F
[07:16:45]N: Received json : {"model":"HHCCJCY01HHCC","id":"C4:7C:8D:6B:05:5F","batt":34}
[07:16:48]N: Subject: /BTtoMQTT/C47C8D6B05DE
[07:16:48]N: Received json : {"model":"HHCCJCY01HHCC","id":"C4:7C:8D:6B:05:DE","batt":100}
[07:16:50]N: Subject: /BTtoMQTT/C47C8D6AEF3C
[07:16:50]N: Received json : {"model":"HHCCJCY01HHCC","id":"C4:7C:8D:6A:EF:3C","batt":54}
[07:16:54]N: Subject: /BTtoMQTT/C47C8D6B0591
[07:16:54]N: Received json : {"model":"HHCCJCY01HHCC","id":"C4:7C:8D:6B:05:91","batt":47}
[07:16:54]N: BLE Connect end

The mi flora device advertize one attribute at a time so this is why you don’t get all the attributes in one message. The gateway acts as a pass through here and doesn’t store data.

If I understand way the scan after the battery reading doesn’t contains anymore data neither the MAC addresses of your mi flora?

Could you share your board setup (platformio env or config files) without credentials?

Of course: I use a Wemos Lolin32 Version 1.0.0.

[platformio]
default_envs = 
  esp32-ble-bc6

[env:esp32-ble-bc6]
platform = ${com.esp32_platform}
board = esp32dev    ; Also tryed: lolin32
board_build.partitions = min_spiffs.csv
lib_deps =
  ${com-esp.lib_deps}
  ${libraries.ble}
build_flags =
  ${com-esp.build_flags}
;  '-DDEFAULT_LOW_POWER_MODE=0'
  '-DZgatewayBT="BT"'
  '-DLED_RECEIVE=2'
  '-DLED_RECEIVE_ON=0'
  '-DESPWifiManualSetup=true'
  '-Dwifi_ssid="***"'
  '-Dwifi_password="***"'
  '-DMQTT_SERVER="mosquitto.***"'
  '-DMQTT_PORT="8883"'
  '-DMQTT_USER="omg"'
  '-DMQTT_PASS="omg"'
  '-DMQTT_SECURE_DEFAULT=true'
  '-DBase_Topic="omg/"'
  '-DGateway_Name="omg"'
  '-DNTP_SERVER="fritz.box"'

Furthermore I added my CA-cert to User_config.h.

Good catch, I found the issue, could you add:
'-DBLE_FILTER_CONNECTABLE=0'

Yes, it works. Thank you very much.