From 7b63be09c18b4e62111468fd549cb639bf654bfb Mon Sep 17 00:00:00 2001 From: beegee-tokyo Date: Tue, 16 May 2023 15:56:55 +0800 Subject: [PATCH] Add new CayenneLPP type for device ID (for Hummingbird PoC) --- CHANGELOG.md | 2 ++ README.md | 2 ++ library.json | 2 +- library.properties | 2 +- src/wisblock_cayenne.cpp | 44 +++++++++++++++++++++++++++++++++++----- src/wisblock_cayenne.h | 4 ++++ 6 files changed, 49 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8528459..cb2cdd7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ Arduino library for RAKWireless WisBlock Core modules that takes all the LoRaWAN # Release Notes +## 2.0.7 Add new CayenneLPP type for device ID (for Hummingbird PoC) + ## 2.0.6 Some clean-up and improvement (e.g. no hang if LoRa init fails) ## 2.0.5 Fix new AT command diff --git a/README.md b/README.md index 8b94968..47f1a9c 100644 --- a/README.md +++ b/README.md @@ -1215,6 +1215,8 @@ AT Command functions: Taylor Lee (taylor.lee@rakwireless.com) ---- # Changelog [Code releases](CHANGELOG.md) +- 2023-05-16 + - Add new CayenneLPP type for device ID (for Hummingbird PoC) - 2023-05-15 - Some clean-up and improvement (e.g. no hang if LoRa init fails) - 2023-04-30 diff --git a/library.json b/library.json index e6cd710..91f6a01 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "WisBlock-API-V2", - "version": "2.0.6", + "version": "2.0.7", "keywords": [ "lora", "Semtech", diff --git a/library.properties b/library.properties index 91ea1bc..1f0e5bd 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=WisBlock-API-V2 -version=2.0.6 +version=2.0.7 author=Bernd Giesecke maintainer=Bernd Giesecke sentence=API for WisBlock Core module diff --git a/src/wisblock_cayenne.cpp b/src/wisblock_cayenne.cpp index 449b856..73c44f9 100644 --- a/src/wisblock_cayenne.cpp +++ b/src/wisblock_cayenne.cpp @@ -16,8 +16,8 @@ union int_union_s uint16_t val16 = 0; uint8_t val8[2]; }; -/** Latitude/Longitude value union */ -union latLong_s +/** 32bit value union */ +union long_union_s { int32_t val32; int8_t val8[4]; @@ -43,7 +43,7 @@ uint8_t WisCayenne::addGNSS_4(uint8_t channel, int32_t latitude, int32_t longitu _buffer[_cursor++] = channel; _buffer[_cursor++] = LPP_GPS4; - latLong_s pos_union; + long_union_s pos_union; // Save default Cayenne LPP precision pos_union.val32 = latitude / 1000; // Cayenne LPP 0.0001 ° Signed MSB @@ -86,7 +86,7 @@ uint8_t WisCayenne::addGNSS_6(uint8_t channel, int32_t latitude, int32_t longitu _buffer[_cursor++] = channel; _buffer[_cursor++] = LPP_GPS6; - latLong_s pos_union; + long_union_s pos_union; pos_union.val32 = latitude / 10; // Custom 0.000001 ° Signed MSB _buffer[_cursor++] = pos_union.val8[3]; @@ -129,7 +129,7 @@ uint8_t WisCayenne::addGNSS_H(int32_t latitude, int32_t longitude, int16_t altit return 0; } - latLong_s pos_union; + long_union_s pos_union; pos_union.val32 = latitude / 100; // Custom 0.00001 ° Signed MSB _buffer[_cursor++] = pos_union.val8[0]; @@ -279,6 +279,14 @@ uint8_t WisCayenne::addVoc_index(uint8_t channel, uint32_t voc_index) return _cursor; } +/** + * @brief Add SensorHub values to the payload + * + * @param channel LPP channel + * @param data_type LPP data type + * @param value Sensor value + * @return uint8_t bytes added to the data packet + */ uint8_t WisCayenne::addSH_2_value(uint8_t channel, uint8_t data_type, float value) { // check buffer overflow @@ -317,5 +325,31 @@ uint8_t WisCayenne::addSH_2_value(uint8_t channel, uint8_t data_type, float valu _buffer[_cursor++] = value_union.val8[1]; _buffer[_cursor++] = value_union.val8[0]; + return _cursor; +} + +/** + * @brief Add device ID to payload + * + * @param channel LPP channel + * @param dev_id pointer to 4 byte long array with the device ID + * @return uint8_t bytes added to the data packet + */ +uint8_t WisCayenne::addDevID(uint8_t channel, uint8_t *dev_id) +{ + // check buffer overflow + if ((_cursor + WB_DEV_ID_SIZE + 2) > _maxsize) + { + _error = LPP_ERROR_OVERFLOW; + return 0; + } + _buffer[_cursor++] = channel; + _buffer[_cursor++] = WB_DEV_ID; + + _buffer[_cursor++] = dev_id[0]; + _buffer[_cursor++] = dev_id[1]; + _buffer[_cursor++] = dev_id[2]; + _buffer[_cursor++] = dev_id[3]; + return _cursor; } \ No newline at end of file diff --git a/src/wisblock_cayenne.h b/src/wisblock_cayenne.h index 30ce7b6..e35a504 100644 --- a/src/wisblock_cayenne.h +++ b/src/wisblock_cayenne.h @@ -16,6 +16,7 @@ #include // Additional value ID's +#define WB_DEV_ID 255 // 4 byte device ID #define LPP_GPS4 136 // 3 byte lon/lat 0.0001 °, 3 bytes alt 0.01 meter (Cayenne LPP default) #define LPP_GPS6 137 // 4 byte lon/lat 0.000001 °, 3 bytes alt 0.01 meter (Customized Cayenne LPP) #define LPP_VOC 138 // 2 byte VOC index @@ -36,8 +37,10 @@ #define LPP_GPST_SIZE 10 #define LPP_VOC_SIZE 2 #define SH_SIZE_2 2 +#define WB_DEV_ID_SIZE 4 // Cayenne LPP Channel numbers per sensor value used in WisBlock API examples +#define LPP_CHANNEL_DEVID 0 // Device ID, only used in LoRa P2P #define LPP_CHANNEL_BATT 1 // Base Board #define LPP_CHANNEL_HUMID 2 // RAK1901 #define LPP_CHANNEL_TEMP 3 // RAK1901 @@ -109,6 +112,7 @@ class WisCayenne : public CayenneLPP uint8_t addGNSS_T(int32_t latitude, int32_t longitude, int16_t altitude, float accuracy, int8_t sats); uint8_t addVoc_index(uint8_t channel, uint32_t voc_index); uint8_t addSH_2_value(uint8_t channel, uint8_t data_type, float value); + uint8_t addDevID(uint8_t channel, uint8_t *dev_id); private: };