description | title | keywords | image | slug | last_update | |||||
---|---|---|---|---|---|---|---|---|---|---|
SenseCAP M2 Multi-Platform Gateway LNS Configuration |
LNS Configuration |
|
/SenseCAP_m2_LNS_config |
|
SenseCAP M2 Multi Platform Gateway has a built-in LoRaWAN Network Server, it's based on Chirpstack, provides a fast and reliable solution for launching a LoRaWAN network.
Configure the gateway via the Web UI, please check the Quick Start to log into Luci.
Navigate to LoRa
> Channel Plan
Select the Region and Frequency plan.
After setting, click Save&Apply
Navigate to LoRa
> LoRa Network
Set Mode to Local Network Server
, add your MQTT info (Broker Host/Port/User/Password), other parameters can keep the default value.
Click Save&Apply
to apply your settings.
:::tip Note It will take about 1 min to start the process , then you can access the GUI configuration. :::
Login to the ChirpStack GUI via http://localhost:8080
.
The default account and password: admin
.
Then you will see the dashboard page.
Navigate to Network Server
> Regions
.
There should be a Region ID, click it and confirm the info, it should be same as your settings in the previous step.
Navigate to Tenant
> Device Profiles
, and click Add Profile
.
MAC version: LoRaWAN 1.0.3
Regional parameters reversion: A
ADR algorithm: Default ADR algorithm(LoRa only)
Expected uplink interval: Customize, default 3600s
Navigate to Codec
, and select JavaScript functions
, copy the SenseCAP Decoder for TTN and submit it.
Navigate to Gateway
, and click Add Gateway
.
Define the Name and Gateway ID(you can click to randomly generate the ID), then submit it.
Navigate to Tenant
> Application
, and click Add Application
.
Name your application and submit it.
Navigate to your application, and click Add device
.
Paste your device EUI and select the device profile we added before, then submit it.
Paste the Application key and click submit.
:::tip
Please check the user guide to set up the device correctly, select the platform to Other Platform
.
:::
Check the Events
of your device, you will get the join packet when the device joins the network.
You can also check the packet details.
This chapter is for cloud service development, the following guideline is for reference.
The MQTT integration exposes all events as documented by Event types.
The default event topic is:
application/APPLICATION\_ID/device/DEV\_EUI/event/EVENT
Check Event Types for more details.
You can find the Application id on your application tab:
- Event types
up | Uplink event |
---|---|
status | Margin and battery status |
join | Device join event |
ack | Confirmed downlink (n)ack |
txack | Downlink transmission ack |
log | Log (or error) event |
location | Location event |
integration | Integration event |
:::info Note
+
means to receive all messages
:::
Example:
- To receive uplink messages from all devices under a certain gateway:
gateway/<GATEWAY\_EUI>/device/+/event/up
- To receive all messages from all devices under the application:
application/+/device/+/event/+
- To receive all device messages from all gateways:
gateway/+/device/+/event/+
You can check the gatewayid
to distinguish the gateways.
When the object.valid is true, means the data analysis is successful, then you can traverse the object.messages, and extract the data type you need.
- Up event for SenseCAP LoRaWAN S210X Sensors payload example description:
upload\_battery
: Batteryupload\_interval
: upload interval, unit: Secondupload\_version
: Hardware/Firmware Versionreport\_telemetry
: Measurement value
The measurementId
in the ‘report_telemetry’ message please check SenseCAP Measurement ID for more details.
- Up event for SenseCAP Data logger payload example description:
The measurementId
in the ‘report_telemetry’ message please check SenseCAP Measurement ID for more details.
Click +
in the HTTP tab to add a new HTTP integration.
LNS will send messages as POST to the configured URL.
Submit your URL info.
:::info Note Support http only, not https. :::
The HTTP integration will make POST requests to the configured event endpoint or endpoints (multiple URLs can be configured, comma separated). The event URL query parameter indicates the type of the event.
The HTTP integration exposes all events as documented by Event Type.
Example:
(main.py)
from http.server import HTTPServer, BaseHTTPRequestHandler
from urllib.parse import urlparse, parse\_qs
from chirpstack\_api import integration
from google.protobuf.json\_format import Parse
class Handler(BaseHTTPRequestHandler):
\# True - JSON marshaler
\# False - Protobuf marshaler (binary)
json = False
def do\_POST(self):
self.send\_response(200)
self.end\_headers()
query\_args = parse\_qs(urlparse(self.path).query)
content\_len = int(self.headers.get('Content-Length', 0))
body = self.rfile.read(content\_len)
if query\_args["event"][0] == "up":
self.up(body)
elif query\_args["event"][0] == "join":
self.join(body)
else:
print("handler for event %s is not implemented" % query\_args["event"][0])
def up(self, body):
up = self.unmarshal(body, integration.UplinkEvent())
print("Uplink received from: %s with payload: %s" % (up.device\_info.dev\_eui, up.data.hex()))
def join(self, body):
join = self.unmarshal(body, integration.JoinEvent())
print("Device: %s joined with DevAddr: %s" % (join.device\_info.dev\_eui, join.dev\_addr))
def unmarshal(self, body, pl):
if self.json:
return Parse(body, pl)
pl.ParseFromString(body)
return pl
httpd = HTTPServer(('', 8090), Handler)
httpd.serve\_forever()
Downlink message:
:::info It’s recommended to mark the downlink as retained, Then the command will not be executed repeatedly. :::
The default Topic is:application/APPLICATION\_ID/device/DEV\_EUI/command/down
command
: Please check the downlink command in Device User Manual for more details.
Topic | application/APPLICATION_ID/device/DEV_EUI/command/down |
---|---|
devEUI | Device EUI |
confirmed | true/false(whether the payload must be sent as confirmed data down or not) |
fPort | FPort to use (must be > 0) |
data | base64 encoded data (plaintext, will be encrypted by ChirpStack) |
Example:
- Reboot SenseCAP S210x LoRaWAN Sensors:
Topic:
application/dbf6\*\*\*\*6c92/device/2CF7F1C2\*\*\*/command/down
Json:
{
"devEui":"2CF7F1C2\*\*\*",
"confirmed":true,
"fPort":2,
"data":"AMgAAAAAACsm"
}
- Set the upload interval of the SenseCAP S210x LoRaWAN Sensors to 1min :
Topic:
application/dbf6\*\*\*\*6c92/device/2CF7F1C2\*\*\*/command/down
Json:
{
"devEui":"2CF7F1C2\*\*\*",
"confirmed":true,
"fPort":2,
"data":"AIkAESIBAJBQ
"
}