# JAVA: Encode Beacon MessagePack form MQTT via AB BLE Gateway 4.0

**URL:** <https://bbs.aprbrother.com/t/java-encode-beacon-messagepack-form-mqtt-via-ab-ble-gateway-4-0/1686>\
**Category:** BLE Gateway\
**Created:** [October 7, 2020, 4:48pm UTC](https://bbs.aprbrother.com/t/java-encode-beacon-messagepack-form-mqtt-via-ab-ble-gateway-4-0/1686 "2020-10-07T16:48:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![motocrossmaster](https://bbs.aprbrother.com/letter_avatar_proxy/v4/letter/m/96bed5/32.png) [@motocrossmaster](https://bbs.aprbrother.com/u/motocrossmaster)\
**Post date:** [October 7, 2020, 4:48pm UTC](https://bbs.aprbrother.com/t/java-encode-beacon-messagepack-form-mqtt-via-ab-ble-gateway-4-0/1686/1 "2020-10-07T16:48:12Z")

</div>

JAVA:  
I have encoding problems when evaluating the MessagePack.  
A part is encoded correctly, but the advertising (devices) is not encoded correctly.

 ![image](https://bbs.aprbrother.com/uploads/default/original/1X/e93532b293044f16ede0647502faa5bf527cd167.png)

**I actually want to evaluate the following values:**  
ID of the beacon  
RSSI  
Tx-Power  
Battery level in% (do you have a java example?)

_Can someone help me there?_

The example-method Parse.java did not work unfortunately:  
Link: gateway-v4/examples/java/http-server/Parse.java

**Hardware:**  
AprilBeacon EEK-N BLE Beacon (Eddystone UID)  
AB BLE Gateway 4.0 (MQTT)

_ **Gateway Config:** _  
Connection Type: MQTT Client  
Host: [mqtt.bconimg.com](http://mqtt.bconimg.com)  
Port: 1883  
Publish Topic: joelBLE  
Request Interval: 2 sec  
RSSI Filter: Default  
**Advertising Filter: Eddystone UID Only**  
Duplicate Filter: Yes  
Auto Restart: Disable

**Here is my project on GitLab:**  
[https://dev.hftm.ch:4430/Joel.Blaser/mqtt-test.git](https://dev.hftm.ch:4430/Joel.Blaser/mqtt-test.git)

---

<div class="post-metadata">

**Author:** ![motocrossmaster](https://bbs.aprbrother.com/letter_avatar_proxy/v4/letter/m/96bed5/32.png) [@motocrossmaster](https://bbs.aprbrother.com/u/motocrossmaster)\
**Post date:** [October 8, 2020, 7:41am UTC](https://bbs.aprbrother.com/t/java-encode-beacon-messagepack-form-mqtt-via-ab-ble-gateway-4-0/1686/2 "2020-10-08T07:41:32Z")

</div>

I found the Problem. the message was not always a Beacon, so it wasn`t always a map-format. So i have to check if the message is in map-format, then i can parse the massage like in the parse.java example.  
[https://github.com/AprilBrother/ab-ble-gateway-sdk/blob/master/gateway-v4/examples/java/http-server/Parse.java](https://github.com/AprilBrother/ab-ble-gateway-sdk/blob/master/gateway-v4/examples/java/http-server/Parse.java)

just add the line:  
if( unpacker.getNextFormat() == MessageFormat.FIXMAP) {

 ![image](https://bbs.aprbrother.com/uploads/default/original/1X/e23036909f6b79920d13646ab778fa382cd64c25.png)

---

<div class="post-metadata">

**Author:** ![aprilpea](https://bbs.aprbrother.com/user_avatar/bbs.aprbrother.com/aprilpea/32/9_2.png) [@aprilpea](https://bbs.aprbrother.com/u/aprilpea)\
**Post date:** [October 9, 2020, 3:42am UTC](https://bbs.aprbrother.com/t/java-encode-beacon-messagepack-form-mqtt-via-ab-ble-gateway-4-0/1686/3 "2020-10-09T03:42:02Z")

</div>

Thanks for your update!
