bch-mqtt2influxdb icon indicating copy to clipboard operation
bch-mqtt2influxdb copied to clipboard

location mapping for a sensor

Open kiwi64ajs opened this issue 6 years ago • 4 comments

Hi Guys, I'm using mqtt2influxdb to read in temperature and humidity readings from bluetooth sensors via mqtt and it would be useful to be able to map the Bluetooth MAC address of the sensor to a user defined location string.

Is there any such configuration supported in the utility currently that would allow me to define a (key, value) pair dictionary in the config file and use that to map the sensor_id as the key and if exists, add a "location" tag with the user defined value, to the record being sent to influxdb?

Regards Alex Shepherd

kiwi64ajs avatar Sep 30 '19 01:09 kiwi64ajs

Hi, please send me example topics and payload and I look if is possible. Measurements, fields and tags support getting value from payload or topic over jsonpath rule

blavka avatar Oct 03 '19 08:10 blavka

Hi,

Here’s our config file:

mqtt: host: 127.0.0.1 port: 1883

influxdb: host: 127.0.0.1 port: 8086 database: office

points:

  • measurement: Temperature topic: +/+/Temperature fields: value: $.payload tags: sensor_id: $.topic[1]

  • measurement: Temperature2 topic: +/+/Temperature2 fields: value: $.payload tags: sensor_id: $.topic[1]

  • measurement: Humidity topic: +/+/Humidity fields: value: $.payload tags: sensor_id: $.topic[1]

  • measurement: Pressure topic: +/+/Pressure fields: value: $.payload tags: sensor_id: $.topic[1]

  • measurement: CO2 topic: +/+/CO2 fields: value: $.payload tags: sensor_id: $.topic[1]

  • measurement: VOC topic: +/+/VOC fields: value: $.payload tags: sensor_id: $.topic[1]

  • measurement: RSSI topic: +/+/RSSI fields: value: $.payload tags: sensor_id: $.topic[1]

  • measurement: BatteryLevel topic: +/+/BatteryLevel fields: value: $.payload tags: sensor_id: $.topic[1]

Here is a sample of our MQTT Data:

BLE2MQTT-F6B5/58:2d:34:34:31:a5/Type Mijia Temp+Hum BLE2MQTT-F6B5/58:2d:34:34:31:a5/RSSI -72 BLE2MQTT-F6B5/58:2d:34:34:31:a5/MACAddress 58:34:2d:34:31:a5 BLE2MQTT-F6B5/58:2d:34:34:31:a5/MessageCounter 241 BLE2MQTT-F6B5/58:2d:34:34:31:a5/Temperature 22.3 BLE2MQTT-F6B5/58:2d:34:34:31:a5/Humidity 58.7 BLE2MQTT-80E4/58:2d:34:34:31:a4/Type Mijia Temp+Hum BLE2MQTT-80E4/58:2d:34:34:31:a4/RSSI -76 BLE2MQTT-80E4/58:2d:34:34:31:a4/MACAddress 58:34:2d:34:31:a4 BLE2MQTT-80E4/58:2d:34:34:31:a4/MessageCounter 251 BLE2MQTT-80E4/58:2d:34:34:31:a4/Temperature 23.3 BLE2MQTT-80E4/58:2d:34:34:31:a4/Humidity 55.9 BLE2MQTT-1374/58:2d:34:34:33:41/Type Mijia Temp+Hum BLE2MQTT-1374/58:2d:34:34:33:41/RSSI -90 BLE2MQTT-1374/58:2d:34:34:33:41/MACAddress 58:34:2d:34:33:41 BLE2MQTT-1374/58:2d:34:34:33:41/MessageCounter 177 BLE2MQTT-1374/58:2d:34:34:33:41/Temperature 23.3 BLE2MQTT-1374/58:2d:34:34:33:41/Humidity 54.0 BLE2MQTT-F6B5/58:2d:34:34:39:6e/Type Mijia Temp+Hum BLE2MQTT-F6B5/58:2d:34:34:39:6e/RSSI -74 BLE2MQTT-F6B5/58:2d:34:34:39:6e/MACAddress 58:34:2d:34:39:6e BLE2MQTT-F6B5/58:2d:34:34:39:6e/MessageCounter 28 BLE2MQTT-F6B5/58:2d:34:34:39:6e/Temperature 25.7 BLE2MQTT-F6B5/58:2d:34:34:39:6e/Humidity 46.4

The middle part of the topic is the Bluetooth Sensor MAC Address, which we want to use as a key to lookup a value in a sensor locations list and add that location text to the InfluxDB measurement entry as a tag, which we can use in Grafana to show the location.

Below is the list of BLE MAC Addresses and Locations we want to use for the lookup above, which could be reformatted into a parsable file format. 58:2d:34:34:35:0e Admin Desk 58:2d:34:34:35:94 Boardroom Desk 58:2d:34:34:31:a4 Boardroom Vent 3C:71:BF:9A:BF:4C CO2 VOC Sensor 58:2d:34:34:33:43 Darren's Vent 58:2d:34:34:34:71 DevOps Vent 3C:71:BF:9A:BF:54 East CO2 VOC Sensor 4c:65:a8:d5:65:3e East Window 58:2d:34:34:39:67 Fabric Desk 58:2d:34:34:3a:29 Fabric Vent 58:2d:34:34:43:59 Fresh Air Duct 58:2d:34:34:36:9d Graham's Desk 58:2d:34:34:31:a3 Graham's Vent 3C:71:BF:9A:C1:3C Hosting Fresh Air CO2 VOC Sensor 58:2d:34:34:30:06 Hosting Vent 58:2d:34:34:34:f9 Hosting Wall 58:2d:34:34:2f:48 Infusion Desk 58:2d:34:34:2f:49 Jean Batten Desk 58:2d:34:34:35:c9 Jean Batten Vent 58:2d:34:34:39:71 JobFlow Demo Room 58:2d:34:34:34:d0 JobFlow Desk 58:2d:34:34:31:a5 JobFlow Vent 58:2d:34:34:25:a7 Lunchroom Vent 58:2d:34:34:39:8a RTG Desk 58:2d:34:34:32:50 Ray Avery Vent 58:2d:34:34:33:41 Sales Vent 58:2d:34:34:34:4c Stu's Desk 58:2d:34:34:39:f7 Web Desk 3C:71:BF:9A:BF:4C West CO2 VOC Sensor 58:2d:34:34:39:6e West Window For now I was just going to hack you code to add a dictionary with the key, values and add the tag just before we send the measurement to InfluxDB.

Thanks for considering the feature

Regards

Alex Shepherd

On 3/10/2019, at 9:29 PM, Karel Blavka [email protected] wrote:

Hi, please send me example topics and payload and I look if is possible. Measurements, fields and tags support getting value from payload or topic over jsonpath rule

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/bigclownlabs/bch-mqtt2influxdb/issues/9?email_source=notifications&email_token=AB5Y53IZS2NDMWUZGHN6KHDQMWUNHA5CNFSM4I3U5C3KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEAHNTXI#issuecomment-537844189, or mute the thread https://github.com/notifications/unsubscribe-auth/AB5Y53P6UJHXLU2SYQ3ZXOTQMWUNHANCNFSM4I3U5C3A.

kiwi64ajs avatar Oct 10 '19 05:10 kiwi64ajs

Hello, I see now. Unfortunately, it can't do this. But it's not a bad idea, I'm thinking about implementation.

blavka avatar Oct 15 '19 12:10 blavka

Hi Karel,

Here’s a “diff” of what I’ve done as a "quick hack” to the code in mqtt2influxdb.py to add locations into the bundle sent to InfluxDB:

root@airconmonitor:/usr/local/lib/python3.6/dist-packages/mqtt2influxdb# diff mqtt2influxdb.py-orig-ajs mqtt2influxdb.py 16a17,48

MacToLocationDict = { '58:2d:34:34:35:0e': 'Admin Desk', '58:2d:34:34:35:94': 'Boardroom Desk', '58:2d:34:34:31:a4': 'Boardroom Vent', '3C:71:BF:9A:BF:4C': 'CO2 VOC Sensor', '58:2d:34:34:33:43': 'Darren's Vent', '58:2d:34:34:34:71': 'DevOps Vent', '3C:71:BF:9A:BF:54': 'East CO2 VOC Sensor', '4c:65:a8:d5:65:3e': 'East Window', '58:2d:34:34:39:67': 'Fabric Desk', '58:2d:34:34:3a:29': 'Fabric Vent', '58:2d:34:34:43:59': 'Fresh Air Duct', '58:2d:34:34:36:9d': 'Graham's Desk', '58:2d:34:34:31:a3': 'Graham's Vent', '3C:71:BF:9A:C1:3C': 'Hosting Fresh Air CO2 VOC Sensor', '58:2d:34:34:30:06': 'Hosting Vent', '58:2d:34:34:34:f9': 'Hosting Wall', '58:2d:34:34:2f:48': 'Infusion Desk', '58:2d:34:34:2f:49': 'Jean Batten Desk', '58:2d:34:34:35:c9': 'Jean Batten Vent', '58:2d:34:34:39:71': 'JobFlow Demo Room', '58:2d:34:34:34:d0': 'JobFlow Desk', '58:2d:34:34:31:a5': 'JobFlow Vent', '58:2d:34:34:25:a7': 'Lunchroom Vent', '58:2d:34:34:39:8a': 'RTG Desk', '58:2d:34:34:32:50': 'Ray Avery Vent', '58:2d:34:34:33:41': 'Sales Vent', '58:2d:34:34:34:4c': 'Stu's Desk', '58:2d:34:34:39:f7': 'Web Desk', '3C:71:BF:9A:BF:4C': 'West CO2 VOC Sensor', '58:2d:34:34:39:6e': 'West Window' } 146a179,182

            sensorId = record['tags']['sensor_id']
            if sensorId in MacToLocationDict:
                    record['tags']['location'] = MacToLocationDict[sensorId]

Also thanks for a very helpful utility - keep up the good work.

Alex

On 16/10/2019, at 1:06 AM, Karel Blavka [email protected] wrote:

Hello, I see now. Unfortunately, it can't do this. But it's not a bad idea, I'm thinking about implementation.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/bigclownlabs/bch-mqtt2influxdb/issues/9?email_source=notifications&email_token=AB5Y53JZ2XWJS47SYRWWWGLQOWW45A5CNFSM4I3U5C3KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEBIP6TY#issuecomment-542179151, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB5Y53IUX45PJY2MTOLGAQDQOWW45ANCNFSM4I3U5C3A.

kiwi64ajs avatar Oct 15 '19 23:10 kiwi64ajs