Skip to content

Commit

Permalink
Add new CayenneLPP type for device ID
Browse files Browse the repository at this point in the history
(for Hummingbird PoC)
  • Loading branch information
beegee-tokyo committed May 16, 2023
1 parent 3f3d876 commit 7b63be0
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1215,6 +1215,8 @@ AT Command functions: Taylor Lee ([email protected])
----
# 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
Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "WisBlock-API-V2",
"version": "2.0.6",
"version": "2.0.7",
"keywords": [
"lora",
"Semtech",
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=WisBlock-API-V2
version=2.0.6
version=2.0.7
author=Bernd Giesecke <[email protected]>
maintainer=Bernd Giesecke <[email protected]>
sentence=API for WisBlock Core module
Expand Down
44 changes: 39 additions & 5 deletions src/wisblock_cayenne.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
4 changes: 4 additions & 0 deletions src/wisblock_cayenne.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <CayenneLPP.h>

// 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
Expand All @@ -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
Expand Down Expand Up @@ -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:
};
Expand Down

0 comments on commit 7b63be0

Please sign in to comment.