Smartico P22-LR
Smartico P22-LR
Smartico
- Platform
- ThingsBoard
- Hardware Type
- Sensors
- Connectivity
- LoRaWAN
- Industry
- Energy Management, Smart Cities, Smart Buildings
- Use Case
- Smart Energy, Smart Metering, Water Metering
Introduction
The Smartico P22-LR is a pulse sensor used in industry, utilities, and automation for remote data collection via LoRaWAN networks. It has two universal pulse inputs with line integrity monitoring. In this guide, two water meters are connected to the device. Data is transmitted wirelessly over LoRaWAN in the license-free frequency range.
This guide describes how to receive telemetry from the Smartico P22-LR over LoRaWAN using ChirpStack and a ThingsBoard MQTT integration, and visualize the data on a dashboard.
Prerequisites
- Smartico P22-LR — 1×
- ChirpStack LoRaWAN Network Server with the device registered and connected
- ChirpStack MQTT integration configured with a Mosquitto MQTT broker
- ThingsBoard PE instance: use ThingsBoard Cloud or install a local PE server
Configure ChirpStack
Register the Smartico P22-LR in ChirpStack and verify the device is transmitting. The device should appear on the Applications page with its serial number (like 012685).
Create the uplink data converter
The uplink data converter decodes the Base64-encoded payload from the P22-LR into ThingsBoard telemetry format.
- Download uplink_pulse_sensor.json.
- Go to Integrations center ⇾ Data converters and click + Add data converter > Import converter.
- Drag and drop the downloaded
uplink_pulse_sensor.jsonfile. - Click Import.
/** Decoder **/var payloadStr = decodeToString(payload);var data = JSON.parse(payloadStr);
var KOEF_PULSE = 0.01;
var deviceName = data.deviceName;var deviceType = 'Water Pulse';var res = _base64ToArrayBuffer(data.data);var dateTime = GetCurrentDateTime();
var waterPulseValue1 = GetPulseMeterValue(res[3], res[4], res[5], res[6]);var waterPulseValue2 = GetPulseMeterValue(res[7], res[8], res[9], res[10]);
var fraud1 = GetFraud(res[2], 1);var fraud2 = GetFraud(res[2], 2);
var flg_err_pulse1 = GetErrPulse(res[2], 1);var flg_err_pulse2 = GetErrPulse(res[2], 2);
var low_bat = GetFlagError(res[0], 1);var motion_detect = GetFlagError(res[0], 2);var magnet_detect = GetFlagError(res[0], 3);var tamper_detect = GetFlagError(res[0], 4);var power_on = GetFlagError(res[0], 5);var power_bat = GetFlagError(res[0], 6);var err_time = GetFlagError(res[0], 7);var cfg_done = GetFlagError(res[0], 8);
var result = { deviceName: deviceName, deviceType: deviceType, attributes: { integrationName: metadata['integrationName'], }, telemetry: { NAME_DEV: "Water meter Pulse Sensor LoRaWAN 'Smartico P22-LR'", SN: data.deviceName, REAL_TIME: dateTime, WATER_PULSE_VALUE_1: waterPulseValue1, WATER_PULSE_VALUE_2: waterPulseValue2, FRAUD_1: fraud1, FRAUD_2: fraud2, FLG_ERR_PULSE_1: flg_err_pulse1, FLG_ERR_PULSE_2: flg_err_pulse2, FLG_LOW_BAT: low_bat, FLG_MOTION_DETECT: motion_detect, FLG_MAGNET_DETECT: magnet_detect, FLG_TAMPER_DETECT: tamper_detect, FLG_POWER_ON: power_on, FLG_POWER_BAT: power_bat, FLG_ERR_TIME: err_time, FLG_CFG_DONE: cfg_done }};
/** Helper functions **/
function decodeToString(payload) { return String.fromCharCode.apply(String, payload);}
function decodeToJson(payload) { var str = decodeToString(payload); return JSON.parse(str);}
function _base64ToArrayBuffer(base64) { var binary_string = atob(base64); var len = binary_string.length; var bytes = new Uint8Array(len); for (var i = 0; i < len; i++) { bytes[i] = binary_string.charCodeAt(i); } return bytes;}
function GetCurrentDateTime(){ var a = new Date(); var year = a.getFullYear().toString(); var month = (a.getMonth()+1).toString(); if(month.length==1) month="0"+month; var date = a.getDate().toString(); if(date.length==1) date="0"+date; var hour = a.getHours().toString(); if(hour.length==1) hour="0"+hour; var min = a.getMinutes().toString(); if(min.length==1) min="0"+min; var sec = a.getSeconds().toString(); if(sec.length==1) sec="0"+sec; return date + '.' + month + '.' + year + ' ' + hour + ':' + min + ':' + sec;}
function GetPulseMeterValue(byte1, byte2, byte3, byte4) { var value1 = parseInt(byte1, 10).toString(16); while(value1.length<2){value1='0'+value1;} var value2 = parseInt(byte2, 10).toString(16); while(value2.length<2){value2='0'+value2;} var value3 = parseInt(byte3, 10).toString(16); while(value3.length<2){value3='0'+value3;} var value4 = parseInt(byte4, 10).toString(16); while(value4.length<2){value4='0'+value4;}
var value = value1 + value2 + value3 + value4; var res = parseInt(value, 16);
return res * KOEF_PULSE;}
function GetFraud(byte1, num) { var value1 = parseInt(byte1, 10).toString(2); while(value1.length<8){value1='0'+value1;}
if(num==1){ var res = value1[5]+value1[6]+value1[7]; return parseInt(res,2); } if(num==2){ var res1 = value1[2]+value1[3]+value1[4]; return parseInt(res1,2); } return null;}
function GetErrPulse(byte1, num) { var value1 = parseInt(byte1, 10).toString(2); while(value1.length<8){value1='0'+value1;}
if(num==1) return parseInt(value1[1],2); if(num==2) return parseInt(value1[0],2);
return null;}
function GetFlagError(byte1, num) { var value = parseInt(byte1, 10).toString(2); while(value.length<8){value='0'+value;}
if(num==1) return Number(value[7]); if(num==2) return Number(value[6]); if(num==3) return Number(value[5]); if(num==4) return Number(value[4]); if(num==5) return Number(value[3]); if(num==6) return Number(value[2]); if(num==7) return Number(value[1]); if(num==8) return Number(value[0]);
return null;}
return result;You can test the converter before connecting the device. Open the Uplink Pulse Sensor converter, enter edit mode and click the Test decoder function tab. Paste the sample input below into the Payload content field and press Test.
Sample input payload (Base64-encoded)
{ "applicationID": "4", "applicationName": "Smartico_puls_sensor", "deviceName": "012685", "devEUI": "02aaaa010000318d", "rxInfo": [{ "gatewayID": "647fdafffe00d228", "uplinkID": "7ee7327f-9bde-4039-b993-4f8a2d593166", "name": "tectelic_micro_lite_TECH", "rssi": -72, "loRaSNR": 4, "location": { "latitude": 48.44229794818326, "longitude": 35.014479160308845, "altitude": 144 } }], "txInfo": { "frequency": 868500000, "dr": 0 }, "adr": true, "fCnt": 6368, "fPort": 7, "data": "YgASAACBBAAAAAk="}Expected decoded output
{ "deviceName": "012685", "deviceType": "Water Pulse", "attributes": { "integrationName": "Pulse Sensor" }, "telemetry": { "NAME_DEV": "Water meter Pulse Sensor LoRaWAN 'Smartico P22-LR'", "SN": "012685", "REAL_TIME": "27.08.2020 10:14:19", "WATER_PULSE_VALUE_1": 330.28000000000003, "WATER_PULSE_VALUE_2": 0.09, "FRAUD_1": 2, "FRAUD_2": 2, "FLG_ERR_PULSE_1": 0, "FLG_ERR_PULSE_2": 0, "FLG_LOW_BAT": 0, "FLG_MOTION_DETECT": 1, "FLG_MAGNET_DETECT": 0, "FLG_TAMPER_DETECT": 0, "FLG_POWER_ON": 0, "FLG_POWER_BAT": 1, "FLG_ERR_TIME": 1, "FLG_CFG_DONE": 0 }}Create the integration
For more information about MQTT integrations in ThingsBoard, see the MQTT integration documentation.
- Go to Integrations center ⇾ Integrations and click + Add integration.
- Basic settings:
- Set Integration type to MQTT.
- Enable integration and Allow create devices or assets are on by default.
- Click Next.
- Uplink data converter:
- Select existing — choose the previously created
Uplink Pulse Sensorfrom the list. - Click Next.
- Select existing — choose the previously created
- Downlink data converter:
- Click Skip — only needed for RPC; can be added later.
- Connection:
- Set your MQTT broker Host and Port.
- Select the Credentials type (e.g. Anonymous).
- Add at least one topic filter with QoS (e.g.
application/4/device/+/rx, QoS0 — At most once).
- Click Add to complete the integration setup.
Verify data
After the P22-LR transmits its first packet, a new device named after its serial number (like 012685) appears automatically in Entities > Devices. You can also verify input and output data in Data converters > Uplink Pulse Sensor > Events.
Create an asset
To display data on the dashboard, create an asset and add the device as a relation.
-
Go to Entities ⇾ Assets and create a new asset named
Pulse Sensorwith asset typepulse-sensor. -
Open the asset, go to the Relations tab, and add a relation to the device.
Import the rule chain
In addition to meter readings, the device reports status flags: low battery, tamper detection, and magnetic field exposure. These are displayed in an Alarm widget. Import the rule chain first to enable alarm processing.
-
Download alarms_pulse_sensor.json and import it in Rule chains.
-
Open the Root Rule Chain, add a link to the imported Alarms Pulse Sensor rule chain, and save.
Import the dashboard
-
Download dashboard_pulse_sensor.json and import it in Dashboards. See the dashboard import instructions.
-
After importing, edit the dashboard alias and set it to the Pulse Sensor asset created in the previous step.
The dashboard now displays live pulse counts and device health data from the Smartico P22-LR.