Solar Bluetooth Gateway is designed based on LoRaWAN and Bluetooth 5.0 technology. It receives nearby Bluetooth beacon messages, and then transmit to a LoRaWAN gateways through LoRaWAN after restructure the data. It is powered with robust solar film and a 5300mAh rechargeable battery.
Prerequisites
To continue with this guide we will need the following:
To create integration with the network server Chirpstack
Add a LoRaWAN Gateway on Chirpstack
First, we need to add a LoRaWAN gateway on the Chirpstack.
Step to add a gateway:
Log in to Chirpstack server. Go to the Gateways page and click the Add gateway button.
Enter the Name, Gateway ID (found in the gateway control panel), then scroll down and click the Submit button.
Once added, you can view the gateway's status under the Gateways tab.
Log in to Chirpstack server. Go to the Gateways page and click the Add gateway button.
Enter the Name, Gateway ID (found in the gateway control panel), then scroll down and click the Submit button.
Once added, you can view the gateway's status under the Gateways tab.
Configure the LoRaWAN Gateway to send data
To connect the gateway and transmit data to ChirpStack, follow these steps:
Open the gateway control panel. Go to the Network Settings page and set the Mode to Packet Forwarder. Enter your server address in the Server Address field (e.g., 192.168.31.11 in our case), then click Save & Apply button.
Verify the gateway's status on ChirpStack, it should now appear online.
Open the gateway control panel. Go to the Network Settings page and set the Mode to Packet Forwarder. Enter your server address in the Server Address field (e.g., 192.168.31.11 in our case), then click Save & Apply button.
Verify the gateway's status on ChirpStack, it should now appear online.
Add a device profile on Chirpstack
In Chirpstack UI, go to the Device Profiles page and click Add device profile button.
Fill in the required fields.
Navigate to the Codec tab, select “JavaScript functions”, paste the Solar Bluetooth Gateway decoder, and click Submit.
In Chirpstack UI, go to the Device Profiles page and click Add device profile button.
Fill in the required fields.
Navigate to the Codec tab, select “JavaScript functions”, paste the Solar Bluetooth Gateway decoder, and click Submit.
// 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.// Solar Bluetooth Gateway decoderfunctiondecodeUplink(input){// bytesvarbytes=input.bytes;// typevaruplinkType=(bytes[0]>>4)&0x0f;switch(uplinkType){case0x01:return{data:decodeRegistration(bytes)};case0x02:return{data:decodeHeartbeat(bytes)};case0x03:return{data:decodeDeviceReportRule(bytes)};case0x05:return{data:decodeWaterLevelDetection(bytes)};case0x08:return{data:decodeDeviceType1(bytes)};case0x09:return{data:decodeDeviceType2(bytes)};case0x0a:return{data:decodeDeviceType3(bytes)};case0x0e:return{data:decodeMultiDeviceTypeMessage(bytes)};case0x0f:return{data:decodeAcknowledgment(bytes)};default:returnnull;}}// type: 0x1 RegistrationfunctiondecodeRegistration(bytes){vardata={};data.type="Registration";// adrdata.adr=((bytes[0]>>3)&0x1)==0?"OFF":"ON";// modedata.mode=bytes[0]&0x07;// loRaWANBandvarloRaWANBandValue=bytes[1];if(loRaWANBandValue==0x00){data.loRaWANBand="KR920";}elseif(loRaWANBandValue==0x01){data.loRaWANBand="AU915";}elseif(loRaWANBandValue==0x04){data.loRaWANBand="CN470";}elseif(loRaWANBandValue==0x08){data.loRaWANBand="AS923";}elseif(loRaWANBandValue==0x10){data.loRaWANBand="EU433";}elseif(loRaWANBandValue==0x20){data.loRaWANBand="EU868";}elseif(loRaWANBandValue==0x40){data.loRaWANBand="US915";}// powerdata.power=((bytes[2]>>3)&0x1f)+"dBm";// continuousBleReceiveEnabledata.continuousBleReceiveEnable=((bytes[2]>>1)&0x1)==0?"Disable":"Enable";// drdata.dr=(bytes[3]>>4)&0x0f;// positionReportIntervaldata.positionReportInterval=(((bytes[4]<<8)&0xff00)|(bytes[5]&0xff))*5+"s";// heartbeatIntervaldata.heartbeatInterval=bytes[6]*30+"s";// bleReceivingDurationdata.bleReceivingDuration=bytes[7]+"s";// networkReconnectionIntervaldata.networkReconnectionInterval=bytes[8]*5+"min";returndata;}// type: 0x2 HeartbeatfunctiondecodeHeartbeat(bytes){vardata={};// typedata.type="Heartbeat";// batteryvarbatteryValue=bytes[1];if(batteryValue>100){data.battery=bytes[1]/100+1.5+"V";}else{data.battery=bytes[1]+"%";}// rssidata.rssi=bytes[2]*-1+"dBm";// snrdata.snr=(((bytes[3]<<8)&0xff00)|(bytes[4]&0xff))/100+"dB";// versiondata.version=((bytes[5]<<8)&0xff00)|(bytes[6]&0xff);// chargeStatevarchargeStateValue=bytes[7]&0xff;if(chargeStateValue==0x00){data.chargeState="Not charging";}elseif(chargeStateValue==0x50){data.chargeState="Charging";}elseif(chargeStateValue==0x60){data.chargeState="Charging completed";}returndata;}// type: 0x3 DeviceReportRulefunctiondecodeDeviceReportRule(bytes){vardata={};data.type="DeviceReportRule";data.deviceTypeQuantity=bytes[1]&0xff;data.deviceTypeId=(bytes[2]>>4)&0x0f;data.filterAndDataBlockQuantity=bytes[2]&0x0f;varfilterBlock=[];vardataBlock=[];varmacBlock=[];varindex=3;for(leti=0;i<data.filterAndDataBlockQuantity;i++){varruleType=bytes[index++]&0xff;varstartAddress=bytes[index++]&0xff;varendAddress=bytes[index++]&0xff;varfilter={};if(ruleType==1){filter.ruleType="FilterBlock";filter.startAddress=byteToHex(startAddress);filter.endAddress=byteToHex(endAddress);varlen=endAddress-startAddress;varfilterValue="";for(letj=0;j<len+1;j++){filterValue+=byteToHex(bytes[index+j]);}filter.value=filterValue;index=index+(endAddress-startAddress+1);filterBlock.push(filter);}elseif(ruleType==2){filter.ruleType="DataBlock";filter.startAddress=byteToHex(startAddress);filter.endAddress=byteToHex(endAddress);dataBlock.push(filter);}elseif(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;returndata;}// type: 0x5 WaterLevelDetectionfunctiondecodeWaterLevelDetection(bytes){vardata={};// typedata.type="WaterLevelDetection";data.waterLevel=(((bytes[1]<<8)&0xff00)|(bytes[2]&0xff))+"mm";returndata;}// type: 0x8 DeviceType1functiondecodeDeviceType1(bytes){vardata={type:"DeviceType1",number:bytes[0]&0x0f,};varindex=1;for(leti=0;i<data.number;i++){varmajor=((bytes[index]<<8)|bytes[index+1]).toString(16).toUpperCase().padStart(4,"0");varminor=((bytes[index+2]<<8)|bytes[index+3]).toString(16).toUpperCase().padStart(4,"0");varrssi=bytes[index+4]-256+"dBm";data["beacon"+(i+1)]=major+minor;data["rssi"+(i+1)]=rssi;index=index+5;}returndata;}// type: 0x9 DeviceType2functiondecodeDeviceType2(bytes){vardata={type:"DeviceType2",number:bytes[0]&0x0f,};varindex=1;for(leti=0;i<data.number;i++){varmajor=((bytes[index]<<8)|bytes[index+1]).toString(16).toUpperCase().padStart(4,"0");varminor=((bytes[index+2]<<8)|bytes[index+3]).toString(16).toUpperCase().padStart(4,"0");varrssi=bytes[index+4]-256+"dBm";data["beacon"+(i+1)]=major+minor;data["rssi"+(i+1)]=rssi;index=index+5;}returndata;}// type: 0xa DeviceType3functiondecodeDeviceType3(bytes){vardata={type:"DeviceType3",number:bytes[0]&0x0f,};varindex=1;for(leti=0;i<data.number;i++){varmajor=((bytes[index]<<8)|bytes[index+1]).toString(16).toUpperCase().padStart(4,"0");varminor=((bytes[index+2]<<8)|bytes[index+3]).toString(16).toUpperCase().padStart(4,"0");varrssi=bytes[index+4]-256+"dBm";data["beacon"+(i+1)]=major+minor;data["rssi"+(i+1)]=rssi;index=index+5;}returndata;}// type: 0xe MultiDeviceTypeMessagefunctiondecodeMultiDeviceTypeMessage(bytes){vardata={type:"MultiDeviceTypeMessage",number:bytes[0]&0x0f,};varindex=1;for(leti=0;i<data.number;i++){varindex=1+6*i;vardeviceTypeId=bytes[index];varmajor=((bytes[index+1]<<8)|bytes[index+2]).toString(16).toUpperCase().padStart(4,"0");varminor=((bytes[index+3]<<8)|bytes[index+4]).toString(16).toUpperCase().padStart(4,"0");varrssi=bytes[index+5]-256+"dBm";data["deviceTypeId"+(i+1)]=deviceTypeId;data["beacon"+(i+1)]=major+minor;data["rssi"+(i+1)]=rssi;index=index+6;}returndata;}// type: 0xf AcknowledgmentfunctiondecodeAcknowledgment(bytes){vardata={};data.type="Acknowledgment";data.result=(bytes[0]&0x0f)==0?"Success":"Failure";data.msgId=(bytes[1]&0xff).toString(16).toUpperCase();returndata;}functionbyteToHex(str){returnstr.toString(16).toUpperCase().padStart(2,"0");}
Add a device on Chirpstack
Go to the Applications page and click Add application button.
Enter application name and click Submit button.
Click Add device button.
Fill in the device configuration parameters.
Go to the Variables dection, enter the “ThingsBoardAccessToken” parameter, and then click the Submit button.
Enter your Application key in this field and click Submit button to save the device.
Go to the Applications page and click Add application button.
Enter application name and click Submit button.
Click Add device button.
Fill in the device configuration parameters.
Go to the Variables dection, enter the “ThingsBoardAccessToken” parameter, and then click the Submit button.
Enter your Application key in this field and click Submit button to save the device.
Configure Application Integration with ThingsBoard
Go to the Integrations page and click on ThingsBoard.
Enter your ThingsBoard server address and click Submit.
Go to the Integrations page and click on ThingsBoard.
Enter your ThingsBoard server address and click Submit.
Create device on ThingsBoard
Go to the Devices page.
Click the plus icon to add new device.
Enter the device information and click “Next: Credentials” button.
Enter the Access token for the device and click Add button.
Click on the device to view detailed information.
Navigate to the Latest telemetry tab to view the device's reported data.
Go to the Devices page.
Click the plus icon to add new device.
Enter the device information and click “Next: Credentials” button.
Enter the Access token for the device and click Add button.
Click on the device to view detailed information.
Navigate to the Latest telemetry tab to view the device's reported data.
Conclusion
With the information provided in this guide, you can easily connect your Solar Bluetooth Gateway and transmit data to ThingsBoard.
For further learning about key concepts and features, explore the platform's documentation. You can also configure alarm rules or set up dashboards.
Our website uses cookies to ensure site security and optimize your experience on our website. By continuing to browse this site, you agree to the use of these cookies, in accordance with our Cookie Policy. For details on managing cookies, please adjust your browser settings.