Skip to content
Stand with Ukraine flag

Micro Bluetooth Gateway

Micro Bluetooth Gateway

Micro Bluetooth Gateway

Lansitec

Platform
ThingsBoard
Hardware Type
Gateways
Connectivity
LoRaWAN
Industry
Smart Cities, Smart Buildings, Industrial Manufacturing, Security
Use Case
Smart Office, Fleet Tracking

Micro Bluetooth Gateway is designed based on LoRaWAN and Bluetooth 5.0 technology. It receives nearby beacon information and forwards it to a LoRaWAN gateway. It is powered by 8000mAh industrial battery with a standby time as long as 6 years (Bluetooth receive duration is 60s in every one hour LoRa report interval).

Prerequisites

To continue with this guide we will need the following:

Configuration

Only ThingsBoard Cloud works when using direct communication from this device to ThingsBoard via MQTT.

You may use ThingsBoard PE on-premises or ThingsBoard Cloud when using ThingsBoard Integrations.

To create an integration with a network server please choose first one of the supported network servers:

Add a gateway on the Chirpstack

We need to add a gateway on the Chirpstack.

To add a gateway, follow next steps:

  1. Login to Chirpstack server. Go to the “Gateways” page and click on the “Add gateway” button.
  2. Fill name, Gateway ID (It will be different, you can find it on the gateway control panel) with your data, scroll down and click on the “Submit” button.
  3. The gateway is added. In gateways tab you can see its status.

Add device profile on the Chirpstack

  1. Login to Chirpstack server. Go to the “Device profiles” page and click on Add device profile button.
  2. Fill in the required fields.
  3. Go to the Codec tab, select JavaScript functions from the Payload codec dropdown menu, and paste the decoder function. Then click the Submit button.

Decode function:

// Decode uplink function.
//
// Input is an object with the following fields:
// - bytes = Byte array containing the uplink payload, e.g. [255, 230, 255, 0]
// - fPort = Uplink fPort.
// - variables = Object containing the configured device variables.
//
// Output must be an object with the following fields:
// - data = Object representing the decoded payload.
// Micro Bluetooth Gateway decoder
function decodeUplink(input) {
// bytes
var bytes = input.bytes;
// type
var uplinkType = (bytes[0] >> 4) & 0x0f;
switch (uplinkType) {
case 0x01:
return {data: decodeRegistration(bytes)};
case 0x02:
return {data: decodeHeartbeat(bytes)};
case 0x03:
return {data: decodeDeviceReportRule(bytes)};
case 0x05:
return {data: decodeWaterLevelDetection(bytes)};
case 0x08:
return {data: decodeDeviceType1(bytes)};
case 0x09:
return {data: decodeDeviceType2(bytes)};
case 0x0a:
return {data: decodeDeviceType3(bytes)};
case 0x0e:
return {data: decodeMultiDeviceTypeMessage(bytes)};
case 0x0f:
return {data: decodeAcknowledgment(bytes)};
default:
return null;
}
}
// type: 0x1 Registration
function decodeRegistration(bytes) {
var data = {};
data.type = "Registration";
// adr
data.adr = ((bytes[0] >> 3) & 0x1) == 0 ? "OFF" : "ON";
// mode
data.mode = bytes[0] & 0x07;
// loRaWANBand
var loRaWANBandValue = bytes[1];
if (loRaWANBandValue == 0x00) {
data.loRaWANBand = "KR920";
} else if (loRaWANBandValue == 0x01) {
data.loRaWANBand = "AU915";
} else if (loRaWANBandValue == 0x04) {
data.loRaWANBand = "CN470";
} else if (loRaWANBandValue == 0x08) {
data.loRaWANBand = "AS923";
} else if (loRaWANBandValue == 0x10) {
data.loRaWANBand = "EU433";
} else if (loRaWANBandValue == 0x20) {
data.loRaWANBand = "EU868";
} else if (loRaWANBandValue == 0x40) {
data.loRaWANBand = "US915";
}// power
data.power = ((bytes[2] >> 3) & 0x1f) + "dBm";
// continuousBleReceiveEnable
data.continuousBleReceiveEnable =
((bytes[2] >> 1) & 0x1) == 0 ? "Disable" : "Enable";
// dr
data.dr = (bytes[3] >> 4) & 0x0f;
// positionReportInterval
data.positionReportInterval =
(((bytes[4] << 8) & 0xff00) | (bytes[5] & 0xff)) * 5 + "s";
// heartbeatInterval
data.heartbeatInterval = bytes[6] * 30 + "s";
// bleReceivingDuration
data.bleReceivingDuration = bytes[7] + "s";
// networkReconnectionInterval
data.networkReconnectionInterval = bytes[8] * 5 + "min";
return data;
}
// type: 0x2 Heartbeat
function decodeHeartbeat(bytes) {
var data = {};
// type
data.type = "Heartbeat";
// battery
var batteryValue = bytes[1];
if (batteryValue > 100) {
data.battery = bytes[1] / 100 + 1.5 + "V";
} else {
data.battery = bytes[1] + "%";
}
// rssi
data.rssi = bytes[2] * -1 + "dBm";
// snr
data.snr = (((bytes[3] << 8) & 0xff00) | (bytes[4] & 0xff)) / 100 + "dB";
// version
data.version = ((bytes[5] << 8) & 0xff00) | (bytes[6] & 0xff);
// chargeState
var chargeStateValue = bytes[7] & 0xff;
if (chargeStateValue == 0x00) {
data.chargeState = "Not charging";
} else if (chargeStateValue == 0x50) {
data.chargeState = "Charging";
} else if (chargeStateValue == 0x60) {
data.chargeState = "Charging completed";
}
return data;
}
// type: 0x3 DeviceReportRule
function decodeDeviceReportRule(bytes) {
var data = {};
data.type = "DeviceReportRule";
data.deviceTypeQuantity = bytes[1] & 0xff;
data.deviceTypeId = (bytes[2] >> 4) & 0x0f;
data.filterAndDataBlockQuantity = bytes[2] & 0x0f;
var filterBlock = [];
var dataBlock = [];
var macBlock = [];
var index = 3;
for (let i = 0; i < data.filterAndDataBlockQuantity; i++) {
var ruleType = bytes[index++] & 0xff;
var startAddress = bytes[index++] & 0xff;
var endAddress = bytes[index++] & 0xff;
var filter = {};
if (ruleType == 1) {
filter.ruleType = "FilterBlock";
filter.startAddress = byteToHex(startAddress);
filter.endAddress = byteToHex(endAddress);
var len = endAddress - startAddress;
var filterValue = "";
for (let j = 0; j < len + 1; j++) {
filterValue += byteToHex(bytes[index + j]);
}
filter.value = filterValue;
index = index + (endAddress - startAddress + 1);
filterBlock.push(filter);
} else if (ruleType == 2) {
filter.ruleType = "DataBlock";
filter.startAddress = byteToHex(startAddress);
filter.endAddress = byteToHex(endAddress);
dataBlock.push(filter);
} else if (ruleType == 3) {
filter.ruleType = "MACBlock";
filter.startAddress = byteToHex(startAddress);
filter.endAddress = byteToHex(endAddress);
macBlock.push(filter);
}
}
data.filterBlock = filterBlock;
data.dataBlock = dataBlock;
data.macBlock = macBlock;
return data;
}
// type: 0x5 WaterLevelDetection
function decodeWaterLevelDetection(bytes) {
var data = {};
// type
data.type = "WaterLevelDetection";
data.waterLevel = (((bytes[1] << 8) & 0xff00) | (bytes[2] & 0xff)) +
"mm";
return data;
}
// type: 0x8 DeviceType1
function decodeDeviceType1(bytes) {
var data = {
type: "DeviceType1",
number: bytes[0] & 0x0f,
};
var index = 1;
for (let i = 0; i < data.number; i++) {
var major = ((bytes[index] << 8) | bytes[index + 1])
.toString(16)
.toUpperCase()
.padStart(4, "0");
var minor = ((bytes[index + 2] << 8) | bytes[index + 3])
.toString(16)
.toUpperCase()
.padStart(4, "0");
var rssi = bytes[index + 4] - 256 + "dBm";
data["beacon" + (i + 1)] = major + minor;
data["rssi" + (i + 1)] = rssi;
index = index + 5;
}
return data;
}
// type: 0x9 DeviceType2
function decodeDeviceType2(bytes) {
var data = {
type: "DeviceType2",
number: bytes[0] & 0x0f,
};
var index = 1;
for (let i = 0; i < data.number; i++) {
var major = ((bytes[index] << 8) | bytes[index + 1])
.toString(16)
.toUpperCase()
.padStart(4, "0");
var minor = ((bytes[index + 2] << 8) | bytes[index + 3])
.toString(16)
.toUpperCase()
.padStart(4, "0");
var rssi = bytes[index + 4] - 256 + "dBm";
data["beacon" + (i + 1)] = major + minor;
data["rssi" + (i + 1)] = rssi;
index = index + 5;
}
return data;
}
// type: 0xa DeviceType3
function decodeDeviceType3(bytes) {
var data = {
type: "DeviceType3",
number: bytes[0] & 0x0f,
};
var index = 1;
for (let i = 0; i < data.number; i++) {
var major = ((bytes[index] << 8) | bytes[index + 1]).toString(16)
.toUpperCase()
.padStart(4, "0");
var minor = ((bytes[index + 2] << 8) | bytes[index + 3])
.toString(16)
.toUpperCase()
.padStart(4, "0");
var rssi = bytes[index + 4] - 256 + "dBm";
data["beacon" + (i + 1)] = major + minor;
data["rssi" + (i + 1)] = rssi;
index = index + 5;
}
return data;
}
// type: 0xe MultiDeviceTypeMessage
function decodeMultiDeviceTypeMessage(bytes) {
var data = {
type: "MultiDeviceTypeMessage",
number: bytes[0] & 0x0f,
};
var index = 1;
for (let i = 0; i < data.number; i++) {
var index = 1 + 6 * i;
var deviceTypeId = bytes[index];
var major = ((bytes[index + 1] << 8) | bytes[index + 2])
.toString(16)
.toUpperCase()
.padStart(4, "0");
var minor = ((bytes[index + 3] << 8) | bytes[index + 4])
.toString(16)
.toUpperCase()
.padStart(4, "0");
var rssi = bytes[index + 5] - 256 + "dBm";
data["deviceTypeId" + (i + 1)] = deviceTypeId;
data["beacon" + (i + 1)] = major + minor;
data["rssi" + (i + 1)] = rssi;
index = index + 6;
}
return data;
}
// type: 0xf Acknowledgment
function decodeAcknowledgment(bytes) {
var data = {};
data.type = "Acknowledgment";
data.result = (bytes[0] & 0x0f) == 0 ? "Success" : "Failure";
data.msgId = (bytes[1] & 0xff).toString(16).toUpperCase();
return data;
}
function byteToHex(str) {
return str.toString(16).toUpperCase().padStart(2, "0");
}

Add a device on the Chirpstack

  1. Go to the Applications page and click on Add application button.
  2. Enter name and click Submit button.
  3. Click Add device.
  4. Fill in the required fields with your device information and specify the previously created device profile.
  5. Go to the Variables tab, enter the value for ThingsBoardAccessToken, and click the Submit button.
  6. Put your Application key to the field and click on Submit button to save the device.

Configure application integration with ThingsBoard

  1. Go to the Integrations page, find and select the ThingsBoard.
  2. Enter the URL of your ThingsBoard server and click Submit button.

Create device on ThingsBoard

  1. Go to the Devices page.
  2. Click on Add device button.
  3. Fill in the device name and click the Next: Credentials button.
  4. Enter the device Access token (previously copied Device EUI value) and click the Add button.
  5. Click on the device to open device information window.
  6. Go to the Latest telemetry tab to view device reported data.

Check data on ThingsBoard

So, the device was added and if it sends any data - it should appear in the devices. To check it you may open Devices page in Entities section. The device should be in devices list. You can check the data by click on it and open tab Attributes or Latest telemetry.

In order to get more user-friendly view - you can use dashboards. You can download a simple dashboard for this device, it is configured to display a data from “latitude” and “longitude” telemetry keys for device with name “Devices”.

ThingsBoard provides the ability to create and customize interactive visualizations (dashboards) for monitoring and managing data and devices. Through ThingsBoard dashboards, you can efficiently manage and monitor your IoT devices and data. So, we will create the dashboard, for our device.

To add the dashboard to ThingsBoard, we need to import it. To import a dashboard, follow these steps:

  1. Navigate to the “Dashboards” page. By default, you navigate to the dashboard group “All”. Click on the “plus” icon in the top right corner. Select “Import dashboard”.
  2. In the dashboard import window, upload the JSON file and click “Import” button.
  3. Dashboard has been imported.

To open the imported dashboard, click on it. Then you should specify your device in entity alias of the dashboard.

To do this, follow these steps:

  1. Open the dashboard and enter edit mode. Click the “Entity aliases” icon, then in the pop-up window click the “Edit alias” icon next to the alias.
  2. In edit alias window select your device from dropdown list and save entity alias.
  3. Apply all changes.

You should now see data from the device.

Example of the dashboard with data:

Conclusion

With the knowledge outlined in this guide, you can easily connect your Asset Management Tracker and send data to ThingsBoard.

Explore the platform documentation to learn more about key concepts and features. For example, configure alarm rules or dashboards.