Skip to content

Commit

Permalink
Changed sendCfgUplink() to encodeCfgUplink()
Browse files Browse the repository at this point in the history
  • Loading branch information
matthias-bs committed Sep 22, 2024
1 parent 7973a7b commit 2323358
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
17 changes: 9 additions & 8 deletions BresserWeatherSensorLWCmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
// 20240729 Added PowerFeather specific status information
// 20240818 Replaced delay() with light sleep for ESP32
// 20240829 Added missing implementation of CMD_SET_LW_STATUS_INTERVAL
// 20240920 Changed sendCfgUplink() to encodeCfgUplink()
//
// ToDo:
// -
Expand Down Expand Up @@ -162,13 +163,12 @@ uint8_t decodeDownlink(uint8_t port, uint8_t *payload, size_t size)
}


// Send configuration uplink
void sendCfgUplink(uint8_t uplinkReq, uint32_t uplinkInterval)
// Encode configuration/status uplink
void encodeCfgUplink(uint8_t port, uint8_t *uplinkPayload, uint8_t &payloadSize, uint32_t uplinkInterval)
{
log_d("--- Uplink Configuration/Status ---");

uint8_t uplinkPayload[48];
uint8_t port = uplinkReq;
uint8_t uplinkReq = port;

//
// Encode data as byte array for LoRaWAN transmission
Expand Down Expand Up @@ -309,14 +309,15 @@ void sendCfgUplink(uint8_t uplinkReq, uint32_t uplinkInterval)
uint32_t interval = node.timeUntilUplink(); // calculate minimum duty cycle delay (per FUP & law!)
uint32_t delayMs = max(interval, minimumDelay); // cannot send faster than duty cycle allows

log_d("Sending configuration uplink in %u s", delayMs / 1000);
log_d("Sending uplink in %u s", delayMs / 1000);
#if defined(ESP32)
esp_sleep_enable_timer_wakeup(delayMs * 1000);
esp_light_sleep_start();
#else
delay(delayMs);
#endif
log_d("Sending configuration uplink now.");
int16_t state = node.sendReceive(uplinkPayload, encoder.getLength(), port);
debug((state != RADIOLIB_LORAWAN_NO_DOWNLINK) && (state != RADIOLIB_ERR_NONE), "Error in sendReceive", state, false);
//log_d("Sending configuration uplink now.");
payloadSize = encoder.getLength();
//int16_t state = node.sendReceive(uplinkPayload, encoder.getLength(), port);
//debug((state != RADIOLIB_LORAWAN_NO_DOWNLINK) && (state != RADIOLIB_ERR_NONE), "Error in sendReceive", state, false);
}
10 changes: 7 additions & 3 deletions BresserWeatherSensorLWCmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
// 20240716 Added CMD_SCAN_SENSORS
// 20240722 Added CMD_SET_LW_STATUS_INTERVAL, renamed
// CMD_<GET|SET>_STATUS_INTERVAL to CMD_<GET|SET>_APP_STATUS_INTERVAL
// 20240920 Changed sendCfgUplink() to encodeCfgUplink()
//
// ToDo:
// -
Expand Down Expand Up @@ -469,10 +470,13 @@
uint8_t decodeDownlink(uint8_t port, uint8_t *payload, size_t size);

/*!
* \brief Send configuration uplink
* \brief Encode configuration uplink
*
* \param uplinkRequest command ID of uplink request
* \param port uplink request port
* \param uplinkPayload uplink payload
* \param payloadSize uplink payload size in bytes
* \param uplinkInterval uplink interval in seconds
*/
void sendCfgUplink(uint8_t uplinkReq, uint32_t uplinkInterval);
void encodeCfgUplink(uint8_t port, uint8_t *uplinkPayload, uint8_t &payloadSize, uint32_t uplinkInterval);

#endif

0 comments on commit 2323358

Please sign in to comment.