Shelly LoRa Add-On
Shelly LoRa add-on provides two-way RF communication using LoRa radio protocol. It uses LoRa as RPC namespace and provides the methods:
LoRa.SetConfigto update the component's configurationLoRa.GetConfigto obtain the component's configurationLoRa.GetStatusto obtain the component's statusLoRa.SendBytesto send raw data over LoRa RF sendbytesLoRa.Sendto send data over LoRa RF using Shelly Long-Range Protocol (SheLR) send
Methods
LoRa.SetConfig
This method updates the configuration of the LoRa component.
Parameters:
| Property | Type | Description |
|---|---|---|
| number | ID of the LoRa component instance |
| object | Configuration that the method takes |
Find more about the config properties in config section
Response:
null on success; error if the request can not be executed or failed
Example: LoRa.SetConfig Example
LoRa.GetConfig
This method retrieves the configuration of the LoRa component.
Parameters:
| Property | Type | Description |
|---|---|---|
| number | ID of the LoRa component instance |
Find more about the config properties in config section
Example: LoRa.GetConfig Example
LoRa.GetStatus
This method retrieves the status of the LoRa component.
Parameters:
| Property | Type | Description |
|---|---|---|
| number | ID of the LoRa component instance |
Find more about the status properties in status section
Example: LoRa.GetStatus Example
LoRa.SendBytes
Sends raw data over LoRa RF.
Parameters:
| Property | Type | Description |
|---|---|---|
| number | ID of the LoRa component instance |
| string | Data to be sent (remark: data should be encoded in 'base64') |
Response:
null on success; error if the request can not be executed or failed
Example: LoRa.SendBytes Example
LoRa.Send
Sends data over LoRa RF using SheLR. For more details see info below.
Parameters:
| Property | Type | Description |
|---|---|---|
| number | ID of the LoRa component instance |
| string | The address of recipient in LoRa network as hexadecimal string |
| string | The encryption key, |
| number | The encryption key index, possible values: [1,3], |
| string | Data to be sent (remark: data should be encoded in 'base64') |
Response:
null on success; error if the request can not be executed or failed
LoRa RF using SheLR:
- LoRa RF using SheLR gives more benefits of using LoRa: more advanced security based on AES-CCM cryptography, unicast, multicast, broadcast communication
- Using LoRa RF over SheLR should be considered preferable way compared to LoRa.SendBytes
The encryption key:
- The cryptography keys should be encoded in 'base64'
- The size of the keys should be 16 bytes (128 bit key)
- To generate keys and encode them to base64 the following command could be used:
openssl rand -base64 16 (it works on Linux, macOS and Windows)
- If
tx_keyortx_key_idare not provided when callingLoRa.Send, the one fromLoRa.SetConfigwill be used for encryption - If both
tx_keyandtx_key_idare provided an error will be returned as mutual exclusive
The address of recipient lr_addr:
- The size of the address should be 8 symbols (4 bytes), represented as hexadecimal string
- The address could be "FFFFFFFF" for broadcast sending to all devices in LoRa network
Example: LoRa.Send Example
Configuration
LoRa add-on can be enabled or disabled by setting device.addon_type parameter in Sys config. To enable Shelly LoRa Add-on, addon_type must be set to "LoRa". When add-on is enabled, device must be restarted and all related API will be accessible. To disable Shelly LoRa Add-on, parameter device.addon_type must be set to null, after disabling, the device must be restarted as well.
The configuration of the LoRa component shows the current settings of the LoRa add-on and Shelly Long-Range Protocol (SheLR).
Parameters:
| Property | Type | Description | |||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| number | ID of the LoRa component instance | |||||||||||||||||||||||||
| string | RF band plan, possible settings: EU868, US915, BR915-928, the | |||||||||||||||||||||||||
| number | Frequency in Hz, possible values:
| |||||||||||||||||||||||||
| number | Bandwidth in kHz, for possible values see the table below | |||||||||||||||||||||||||
| number | Data rate (or spreading factor), possible values: [7, 12] | |||||||||||||||||||||||||
| number | Coding rate, possible values: [5, 8], corresponding to coding rates:["4:5", "4:8"] | |||||||||||||||||||||||||
| number | Preamble length, possible values: [6, 65535] | |||||||||||||||||||||||||
| number | Transmit power in dBm, possible values: [0, 14] | |||||||||||||||||||||||||
| boolean | Enable/disable reception over RF | |||||||||||||||||||||||||
| object | Frequency hopping settings (see
| |||||||||||||||||||||||||
| object | SheLR settings (see
|
Band Plan policy:
- If Band plan is set to
EU868, the frequency possible values should be used, like listed infreq: [863000000,870000000] - If Band plan is set to
US915, the frequency possible values should be used, like listed infreq: [902000000,928000000] - If Band plan is set to
BR915-928, the frequency possible values should be used, like listed infreq: [915000000,928000000]
Possible bandwidth values depend on RF band plan.
| RF Band Plan | EU868 | US915 | BR915-928 |
|---|---|---|---|
| Bandwidth | 125 and 250 | 125, 250 and 500 | 125, 250 and 500 |
Frequency hopping enable flag: enable:
enableflag applies only to band planUS915, otherwise is discarded- If band plan is set
US915,enableflag should be set totrue
Frequency hopping settings: fh, freqs
fhsettings apply only to band planUS915, otherwise are discarded- The number of elements (frequencies) in the list (
freqs) should be exactly 64 - If Band plan is set to
US915, the frequency possible values in the list (freqs) should be in range: [902000000,928000000] - Any next frequency in the list should be greater or less with 25000 kHz compared to previous one
- Frequencies in the list should be unique
SheLR settings:
The cryptography keys:
- The cryptography keys should be encoded in 'base64'
- The size of the keys should be 16 bytes (128 bit key)
- To generate keys and encode them to base64 the following command could be used:
openssl rand -base64 16 (it works on Linux, macOS and Windows)
- If
tx_key_idis not provided during configuration, it should be provided whenLoRa.Sendmethod is being called, in order encryption to be done - Although, configuring cryptography keys are
optional, at least 1 from the list of 3 should be provided, in order cryptography to be done - If
nullis provided forkey1,key2andkey3, the current settings will be erased
Device LoRa address lr_addr:
- The size of the address should be 8 symbols (4 bytes), represented as hexadecimal string
- The address could not be "FFFFFFFF" (broadcast)
- If
nullis provided the last 4 bytes of Wi-Fi MAC will be used aslr_addr
Payload type:
- Currently in the list of payload types -
accept, the supported one is:user
Status
The status of the LoRa add-on component contains the following properties:
Parameters:
| Property | Type | Description | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| number | ID of the LoRa component instance | ||||||||||||||||||||||
| number | Number of bytes sent over LoRa RF channel | ||||||||||||||||||||||
| number | Number of bytes received over LoRa RF channel | ||||||||||||||||||||||
| number | Time in milliseconds of the transmission time in the last 60 minutes | ||||||||||||||||||||||
| number | Number of failed transmissions | ||||||||||||||||||||||
| string | Firmware version | ||||||||||||||||||||||
| object | Provides information if encryption keys are set or not
| ||||||||||||||||||||||
| object | Information about available updates(empty object, if no updates available). This information is automatically updated every 24 hours.
| ||||||||||||||||||||||
| object | Provides details of the active OTA update, if any. See the Note below
| ||||||||||||||||||||||
| array of strings | Informational flags if any. Currently the following flag is supported:
| ||||||||||||||||||||||
| array of strings | Error if any. Currently the following errors are supported:
|
Note:
Object update is presented in the status only during active OTA update.
send_blocked flag depends on bandwidth
| Bandwidth, kHz | 125 | 250 | 500 |
|---|---|---|---|
| Back-off sending period, seconds | 20 | 10 | 10 |
Low power mode: lp_mode
- Low power mode
lp_modecan be activated when:band_planisEU868, andfreqis in range: [869700000,870000000] (sub channel Q), andtxpis in range: [0, 7] - Having low power mode active, transmission is unlimited,
duty_cycle_limitandlimit_reachedwill never be listed
Notifications
This notification is triggered when data is received over LoRa RF, sent by LoRa.SendBytes.
method: "NotifyEvent"Property Type Description datastring
Received data (remark: encoded in 'base64')
rssinumber
RSSI of the received packet
snrnumber
SNR (signal / noise ratio) of the received packet
tsunumber
LoRa add-on uptime in ms
This notification is triggered when data is received over LoRa RF using SheLR, sent by LoRa.Send.
method: "NotifyEvent"Property Type Description datastring
Received data (remark: encoded in 'base64')
senderstring
Sender address
rssinumber
RSSI of the received packet
snrnumber
SNR (signal / noise ratio) of the received packet
tsunumber
LoRa add-on uptime in ms
Example: Notifications Example
Examples
Enable / Disable LoRa Add-on
Enable LoRa Add-on
- Sys.SetConfig HTTP GET Request
- Sys.SetConfig Curl Request
- Sys.SetConfig Mos Request
http://192.168.33.1/rpc/Sys.SetConfig?config={"device":{"addon_type":"LoRa"}}
curl -X POST -d '{"id":1,"method":"Sys.SetConfig","params":{"config":{"device":{"addon_type":"LoRa"}}}}' http://${SHELLY}/rpc
mos --port ${PORT} call Sys.SetConfig '{"config":{"device":{"addon_type":"LoRa"}}}'
Response
- Sys.SetConfig HTTP GET Response
- Sys.SetConfig Curl Response
- Sys.SetConfig Mos Response
{
"restart_required": true
}
{
"id": 1,
"src": "shelly1pmg3-dcda0ce0d36c",
"params": {
"restart_required": true
}
}
{
"restart_required": true
}
Disable LoRa Add-on
- Sys.SetConfig HTTP GET Request
- Sys.SetConfig Curl Request
- Sys.SetConfig Mos Request
http://192.168.33.1/rpc/Sys.SetConfig?config={"device":{"addon_type":null}}
curl -X POST -d '{"id":1,"method":"Sys.SetConfig","params":{"config":{"device":{"addon_type":null}}}}' http://${SHELLY}/rpc
mos --port ${PORT} call Sys.SetConfig '{"config":{"device":{"addon_type":null}}}'
Response
- Sys.SetConfig HTTP GET Response
- Sys.SetConfig Curl Response
- Sys.SetConfig Mos Response
{
"restart_required": true
}
{
"id": 1,
"src": "shelly1pmg3-dcda0ce0d36c",
"params": {
"restart_required": true
}
}
{
"restart_required": true
}
LoRa.SetConfig Example
- LoRa.SetConfig HTTP GET Request
- LoRa.SetConfig Curl Request
- LoRa.SetConfig Mos Request
http://192.168.33.1/rpc/LoRa.SetConfig?id=100&config={"band_plan":"EU868","freq":865000000,"bw":125,"dr":7,"cr":5,"plen":8,"txp":14,"rx_enable":true,"fh":{"enable":false,"freqs":[]},"shelr":{"lr_addr":"000000BA","tx_key_id":2,"key1":null,"key2":"MTIzNDU2Nzg5MEFCQ0RFRg==","key3":"cRIzRJVmd4iZqrvM3e7/AA==","accept":["user"]}}
curl -X POST -d '{"id":1,"method":"LoRa.SetConfig","params":{"id":100,"config":{"band_plan":"EU868","freq":865000000,"bw":125,"dr":7,"cr":5,"plen":8,"txp":14,"rx_enable":true,"fh":{"enable":false,"freqs":[]},"shelr":{"lr_addr":"000000BA","tx_key_id":2,"key1":null,"key2":"MTIzNDU2Nzg5MEFCQ0RFRg==","key3":"cRIzRJVmd4iZqrvM3e7/AA==","accept":["user"]}}}}' http://${SHELLY}/rpc
mos --port ${PORT} call LoRa.SetConfig '{"id":100,"config":{"band_plan":"EU868","freq":865000000,"bw":125,"dr":7,"cr":5,"plen":8,"txp":14,"rx_enable":true,"fh":{"enable":false,"freqs":[]},"shelr":{"lr_addr":"000000BA","tx_key_id":2,"key1":null,"key2":"MTIzNDU2Nzg5MEFCQ0RFRg==","key3":"cRIzRJVmd4iZqrvM3e7/AA==","accept":["user"]}}}'
Response
- LoRa.SetConfig HTTP GET Response
- LoRa.SetConfig Curl Response
- LoRa.SetConfig Mos Response
{
"restart_required": false
}
{
"id": 1,
"src": "shelly1pmg3-dcda0ce0d36c",
"params": {
"restart_required": false
}
}
{
"restart_required": false
}
LoRa.GetConfig Example
- LoRa.GetConfig HTTP GET Request
- LoRa.GetConfig Curl Request
- LoRa.GetConfig Mos Request
http://192.168.33.1/rpc/LoRa.GetConfig?id=100
curl -X POST -d '{"id":1,"method":"LoRa.GetConfig","params":{"id":100}}' http://${SHELLY}/rpc
mos --port ${PORT} call LoRa.GetConfig '{"id":100}'
Response
- LoRa.GetConfig HTTP GET Response
- LoRa.GetConfig Curl Response
- LoRa.GetConfig Mos Response
{
"id": 100,
"band_plan": "EU868",
"freq": 865000000,
"bw": 125,
"dr": 7,
"cr": 5,
"plen": 8,
"txp": 14,
"rx_enable": true,
"fh": {
"enable": false,
"freqs": []
},
"shelr": {
"lr_addr": "000000BA",
"tx_key_id": 2,
"accept": [
"user"
]
}
}
{
"id": 1,
"src": "shelly1pmg3-dcda0ce0d36c",
"params": {
"id": 100,
"band_plan": "EU868",
"freq": 865000000,
"bw": 125,
"dr": 7,
"cr": 5,
"plen": 8,
"txp": 14,
"rx_enable": true,
"fh": {
"enable": false,
"freqs": []
},
"shelr": {
"lr_addr": "000000BA",
"tx_key_id": 2,
"accept": [
"user"
]
}
}
}
{
"id": 100,
"band_plan": "EU868",
"freq": 865000000,
"bw": 125,
"dr": 7,
"cr": 5,
"plen": 8,
"txp": 14,
"rx_enable": true,
"fh": {
"enable": false,
"freqs": []
},
"shelr": {
"lr_addr": "000000BA",
"tx_key_id": 2,
"accept": [
"user"
]
}
}
LoRa.GetStatus Example
- LoRa.GetStatus HTTP GET Request
- LoRa.GetStatus Curl Request
- LoRa.GetStatus Mos Request
http://192.168.33.1/rpc/LoRa.GetStatus?id=100
curl -X POST -d '{"id":1,"method":"LoRa.GetStatus","params":{"id":100}}' http://${SHELLY}/rpc
mos --port ${PORT} call LoRa.GetStatus '{"id":100}'
Response
- LoRa.GetStatus HTTP GET Response
- LoRa.GetStatus Curl Response
- LoRa.GetStatus Mos Response
{
"id": 100,
"bytes_sent": 69280,
"bytes_recd": 44,
"air_time_hr_ms": 893342,
"send_fails": 0,
"fw_version": "1.11.1",
"available_updates": {
"stable": {
"version": "1.11.2"
}
},
"update": {
"progress": 95,
"state": "updating",
"ts": 1739763916.762901
},
"errors": [
"addon_update_required"
]
}
{
"id": 1,
"src": "shelly1pmg3-dcda0ce0d36c",
"params": {
"id": 100,
"bytes_sent": 69280,
"bytes_recd": 44,
"air_time_hr_ms": 893342,
"send_fails": 0,
"fw_version": "1.11.1",
"available_updates": {
"stable": {
"version": "1.11.2"
}
},
"update": {
"progress": 95,
"state": "updating",
"ts": 1739763916.762901
},
"errors": [
"addon_update_required"
]
}
}
{
"id": 100,
"bytes_sent": 69280,
"bytes_recd": 44,
"air_time_hr_ms": 893342,
"send_fails": 0,
"fw_version": "1.11.1",
"available_updates": {
"stable": {
"version": "1.11.2"
}
},
"update": {
"progress": 95,
"state": "updating",
"ts": 1739763916.762901
},
"errors": [
"addon_update_required"
]
}
LoRa.SendBytes Example
- LoRa.SendBytes HTTP GET Request
- LoRa.SendBytes Curl Request
- LoRa.SendBytes Mos Request
http://192.168.33.1/rpc/LoRa.SendBytes?id=100&data="MDEyMzQ1Njc4OQ=="
curl -X POST -d '{"id":1,"method":"LoRa.SendBytes","params":{"id":100,"data":"MDEyMzQ1Njc4OQ=="}}' http://${SHELLY}/rpc
mos --port ${PORT} call LoRa.SendBytes '{"id":100,"data":"MDEyMzQ1Njc4OQ=="}'
Response
- LoRa.SendBytes HTTP GET Response
- LoRa.SendBytes Curl Response
- LoRa.SendBytes Mos Response
null
{
"id": 1,
"src": "shelly1pmg3-dcda0ce0d36c",
"params": null
}
null
LoRa.Send Example
- LoRa.Send HTTP GET Request
- LoRa.Send Curl Request
- LoRa.Send Mos Request
http://192.168.33.1/rpc/LoRa.Send?id=100&lr_addr="00000063"&tx_key="MTIzNDU2Nzg5MEFCQ0RFRg=="&data="MTA="
curl -X POST -d '{"id":1,"method":"LoRa.Send","params":{"id":100,"lr_addr":"00000063","tx_key":"MTIzNDU2Nzg5MEFCQ0RFRg==","data":"MTA="}}' http://${SHELLY}/rpc
mos --port ${PORT} call LoRa.Send '{"id":100,"lr_addr":"00000063","tx_key":"MTIzNDU2Nzg5MEFCQ0RFRg==","data":"MTA="}'
Response
- LoRa.Send HTTP GET Response
- LoRa.Send Curl Response
- LoRa.Send Mos Response
null
{
"id": 1,
"src": "shelly1pmg3-dcda0ce0d36c",
"params": null
}
null
Notifications Example
When data is received over LoRa RF sent by LoRa.SendBytes:
{
"src": "shelly1pmg3-dcda0ce0d36c",
"dst": "user_1",
"method": "NotifyEvent",
"params": {
"ts": 1631266595.43,
"events": [
{
"component": "lora:100",
"id": 100,
"event": "lora",
"ts": 1631266595.43,
"info": {
"data": "MDEyMzQ1Njc4OQ==",
"rssi": -70,
"snr": 8,
"tsu": 16212139809
}
}
]
}
}
When data is received over LoRa RF using SheLR, sent by LoRa.Send:
{
"src": "shelly1pmg3-dcda0ce0d36c",
"dst": "user_1",
"method": "NotifyEvent",
"params": {
"ts": 1631266595.43,
"events": [
{
"component": "lora:100",
"id": 100,
"event": "user_rx",
"ts": 1631266595.43,
"info": {
"data": "MTA=",
"sender": 23,
"rssi": -70,
"snr": 8,
"tsu": 16212139809
}
}
]
}
}