Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added configuration of sensor data uplink payload via LoRaWAN #40

Merged
merged 82 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
6071167
Added 1-Wire temperature sensor function (#31) (#32)
matthias-bs May 16, 2024
be853aa
Added CMD_GET_APP_PAYLOAD_CFG
matthias-bs May 20, 2024
350cfee
Added CMD_GET_APP_PAYLOAD_CFG/CMD_GET_APP_PAYLOAD_CFG
matthias-bs May 20, 2024
cd6ff0e
Added CMD_GET_APP_PAYLOAD_CFG/CMD_GET_APP_PAYLOAD_CFG
matthias-bs May 20, 2024
2057270
Added CMD_GET_APP_PAYLOAD_CFG/CMD_GET_APP_PAYLOAD_CFG
matthias-bs May 20, 2024
b2bf46c
Created
matthias-bs May 20, 2024
a8fb896
Fixed encodeOneWire()
matthias-bs May 20, 2024
cc1098d
Added/fixed comments
matthias-bs May 20, 2024
f755094
Created
matthias-bs May 20, 2024
629ddee
Added definitions for AppLayer payload configuration
matthias-bs May 20, 2024
f5b405e
Fixes
matthias-bs May 21, 2024
927b774
Added UBATT_CH/USUPPLY_CH
matthias-bs May 21, 2024
9cd92b3
Moved USUPPLY_CH
matthias-bs May 21, 2024
9846064
Created
matthias-bs May 21, 2024
612cdb6
Created
matthias-bs May 22, 2024
5d7b9ee
Added encodeWeatherSensor(), added defines for signalling invalid data
matthias-bs May 23, 2024
3435457
Added appPayloadCfgDef, setAppPayloadCfg() & getAppPayloadCfg(), move…
matthias-bs May 24, 2024
6455799
Moved rainGauge, appPrefs and time members from AppLayer into the class
matthias-bs May 24, 2024
f3cf2ed
Moved Weather Sensor and rain gauge/lightning post processing from Ap…
matthias-bs May 24, 2024
7d79d45
Added sensor feature flags
matthias-bs May 24, 2024
49dca01
Added handling of sensor feature flags
matthias-bs May 24, 2024
a081330
Added logging.h
matthias-bs May 24, 2024
54d7369
Removed unused variable
matthias-bs May 24, 2024
fa0b766
Added payload size check, changed bitmap order
matthias-bs May 24, 2024
2f3ae73
Added isSpaceLeft(), payloadSize[] & sensorTypes[]
matthias-bs May 24, 2024
fc42520
Added payload size check, modified log messages, changed bitmap order
matthias-bs May 24, 2024
780a91c
Modified PAYLOAD_SIZE
matthias-bs May 24, 2024
eb1c19f
Moved PAYLOAD_SIZE from BresserWeatherSensorLW.ino
matthias-bs May 24, 2024
fb99798
Disabled target m5stack-core2
matthias-bs May 24, 2024
244ab2e
Created
matthias-bs May 26, 2024
e6ca7bf
Added usage, improved formatting.
matthias-bs May 26, 2024
b6500f6
Added comments
matthias-bs May 26, 2024
e0d2ba9
Update doxygen.yml
matthias-bs May 27, 2024
e79e781
Added generation of uplink decoder parameters
matthias-bs May 27, 2024
abf7ff2
Fixed bug in arrayOutput generation
matthias-bs May 27, 2024
78b050a
Added section "Payload Configuration"
matthias-bs May 28, 2024
df7d0d5
Fixed getMultichannelconfig()
matthias-bs May 28, 2024
724f471
Fixed getWeatherconfig()
matthias-bs May 28, 2024
eaf8981
Moved encoding of invalid values to BresserWeatherSensorLWCmd.h
matthias-bs May 28, 2024
536db85
Fixes
matthias-bs May 28, 2024
db77dbf
Modified sensor data payload decoder
matthias-bs May 28, 2024
55291ab
Added encoding of invalid values, modified default payload, fixes
matthias-bs May 28, 2024
3bd0487
Disabled uplink transmission of LoRaWAN node status flags
matthias-bs May 28, 2024
e26091e
Changesd order of channels, fixed log messages
matthias-bs May 28, 2024
eeddd55
Changed index count direction, fixed signalling of invalid data
matthias-bs May 28, 2024
6448416
Fixed signalling of invalid data
matthias-bs May 28, 2024
50e4f0e
Midified INV_FLOAT
matthias-bs May 28, 2024
e98d47d
Added uint8fp1 for UV index
matthias-bs May 29, 2024
cd08ac3
Fixes
matthias-bs May 29, 2024
dd609c8
Added handling of NaN values, fixed uint8fp1 length
matthias-bs May 29, 2024
76604ec
Disabled Pool/Spa Thermometer
matthias-bs May 29, 2024
6f9396f
Fixed Weather Sensor size calculation
matthias-bs May 29, 2024
1eef93e
Fixed Weather Sensor size calculation
matthias-bs May 29, 2024
32a3ff1
20242529 Fixed payload size calculation
matthias-bs May 29, 2024
1d1f485
Changed enconding of INV_TEMP
matthias-bs May 29, 2024
3647b1d
Changed encoding of INV_TEMP for BLE sensors
matthias-bs May 29, 2024
a187517
Changed encoding of INV_TEMP
matthias-bs May 29, 2024
7366bc6
Modified encoding of INV_FLOAT
matthias-bs May 29, 2024
2529d98
Added BLE sensor configuration
matthias-bs May 30, 2024
2206860
Removed unused onchange="toggleInput(id, this.checked)" properties
matthias-bs May 30, 2024
0a0c058
Added comments
matthias-bs May 30, 2024
f964b73
Added SKIP_INVALID_SIGNALS, added BLE signals to decoder
matthias-bs May 30, 2024
d08956d
Added stateDecode(), updated debug() from RadioLib v6.6.0
matthias-bs May 30, 2024
4d46d66
Updated to RadioLib v6.6.0
matthias-bs May 30, 2024
562db24
Added decoding of CMD_SET_APP_PAYLOAD_CFG
matthias-bs May 30, 2024
4eb135e
Formatting
matthias-bs May 30, 2024
a65fd49
Added missing entries in sensorTypes[]
matthias-bs May 30, 2024
c5dbff5
Fixed CMD_SET_APP_PAYLOAD_CFG handling
matthias-bs May 30, 2024
0043c30
Added decoding of CMD_GET_APP_PAYLOAD_CFG
matthias-bs May 30, 2024
3b1360e
Added BleSensors as base class
matthias-bs May 30, 2024
5c78bfd
Attempt to fix -Wreorder
matthias-bs May 30, 2024
fc920e4
Fixed handling of arrays in decoder()
matthias-bs May 31, 2024
3dc1a63
Update CI.yml
matthias-bs May 31, 2024
075ffcb
Removed BleSensors as base class & from initializers
matthias-bs May 31, 2024
4ff670e
Weather sensor: Fixed encoding of invalid temperature
matthias-bs May 31, 2024
48c7b12
Fixed getLightningconfig()
matthias-bs May 31, 2024
7afc3bc
Minor improvements
matthias-bs May 31, 2024
370037b
Merge branch 'main' into feat-config-payload
matthias-bs May 31, 2024
e63996f
Fixed file header
matthias-bs May 31, 2024
f51c994
Moved from AppLayer.h/.cpp
matthias-bs May 31, 2024
e63d8eb
Moved BLE specific code to PayloadBLE.h/.cpp
matthias-bs May 31, 2024
8997520
Removed dead code, added missing preprocessor directive
matthias-bs May 31, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ jobs:
#- esp32:esp32:heltec_wifi_lora_32_V2
- esp32:esp32:heltec_wifi_lora_32_V3
#- esp32:esp32:featheresp32
- esp32:esp32:m5stack-core2
- esp32:esp32:esp32s3_powerfeather
#- esp32:esp32:m5stack-core2
#- esp32:esp32:esp32s3_powerfeather
- esp32:esp32:adafruit_feather_esp32s2
- rp2040:rp2040:adafruit_feather:dbgport=Serial

Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/doxygen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ jobs:
cat keywords.txt
echo "-----------------------------------------------------------"

- name: Copy confighelper.html
run: |
cp extras/confighelper/confighelper.html docs/html/

- name: Deploy to GitHub Pages
uses: JamesIves/github-pages-deploy-action@releases/v4
with:
Expand Down
107 changes: 67 additions & 40 deletions BresserWeatherSensorLW.ino
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@
// Library dependencies (tested versions):
// ---------------------------------------
// (install via normal Arduino Library installer:)
// RadioLib 6.5.0
// RadioLib 6.6.0
// LoRa_Serialization 3.2.1
// ESP32Time 2.0.6
// BresserWeatherSensorReceiver 0.27.0
// BresserWeatherSensorReceiver 0.28.2
// OneWireNg 0.13.1 (optional)
// DallasTemperature 3.9.0 (optional)
// NimBLE-Arduino 1.4.1 (optional)
// ATC MiThermometer 0.3.1 (optional)
// Theengs Decoder 1.7.2 (optional)
// ATC MiThermometer 0.4.2 (optional)
// Theengs Decoder 1.7.8 (optional)
//
// (installed from ZIP file:)
// DistanceSensor_A02YYUW 1.0.2 (optional)
Expand Down Expand Up @@ -82,9 +82,16 @@
// 20240504 PowerFeather: added BATTERY_CAPACITY_MAH to init()
// Added BresserWeatherSensorLWCmd.h
// 20240505 Implemented loading of LoRaWAN secrets from file on LittleFS (if available)
// 20230524 Modified PAYLOAD_SIZE: Moved define to header file, added small reserve
// to uplinkPayload[], modified actual size in sendReceive()
// 20240528 Disabled uplink transmission of LoRaWAN node status flags
// 20242529 Fixed payload size calculation
// 20240530 Updated to RadioLib v6.6.0
//
// ToDo:
// -
// - Fix restoring nonces/session buffers after examples in
// https://github.com/radiolib-org/radiolib-persistence
// have been updated
//
// Notes:
// - Set "Core Debug Level: Debug" for initial testing
Expand Down Expand Up @@ -167,10 +174,6 @@ using namespace PowerFeather;
// Time zone info
const char *TZ_INFO = TZINFO_STR;

// Uplink message payload size
// The maximum allowed for all data rates is 51 bytes.
const uint8_t PAYLOAD_SIZE = 51;

// Time source & status, see below
//
// bits 0..3 time source
Expand Down Expand Up @@ -746,20 +749,22 @@ void setup()
gotoSleep(sleepDuration());
}

// build payload byte array
uint8_t uplinkPayload[PAYLOAD_SIZE];
// build payload byte array (+ reserve to prevent overflow with configuration at run-time)
uint8_t uplinkPayload[PAYLOAD_SIZE + 8];

LoraEncoder encoder(uplinkPayload);

// LoRaWAN node status flags
encoder.writeBitmap(0,
0,
0,
0,
0,
longSleep,
0,
0);
// Note:
// This should be enabled by a LoRaWAN downlink command if required.
// // LoRaWAN node status flags
// encoder.writeBitmap(0,
// 0,
// 0,
// 0,
// 0,
// longSleep,
// 0,
// 0);

appLayer.getPayloadStage1(1, encoder);

Expand All @@ -785,25 +790,22 @@ void setup()

// recall session from RTC deep-sleep preserved variable
state = node.setBufferSession(LWsession); // send them to LoRaWAN stack

// if we have booted at least once we should have a session to restore, so report any failure
// otherwise no point saying there's been a failure when it was bound to fail with an empty
// LWsession var. At this point, bootCount has already been incremented, hence the > 2
debug((state != RADIOLIB_ERR_NONE) && (bootCount > 2), "Restoring session buffer failed", state, false);

// process the restored session or failing that, create a new one &
// return flag to indicate a fresh join is required
log_d("Setup LoRaWAN session");
state = node.beginOTAA(joinEUI, devEUI, nwkKey, appKey, false);
// see comment above, no need to report a failure that is bound to occur on first boot
debug((state != RADIOLIB_ERR_NONE) && (bootCount > 2), "Restore session failed", state, false);
// Setup the OTAA session information
node.beginOTAA(joinEUI, devEUI, nwkKey, appKey);

// loop until successful join
while (state != RADIOLIB_ERR_NONE)
while ((state != RADIOLIB_LORAWAN_NEW_SESSION) && (state != RADIOLIB_LORAWAN_SESSION_RESTORED))
{
log_d("Join ('login') to the LoRaWAN Network");
state = node.beginOTAA(joinEUI, devEUI, nwkKey, appKey, true);
state = node.activateOTAA();

if (state < RADIOLIB_ERR_NONE)
if ((state != RADIOLIB_LORAWAN_NEW_SESSION) && (state != RADIOLIB_LORAWAN_SESSION_RESTORED))
{
log_d("Join failed: %d", state);

Expand Down Expand Up @@ -874,11 +876,11 @@ void setup()
}

// Retrieve the last uplink frame counter
uint32_t fcntUp = node.getFcntUp();
uint32_t fCntUp = node.getFCntUp();

// Send a confirmed uplink every 64th frame
// and also request the LinkCheck command
if (fcntUp % 64 == 0)
if (fCntUp % 64 == 0)
{
log_i("[LoRaWAN] Requesting LinkCheck");
node.sendMacCommandReq(RADIOLIB_LORAWAN_MAC_LINK_CHECK);
Expand All @@ -896,14 +898,39 @@ void setup()
LoRaWANEvent_t uplinkDetails;
LoRaWANEvent_t downlinkDetails;

// perform an uplink & optionally receive downlink
if (fcntUp % 64 == 0)
uint8_t payloadSize = encoder.getLength();
if (payloadSize > PAYLOAD_SIZE)
{
state = node.sendReceive(uplinkPayload, encoder.getLength(), port, downlinkPayload, &downlinkSize, true, &uplinkDetails, &downlinkDetails);
log_w("Payload size exceeds maximum of %u bytes - truncating", PAYLOAD_SIZE);
payloadSize = PAYLOAD_SIZE;
}

// perform an uplink & optionally receive downlink
if (fCntUp % 64 == 0)
{
state = node.sendReceive(
uplinkPayload,
payloadSize,
port,
downlinkPayload,
&downlinkSize,
true,
&uplinkDetails,
&downlinkDetails
);
}
else
{
state = node.sendReceive(uplinkPayload, encoder.getLength(), port, downlinkPayload, &downlinkSize, false, nullptr, &downlinkDetails);
state = node.sendReceive(
uplinkPayload,
payloadSize,
port,
downlinkPayload,
&downlinkSize,
false,
nullptr,
&downlinkDetails
);
}
debug((state != RADIOLIB_LORAWAN_NO_DOWNLINK) && (state != RADIOLIB_ERR_NONE), "Error in sendReceive", state, false);

Expand All @@ -919,9 +946,9 @@ void setup()
log_i("Downlink data: ");
arrayDump(downlinkPayload, downlinkSize);

if (downlinkDetails.port > 0)
if (downlinkDetails.fPort > 0)
{
uplinkReq = decodeDownlink(downlinkDetails.port, downlinkPayload, downlinkSize);
uplinkReq = decodeDownlink(downlinkDetails.fPort, downlinkPayload, downlinkSize);
}
}
else
Expand All @@ -945,8 +972,8 @@ void setup()
log_d("[LoRaWAN] Datarate:\t%d", downlinkDetails.datarate);
log_d("[LoRaWAN] Frequency:\t%7.3f MHz", downlinkDetails.freq);
log_d("[LoRaWAN] Output power:\t%d dBm", downlinkDetails.power);
log_d("[LoRaWAN] Frame count:\t%u", downlinkDetails.fcnt);
log_d("[LoRaWAN] Port:\t\t%u", downlinkDetails.port);
log_d("[LoRaWAN] Frame count:\t%u", downlinkDetails.fCnt);
log_d("[LoRaWAN] fPort:\t\t%u", downlinkDetails.fPort);
}

uint32_t networkTime = 0;
Expand Down Expand Up @@ -979,7 +1006,7 @@ void setup()
sendCfgUplink(uplinkReq);
}

log_d("FcntUp: %u", node.getFcntUp());
log_d("FcntUp: %u", node.getFCntUp());

// now save session to RTC memory
uint8_t *persist = node.getBufferSession();
Expand Down
Loading
Loading