Skip to content

Commit

Permalink
More platformio corrections and better place for ack_ reset.
Browse files Browse the repository at this point in the history
  • Loading branch information
clavisound committed Dec 8, 2024
1 parent f4b519d commit 82f0312
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 28 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ The majority of the work was done by Hendrik Hagendorn and Ideetron B.V. Thanks
- [x] Deep Sleep
- [x] Restore session from EEPROM (arduino style)
- [x] Downlink for application.
- [x] Confirmed Downlink
- [x] Sends ACK to confirmed Downlink.
- [x] NbTrans - edit SlimLoRa.h to config.
- [x] Most important MAC commands - more to follow
- [x] Session saved to EEPROM. You only need to join once on the lifetime of the device.
Expand Down
40 changes: 18 additions & 22 deletions SlimLoRa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -711,8 +711,9 @@ void SlimLoRa::RfmSendPacket(uint8_t *packet, uint8_t packet_length, uint8_t cha

#if COUNT_TX_DURATION == 1
// EVAL: maybe this is breaking timing.
// Works with SF7 JOIN and TTN GW in same room and initial delay of 5s
// Works with SF8 JOIN and Helium GW in outdoors and initial delay of 5s
// Works with SF7 JOIN TTN GW in same room delay of 5s
// Works with SF8 JOIN Helium GW in outdoors delay of 5s
// Works with SF7 downlinks Helium GW in same room delay 2s - RX2 window
slimEndTXtimestamp = millis();
#endif

Expand All @@ -722,7 +723,7 @@ void SlimLoRa::RfmSendPacket(uint8_t *packet, uint8_t packet_length, uint8_t cha
// Switch RFM to sleep
RfmWrite(RFM_REG_OP_MODE, 0x00);

// BUG: this is not needed when Join. But Join calls this RfmSendPacket
// BUG: this is not needed when Join. But Join calls this RfmSendPacket function
// NbTrans controls the fCnt
if ( NbTrans_counter > 0 ) {
NbTrans_counter--;
Expand Down Expand Up @@ -1263,7 +1264,8 @@ int8_t SlimLoRa::ProcessJoinAccept(uint8_t window) {
#if DEBUG_SLIM == 1
if ( result == 0 ) {
Serial.print(F("\nPacket Length: "));Serial.println(packet_length);
Serial.print(F("\nJoined on window: "));Serial.println(window);printMAC();
Serial.print(F("\nJoined on window: "));Serial.println(window);
printMAC();
}
#endif

Expand All @@ -1283,13 +1285,6 @@ int8_t SlimLoRa::ProcessJoinAccept(uint8_t window) {
void SlimLoRa::ProcessFrameOptions(uint8_t *options, uint8_t f_options_length) {
uint8_t status, new_rx1_dr_offset, new_rx2_dr; // new_rx2_dr is also used as a temp value

// No I already made the check
/*
if (f_options_length == 0) {
return;
}
*/

for (uint8_t i = 0; i < f_options_length; i++) {

#if DEBUG_SLIM == 1
Expand Down Expand Up @@ -1551,8 +1546,9 @@ void SlimLoRa::ProcessFrameOptions(uint8_t *options, uint8_t f_options_length) {
*/
int8_t SlimLoRa::ProcessDownlink(uint8_t window) {
// start fresh
downlinkSize = 0;
downPort = 0;
downlinkSize = 0;
downPort = 0;
ack_ = 0;

int8_t result;
uint8_t rx1_offset_dr;
Expand Down Expand Up @@ -1602,7 +1598,7 @@ int8_t SlimLoRa::ProcessDownlink(uint8_t window) {
goto end;
}

// We have to ACK that we received the downlink
// Mark ack_ as true so the next uplink we will have ACK enabled.
if (packet[0] == LORAWAN_MTYPE_CONFIRMED_DATA_DOWN) {
ack_ = true;
}
Expand Down Expand Up @@ -1728,6 +1724,7 @@ int8_t SlimLoRa::ProcessDownlink(uint8_t window) {
#if DEBUG_SLIM == 1
if ( downlinkSize > 0 ) {
Serial.print(F("\nDownlinkData"));printHex(downlinkData, downlinkSize);
//printMAC();
}
#endif
}
Expand Down Expand Up @@ -1760,6 +1757,7 @@ int8_t SlimLoRa::ProcessDownlink(uint8_t window) {
} else {
Serial.print(F("Window 2, rx2_DR: "));Serial.println(rx2_data_rate_);
}
printMAC();
Serial.flush();
#if LORAWAN_OTAA_ENABLED
Serial.print(F("\nDevAddr after RX windows: "));printHex(dev_addr, 4);
Expand Down Expand Up @@ -1834,8 +1832,6 @@ void SlimLoRa::Transmit(uint8_t fport, uint8_t *payload, uint8_t payload_length)
// if we received a confirmed downlink respond with ACK
if ( ack_ == true ) {
packet[packet_length] |= LORAWAN_FCTRL_ACK;
// reset so we will have to re-enable ACK if downlink wants it.
ack_ == false;
}

packet[packet_length++] |= pending_fopts_.length + sticky_fopts_.length;
Expand Down Expand Up @@ -2640,18 +2636,18 @@ uint8_t SlimLoRa::GetRx2DataRate() {
if (value == 0x0F) { // probably erased EEPROM.
#if LORAWAN_OTAA_ENABLED
return SF12BW125; // default LORAWAN 1.0.3
#if NETWORK == 'NET_TTN' // TTN
#if NETWORK == NET_TTN // TTN
return SF9BW125;
#endif
#if NETWORK == 'NET_HLM' // Helium
#if NETWORK == NET_HLM // Helium
return SF12BW125;
#endif
#else // ABP settings
return SF12BW125; // default LORAWAN 1.0.3
#if NETWORK == 'NET_TTN' // TTN
#if NETWORK == NET_TTN // TTN
return SF9BW125;
#endif
#if NETWORK == 'NET_HLM' // Helium
#if NETWORK == NET_HLM // Helium
return SF12BW125;
#endif
#endif // LORAWAN_OTAA_ENABLED
Expand All @@ -2674,11 +2670,11 @@ uint8_t SlimLoRa::GetRx1Delay() {
uint8_t value;
value = EEPROM.read(EEPROM_RX_DELAY) >> 4; // shared byte with EEPROM_RX2_DATARATE
if ( value == 0 || value >= 0xF ) { // probably erased EEPROM
#if NETWORK == 'NET_TTN'
#if NETWORK == NET_TTN
value = NET_TTN_RX_DELAY; // default for TTN
#endif

#if NETWORK == 'NET_HELIUM'
#if NETWORK == NET_HELIUM
value = NET_HELIUM_RX_DELAY; // default for Helium
#endif
}
Expand Down
6 changes: 3 additions & 3 deletions SlimLoRa.h
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ class SlimLoRa {
void SetPower(uint8_t power);
bool GetHasJoined();
void GetDevAddr(uint8_t *dev_addr);
bool adr_enabled_ = true;
bool adr_enabled_ = true;
uint8_t data_rate_ = SF7BW125;
uint16_t tx_frame_counter_ = 0;
uint16_t rx_frame_counter_ = 0;
Expand Down Expand Up @@ -338,8 +338,8 @@ class SlimLoRa {
uint8_t rx1_data_rate_offset_ = 0;
uint8_t rx2_data_rate_ = RX_SECOND_WINDOW;
uint32_t rx1_delay_micros_;
bool has_joined_ = false;
bool ack_ = false;
bool has_joined_ = false;
bool ack_ = false;
fopts_t pending_fopts_ = {0};
fopts_t sticky_fopts_ = {0};
uint8_t rx_symbols_ = LORAWAN_RX_MIN_SYMBOLS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* This sketch joins and sends the battery level every 5 minutes.
* It accepts downlinks to change this interval.
*
* Send a downlink to port 1 with range of 0-255
* Send a downlink to port 1 with a value range of 0-255
*
* You need
* To be in Europe! **Only EU868 region**. Sorry. Please feel free
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=SlimLoRa
version=0.6.0
version=0.6.1
author=clavisound
maintainer=clavisound
sentence=SlimLoRa Library
Expand Down

0 comments on commit 82f0312

Please sign in to comment.