OpenMQTTGateway icon indicating copy to clipboard operation
OpenMQTTGateway copied to clipboard

Please add support to April Brother BLE-devices

Open Nikolay-Ch opened this issue 5 years ago • 6 comments

Please add support to April Brother BLE Beacon devices:

ABTemp: https://wiki.aprbrother.com/en/ABTemp.html https://wiki.aprbrother.com/en/ABTemp_Payload_Format.html

ABSebsor N01: https://wiki.aprbrother.com/en/ABSensor.html#absensor-n01

ABSensor N03: https://wiki.aprbrother.com/en/ABSensor.html#absensor-n03

Nikolay-Ch avatar Nov 23 '20 08:11 Nikolay-Ch

Hi,

If you have these sensors, could you take a look to how they advertize their data, servicedata, manufacturerdata, BLE connection? The best way to do that, is to download Nrf connect and look for the beacons and see if they advertise servicedata or manufacturerdata according to the measurements done. If yes you may publish here extracts of different values/ advertized data and we could check how to read them.

1technophile avatar Dec 01 '20 20:12 1technophile

Hi,

If you have these sensors, could you take a look to how they advertize their data, servicedata, manufacturerdata, BLE connection? The best way to do that, is to download Nrf connect and look for the beacons and see if they advertise servicedata or manufacturerdata according to the measurements done. If yes you may publish here extracts of different values/ advertized data and we could check how to read them.

Hi, ABTemp advertise sensor data with minor value in iBeacon protocol, so, if you get IBeacon-formatted advertising message with minor=0x641C, you get:

  • Temperature data at Low byte = 0x1C = 28℃
  • Battery level at High byte = 0x64 = 100 https://wiki.aprbrother.com/en/ABTemp_Payload_Format.html

Both ABNxx sensors advertise in the Eddystone format... Detailed info about packet format on the links: https://wiki.aprbrother.com/en/ABSensor.html#n01-packet-format https://wiki.aprbrother.com/en/ABSensor.html#n03-packet-format If I can help to do something, I can try, but I do not code at c++ for a long time...

Here is my code in c#, that parse data for ABN03 from OpenMQTTGateway message:

string payload = Encoding.UTF8.GetString(e.ApplicationMessage.Payload);
var payloadObj = JObject.Parse(payload);
var serviceData = payloadObj.ContainsKey("servicedata") ? payloadObj["servicedata"].Value<string>() : "";

// if serviceData not started with ab03, that we can't parse data - skip parsing
if (!serviceData.StartsWith("ab03"))
    return;

// convert hexadecimal string into byte-array
var payloadBytes = serviceData.FromHexStringToByteArray();

// create parsed messages
var temp = payloadBytes.ParseShortLE(9, 8);
var humi = payloadBytes.ParseShortLE(11, 2);
var illu = payloadBytes.ParseTwoBytesLE(13);
var batt = payloadBytes[8];

Nikolay-Ch avatar Dec 01 '20 21:12 Nikolay-Ch

Thanks for the info. Seems straightforward.

If I can help to do something, I can try,

Yes, if you could give me examples of manufacturer data, service data, and the expected sensor's values. It would help.

1technophile avatar Dec 01 '20 21:12 1technophile

Yes, if you could give me examples of manufacturer data, service data, and the expected sensor's values. It would help.

Look, For the AbTemp - packet is in the iBeacon standard... It's described here. First 9 bytes are constant, next 16 - USER guid for device (it can be changed at any time by user of the device. and the last 5 bytes carry the payload. So, you need to compare first 9 bytes to constant "0201061aff4c000215" then take last 5 bytes from service data and parse it. But, I don't know, how OMG parse BLE Advertising iBeacon standart packet. So I don't know what part of the iBeacon packet parsed into serviceData value.

For the ABN01 and ABN03 - the packеt is formed according to the format on this page. In gateway terminology - serviceData has started from 11th byte in the table on the page the link to which I gave above.

For ex packet for ABN03 looks like this:

{"id":"XX:XX:XX:XX:YY:ZZ","name":"abeacon_YYZZ","rssi":-76,"distance":6.44788,"servicedata":"ab03zzyyxxxxxxxx64ebff7e000000"}

So, you need to parse it to something like this:

{
  "id": "XX:XX:XX:XX:YY:ZZ",
  "name": "abeacon_YYZZ",
  "rssi": -76,
  "distance": 6.44788,
  "temp": -2.625,
  "hum": 63.0,
  "lux": 0.0,
  "batt": 100
}

by XXYYZZ - I replace my device MAC-addresses

Nikolay-Ch avatar Jan 12 '21 00:01 Nikolay-Ch

@Nikolay-Ch I may be able to add support for this but I need some more data if you're able to provide it. Some sample data of the advertising packets would be very helpful.

h2zero avatar Dec 28 '21 03:12 h2zero

Hi @Nikolay-Ch ,

I've just created a test decoder for the April Brother N03 sensor. For testing change the decoder URL in platformio.ini to

decoder = https://github.com/DigiH/decoder#ABN03-test

For your above example you should now get

{"id":"XX:XX:XX:XX:YY:ZZ","name":"abeacon_YYZZ","rssi":-76,"distance":6.44788,"servicedata":"ab03zzyyxxxxxxxx64ebff7e000000","brand":"AprilBrother","model":"N03","model_id":"ABSensor_N03","batt":100,"tempc":-2.625,"hum":63,"lux":0}

Let us know how it works for you, also with other measured values.

DigiH avatar Mar 04 '22 17:03 DigiH

Integrated

1technophile avatar Apr 10 '23 17:04 1technophile