Skip to content

Commit 75f2b63

Browse files
authored
Merge pull request #36 from gregbreen/stm32-nucleo-wl55jc
GH-31 ST Nucleo-WL55JC binary decoder
2 parents d69fd94 + 0bfa036 commit 75f2b63

File tree

4 files changed

+63
-2
lines changed

4 files changed

+63
-2
lines changed

Diff for: README.md

+2
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ The sample [Decoding binary payloads from LoRaWAN devices](transform_binary_payl
8585
- Adeunis Dry Contacts
8686
- **Weather station**
8787
- MeteoHelix Iot Pro
88+
- **Development Board**
89+
- ST Nucleo-WL55JC
8890

8991
[Contributions](CONTRIBUTING.md) to example binary decoders are welcome.
9092

Diff for: transform_binary_payload/README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ This repository contains resources to quickly onboard included LoRaWAN devices o
2424
- Adeunis Dry Contacts
2525
- Laird Sentrius RS1xx
2626
- MeteoHelix Iot Pro
27+
- ST Nucleo-WL55JC
2728

2829
- AWS Lambda functions in [Python 3](transform_binary_payload/src-iotrule-transformation) and [Node.js](transform_binary_payload/src-iotrule-transformation-node) that will be invoked by the AWS IoT Rule to perform binary decoding
2930

@@ -73,6 +74,7 @@ Example binary decoders for the following devices are included in this sample:
7374
| Adeunis | Dry Contacts | adeunis_dc_v2 | x | |
7475
| Laird | Sentrius RS1xx | sentrius_rs1xx | x | |
7576
| BaraniDesign | MeteoHelix Iot Pro | meteo_helix | x | |
77+
| ST | Nucleo-WL55JC | st_nucleo_wl55jc | x | |
7678

7779

7880
## Approach A: using simulated decoder
@@ -321,6 +323,7 @@ Please perform the following steps to deploy a sample application:
321323
| Adeunis | Dry Contacts | adeunis_dc_v2 | x | |
322324
| Laird | Sentrius RS1xx | sentrius_rs1xx | x | |
323325
| BaraniDesign | MeteoHelix Iot Pro | meteo_helix | x | |
326+
| ST | Nucleo-WL55JC | st_nucleo_wl55jc | x | |
324327

325328
Please note that `sam deploy --guided` should be only executed for a first deployment. To redeploy after that please use `sam deploy`.
326329

@@ -363,6 +366,7 @@ Please perform the following steps to deploy a sample application:
363366
| Adeunis | Dry Contacts | QMAAAQACAAMABKU= |
364367
| Laird | Sentrius RS1xx | AQAeAUEZAgAAAAA= |
365368
| BaraniDesign | MeteoHelix Iot Pro | cScjZ0+jGvrTA/A= |
369+
| ST | Nucleo-WL55JC | ACcQGAH0AAAAAA== |
366370

367371
The payload is structured in a same way as it will be ingested by AWS IoT Core for LoRaWAN. Please replace the `<Sample PayloadData>` with the value of "Sample PayloadData>" from the following table:
368372

@@ -665,7 +669,7 @@ Please perform following steps to implement your own binary transformation model
665669
```
666670
667671
4. Edit `src-iotrule-transformation/app.py` and
668-
1. Add `import mymanufacturer_mydevice.py`
672+
1. Add `import mymanufacturer_mydevice`
669673
2. Add "mymanufacturer_mydevice" value to VALID_PAYLOAD_DECODER_NAMES
670674
671675
5. This sample uses AWS SAM to build and deploy all necessary resources (e.g. AWS Lambda function, AWS IoT Rule, AWS IAM Roles) to your AWS account. Please perform the following commands to build the SAM artifacts:

Diff for: transform_binary_payload/src-iotrule-transformation/app.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
import meteo_helix
5555
import dragino_lsn50
5656
import dragino_llms01
57+
import st_nucleo_wl55jc
5758

5859
# Allowed payload type values. This array will be used for validation of the "type" attribute for a
5960
# handle of a Lambda function. For each value in the list below, you should import a module with the
@@ -68,7 +69,7 @@
6869
"dragino_lht65", "dragino_lgt92", "dragino_lse01", "dragino_lbt1", "dragino_lds01","dragino_laq4",
6970
"dragino_lsn50", "dragino_llms01",
7071
"elsys", "globalsat_lt100", "nas_um3080", "adeunis_ftd2", "adeunis_dc_v2",
71-
"sentrius_rs1xx", "meteo_helix"]
72+
"sentrius_rs1xx", "meteo_helix", "st_nucleo_wl55jc"]
7273

7374
# Function name for logging
7475
FUNCTION_NAME = "ConvertBinaryPayload"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
# SPDX-License-Identifier: MIT-0
3+
#
4+
# Permission is hereby granted, free of charge, to any person obtaining a copy of this
5+
# software and associated documentation files (the "Software"), to deal in the Software
6+
# without restriction, including without limitation the rights to use, copy, modify,
7+
# merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
8+
# permit persons to whom the Software is furnished to do so.
9+
#
10+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
11+
# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
12+
# PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
13+
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
14+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
15+
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
16+
17+
18+
import base64
19+
import time
20+
import math
21+
22+
23+
def dict_from_payload(base64_input: str, fport: int = None):
24+
""" Decodes a base64-encoded binary payload into JSON.
25+
Parameters
26+
----------
27+
base64_input : str
28+
Base64-encoded binary payload
29+
fport: int
30+
FPort as provided in the metadata. Please note the fport is optional and can have value "None", if not provided by the LNS or invoking function.
31+
32+
If fport is None and binary decoder can not proceed because of that, it should should raise an exception.
33+
34+
Returns
35+
-------
36+
JSON object with key/value pairs of decoded attributes
37+
38+
"""
39+
40+
decoded = base64.b64decode(base64_input)
41+
42+
led = "Off" if decoded[0] == 0 else "On"
43+
pressure = int.from_bytes(decoded[1:3], byteorder='big', signed=False) / 10
44+
temperature = int.from_bytes(decoded[3:4], byteorder='big', signed=True)
45+
humidity = int.from_bytes(decoded[4:6], byteorder='big', signed=False) / 10
46+
47+
result = {
48+
"led": led,
49+
"pressure": pressure,
50+
"temperature": temperature,
51+
"humidity": humidity
52+
}
53+
54+
return result

0 commit comments

Comments
 (0)