diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index 59a3d7d..0000000 Binary files a/.DS_Store and /dev/null differ diff --git a/.gitignore b/.gitignore index e6be95d..08c1e24 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ -*/.DS_Store - .DS_Store \ No newline at end of file +.DS_Store +tools/* diff --git a/README.md b/README.md index ab77242..ae4b8da 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ # AWS IoT Core for LoRaWAN sample applications + AWS IoT Core for LoRaWAN enables you to set up a private LoRaWAN network by connecting your devices and gateways with no LoRaWAN Network Server setup required. This repository contains resources to quickly get started developing solutions using AWS IoT Core for LoRaWAN. It includes samples for typical design patterns ([binary decoder](transform_binary_payload), [downlink messaging](send_downlink_payload), [Thing shadow update](iotthingshadow)) and fully functional applications ([dashboards](timestream), [condition monitoring and alarming](soilmoisture_alarming)). Please consider our [developer guide](https://docs.aws.amazon.com/iot/latest/developerguide/connect-iot-lorawan.html) to learn how to connect your wireless devices and gateways to AWS IoT Core for LoRaWAN. @@ -24,6 +25,7 @@ Please consider our [developer guide](https://docs.aws.amazon.com/iot/latest/dev ## Getting help + - [API Reference](http://docs.aws.amazon.com/console/iot/wireless/intro/apiref) - [Developer guide](http://docs.aws.amazon.com/console/iot/wireless/intro/devguide) - [FAQs](https://aws.amazon.com/iot-core/faqs/#AWS_IoT_Core_for_LoRaWAN) diff --git a/soilmoisture_alarming/images/.DS_Store b/soilmoisture_alarming/images/.DS_Store deleted file mode 100644 index 230426a..0000000 Binary files a/soilmoisture_alarming/images/.DS_Store and /dev/null differ diff --git a/timestream/images/.DS_Store b/timestream/images/.DS_Store deleted file mode 100644 index 1042ae2..0000000 Binary files a/timestream/images/.DS_Store and /dev/null differ diff --git a/transform_binary_payload/src-payload-decoders/python/dragino_lht65.py b/transform_binary_payload/src-payload-decoders/python/dragino_lht65.py new file mode 100644 index 0000000..9180788 --- /dev/null +++ b/transform_binary_payload/src-payload-decoders/python/dragino_lht65.py @@ -0,0 +1,105 @@ +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +# SPDX-License-Identifier: MIT-0 +# +# Permission is hereby granted, free of charge, to any person obtaining a copy of this +# software and associated documentation files (the "Software"), to deal in the Software +# without restriction, including without limitation the rights to use, copy, modify, +# merge, publish, distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +# PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + +import base64 + + +def dict_from_payload(base64_input: str): + + decoded = base64.b64decode(base64_input) + + # Batter status flag + # 00(b): Ultra Low ( BAT <= 2.50v) + # 01(b): Low (2.50v <=BAT <= 2.55v) + # 10(b): OK Good (2.55v <= BAT <=2.65v) + # 11(b): Good (BAT >= 2.65v) + battery_status_flag = (decoded[0] & 0b11000000) >> 6 + battery_status = "unknown" + if battery_status_flag == 0b00: + battery_status = "very low" + elif battery_status_flag == 0b01: + battery_status = "low" + elif battery_status_flag == 0b10: + battery_status = "OK" + elif battery_status_flag == 0b11: + battery_status = "Good" + + # Battery voltage + battery_value = ((decoded[0] << 8 | decoded[1]) & 0x3FFF) / 1000 + + # Internal sensor temperature + if (decoded[2] & 0b1000000): + internal_temperature = ((decoded[2] << 8 | decoded[3]) - 0xFFFF)/100 + else: + internal_temperature = (decoded[2] << 8 | decoded[3])/100 + + # Humidity + humidity = ((decoded[4] << 8 | decoded[5])/10) + + # External sensor temperature + if (decoded[7] & 0b1000000): + external_temperature = ( + ((decoded[7] << 8 | decoded[8]) - 0xFFFF) / 100) + else: + external_temperature = ((decoded[7] << 8 | decoded[8]) / 100) + + result = { + "battery_status": battery_status, + "battery_value": battery_value, + "temperature_internal": internal_temperature, + "humidity": humidity, + "temperature_external": external_temperature + } + + return result + + +# Tests +if __name__ == "__main__": + test_definition = [ + { + "input": "CBF60B0D0376010ADD7FFF", + "output": { + "battery_status": "Good", + "battery_value": 3.062, + "temperature_internal": 28.29, + "humidity": 88.6, + "temperature_external": 27.81 + + } + }, + { + "input": "CBBDF5C6022E01F54F7FFF", + "output": { + "battery_status": "Good", + "battery_value": 3.005, + "temperature_internal": -26.17, + "humidity": 55.8, + "temperature_external": -27.36 + + } + } + ] + + for test in test_definition: + base64_input = base64.b64encode( + bytearray.fromhex(test.get("input"))).decode("utf-8") + output = dict_from_payload(base64_input) + for key in test.get("output"): + if(test.get("output").get(key) != output.get(key)): + raise Exception( + f'Assertion failed for input {test.get("input")}, key {key}, expected {test.get("output").get(key)}, got {output.get(key)} ')