Skip to content

Commit

Permalink
When EU DR6 aka SF7BW250 choose second channel. Moved NbTrans variabl…
Browse files Browse the repository at this point in the history
…es to public so applcation can know with if NbTrans_counter == NbTrans that we can send new message.
  • Loading branch information
clavisound committed Dec 14, 2024
1 parent dee0ceb commit 9b0ea0c
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 16 deletions.
11 changes: 4 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@

---

![CI](https://github.com/clavisound/SlimLoRa/actions/workflows/main.yml/badge.svg)

# SlimLoRa - Propably the easiest and smallest footprint LoRaWAN library for Arduino library and EU868.

This library is probably the most easy to use LoRaWAN library. The target is LoRaWAN-1.0.3 specification. It supports OTAA / Join, most important MAC commands - like DR, power, NBtrans, downlinks for user application and session is stored to EEPROM. Applications downlinks are limited to maximum of 16 bytes. I think it's more than enough. If you want a complete LoRaWAN library try [Radiolib](https://github.com/jgromes/RadioLib/) (needs around 52kBytes of program flash), or LMIC (around 36kBytes of program flash).
This library is probably the most easy to use LoRaWAN library. The target is LoRaWAN-1.0.3 specification. It supports OTAA / Join, most important MAC commands - like DR, power, NBtrans, downlinks for user application and session is stored to EEPROM. Applications downlinks are static selectable via `#define` in `SlimLoRa.h`. Default is 11 bytes. If you want a complete LoRaWAN library try [Radiolib](https://github.com/jgromes/RadioLib/) (needs around 52kBytes of program flash), or LMIC (around 36kBytes of program flash).

SlimLoRa needs around 12558 Bytes (13kBytes) but it's getting bigger with the support of MAC commands and more LoRaWAN specification to be added. SlimLoRa gives LoRaWAN life to old μCU's like ATmega 328 with 32kBytes of flash.

[SlimLoRa MAC response in MAC command via Helium original console.](https://krg.etraq.eu/minisites/lora/mac-command-response_crop.png)

The majority of the work was done by Hendrik Hagendorn and Ideetron B.V. Thanks to both of them.
The majority of the work was done by Hendrik Hagendorn and Ideetron B.V. Thanks to both of them. I ported the library to Arduino, I expanded the most important MAC commands and enabled downlinks and ACK for confirmed downlinks.

# Working

Expand All @@ -31,7 +28,7 @@ The majority of the work was done by Hendrik Hagendorn and Ideetron B.V. Thanks
- [x] Join SF8 on Helium chripstack outdors. Success on 1st window in second or third attempt.
- [x] Join SF7 on Helium and power 0dBm in different room. Success on 1st window.
- [x] Downlinks
- [x] Helium on 2nd window (SF12) always works.
- [x] Helium on 2nd window (SF12) always works on Chiprstack.
- [x] SetPower
- [x] Deep Sleep
- [x] Restore session from EEPROM (arduino style)
Expand Down Expand Up @@ -74,8 +71,8 @@ Solutions with avr style.
# TODO's (PR's welcome) - In order of importance.

- [ ] Join back-off
- [ ] Confirmed Uplink
- [ ] Extern variable for Duty Cycle if the application can provide time.
- [ ] Confirmed Uplink
- [ ] Make DevNonce random.
- [ ] More regions. Currently only EU868 is working.
- [ ] Add pin mappings infrastucture for other boards.
Expand Down
22 changes: 19 additions & 3 deletions SlimLoRa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -661,9 +661,21 @@ void SlimLoRa::RfmSendPacket(uint8_t *packet, uint8_t packet_length, uint8_t cha
RfmWrite(RFM_REG_INVERT_IQ_2, 0x1D);

// Channel
#if defined(EU_DR6)
// SF7BW250 is only for channel 868.3 - second channel.
if ( dri == SF7BW250 ) {
RfmWrite(RFM_REG_FR_MSB, pgm_read_byte(&(kFrequencyTable[1][0]))); // 1 is second channel
RfmWrite(RFM_REG_FR_MID, pgm_read_byte(&(kFrequencyTable[1][1])));
RfmWrite(RFM_REG_FR_LSB, pgm_read_byte(&(kFrequencyTable[1][2])));

} else {
#endif
RfmWrite(RFM_REG_FR_MSB, pgm_read_byte(&(kFrequencyTable[channel][0])));
RfmWrite(RFM_REG_FR_MID, pgm_read_byte(&(kFrequencyTable[channel][1])));
RfmWrite(RFM_REG_FR_LSB, pgm_read_byte(&(kFrequencyTable[channel][2])));
#if defined(EU_DR6)
}
#endif

// Bandwidth / Coding Rate / Implicit Header Mode
RfmWrite(RFM_REG_MODEM_CONFIG_1, pgm_read_byte(&(kDataRateTable[dri][0])));
Expand Down Expand Up @@ -894,9 +906,8 @@ int8_t SlimLoRa::Join() {
uint16_t dev_nonce;
uint8_t mic[4];

// Reset RX2 DR to network default
// You need this if you can't control the EEPROM.
// rx2_data_rate_ = RX_SECOND_WINDOW;
// Set RX2 DR default
rx2_data_rate_ = SF12BW125;

packet[0] = LORAWAN_MTYPE_JOIN_REQUEST;

Expand Down Expand Up @@ -1987,6 +1998,11 @@ void SlimLoRa::SendData(uint8_t fport, uint8_t *payload, uint8_t payload_length)
#if DEBUG_SLIM == 1
Serial.println(F("\n*SendData"));printMAC();
#endif

// TODO: protect buffer overflow.
// EU: RP p. 28. DR0-2 (SF12-SF10), 51 bytes, DR3 (SF9): 115 bytes, DR4-5 (SF8, SF7): 222 bytes
// We have to also subtract frame options

Transmit(fport, payload, payload_length);

if (ProcessDownlink(1)) {
Expand Down
13 changes: 9 additions & 4 deletions SlimLoRa.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@
// if you you want to save 6 bytes of RAM and you don't need to provision the Duty Cycle
// because you transmitting only on high Data Rates (DR). You save 76 byte of flash memory if you comment this. RAM is the same.
#define COUNT_TX_DURATION 1

// uncomment to save some byte if you don't use SF7BW250. You gain 32 bytes if you comment this
#define EU_DR6 // applicable for EU RU AS CN
// END OF USER DEFINED OPTIONS

// Drift adjustment. Default: 5 works with feather-32u4 TTN and helium at 5 seconds RX delay. Tested with TTN and SF7, SF8, SF9. Tested with Helium at SF10.
Expand Down Expand Up @@ -216,6 +219,8 @@

// LoRaWAN delays in seconds
#define RX_SECOND_WINDOW SF12BW125

// Usefull for ABP devices only. OTAA devices grab RX2 window DR in after join.
#if NETWORK == NET_TTN
#define RX_SECOND_WINDOW SF9BW125
#define LORAWAN_JOIN_ACCEPT_DELAY1_MICROS NET_TTN_RX_DELAY * MICROS_PER_SECOND
Expand Down Expand Up @@ -261,8 +266,8 @@
// LoRaWAN spreading factors
// TODO for other regions. Example: DR0 for US902 is SF10BW125 and DR8 is SF12BW500
// check https://www.thethingsnetwork.org/docs/lorawan/regional-parameters/
#define FSK 7 // TODO
#define SF7BW250 6
#define FSK 7 // TODO only 868.8 Mhz
#define SF7BW250 6 // only 868.3 Mhz
#define SF7BW125 5
#define SF8BW125 4
#define SF9BW125 3
Expand Down Expand Up @@ -299,6 +304,8 @@ class SlimLoRa {
uint16_t tx_frame_counter_ = 0;
uint16_t rx_frame_counter_ = 0;
uint8_t adr_ack_counter_ = 0;
uint8_t NbTrans = NBTRANS; // changed by the LNS or by DEFINE
uint8_t NbTrans_counter; // if NbTrans_counter is the same with NbTrans, send new message
uint8_t pseudo_byte_;
uint8_t tx_power;
uint16_t GetTxFrameCounter();
Expand Down Expand Up @@ -352,8 +359,6 @@ class SlimLoRa {
#endif

uint16_t ChMask;
uint8_t NbTrans = NBTRANS;
uint8_t NbTrans_counter;

static const uint8_t kFrequencyTable[9][3];
static const uint8_t kDataRateTable[7][3];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ void setup() {

lora.Begin();
lora.SetDataRate(SF7BW125);
//lora.SetDataRate(SF7BW250); // Testing, ignore this.
lora.SetPower(txPower);
lora.SetAdrEnabled(1); // 0 to disable. Network can still send ADR command to device. This is preference, not an order.

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": "SlimLoRa",
"version": "0.6.6",
"version": "0.6.7",
"description": "LoRaWAN library with OTAA join, ADR support and most important MAC commands for EU868 suitable for AVR's with 32Kbytes. It uses 14kBytes of program flash instead of 52kBytes of RadioLib or 32kBytes of LMIC. Tested avr32u4 / ATmega32u4 and HopeRF 95w (SX1276) on Adafruit Feather. ABP untested. Session is stored to EEPROM. Testers wanted and PR's for other regions. It supports downlinks.",
"keywords": "LoRaWAN, rfm95w, hoperf, SX1276, radio, communication",
"repository":
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.6
version=0.6.7
author=clavisound
maintainer=clavisound
sentence=SlimLoRa Library
Expand Down

0 comments on commit 9b0ea0c

Please sign in to comment.