Skip to content

Commit 9b0ea0c

Browse files
committed
When EU DR6 aka SF7BW250 choose second channel. Moved NbTrans variables to public so applcation can know with if NbTrans_counter == NbTrans that we can send new message.
1 parent dee0ceb commit 9b0ea0c

File tree

6 files changed

+35
-16
lines changed

6 files changed

+35
-16
lines changed

README.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
1-
2-
---
3-
41
![CI](https://github.com/clavisound/SlimLoRa/actions/workflows/main.yml/badge.svg)
52

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

8-
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).
5+
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).
96

107
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.
118

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

14-
The majority of the work was done by Hendrik Hagendorn and Ideetron B.V. Thanks to both of them.
11+
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.
1512

1613
# Working
1714

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

7673
- [ ] Join back-off
77-
- [ ] Confirmed Uplink
7874
- [ ] Extern variable for Duty Cycle if the application can provide time.
75+
- [ ] Confirmed Uplink
7976
- [ ] Make DevNonce random.
8077
- [ ] More regions. Currently only EU868 is working.
8178
- [ ] Add pin mappings infrastucture for other boards.

SlimLoRa.cpp

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -661,9 +661,21 @@ void SlimLoRa::RfmSendPacket(uint8_t *packet, uint8_t packet_length, uint8_t cha
661661
RfmWrite(RFM_REG_INVERT_IQ_2, 0x1D);
662662

663663
// Channel
664+
#if defined(EU_DR6)
665+
// SF7BW250 is only for channel 868.3 - second channel.
666+
if ( dri == SF7BW250 ) {
667+
RfmWrite(RFM_REG_FR_MSB, pgm_read_byte(&(kFrequencyTable[1][0]))); // 1 is second channel
668+
RfmWrite(RFM_REG_FR_MID, pgm_read_byte(&(kFrequencyTable[1][1])));
669+
RfmWrite(RFM_REG_FR_LSB, pgm_read_byte(&(kFrequencyTable[1][2])));
670+
671+
} else {
672+
#endif
664673
RfmWrite(RFM_REG_FR_MSB, pgm_read_byte(&(kFrequencyTable[channel][0])));
665674
RfmWrite(RFM_REG_FR_MID, pgm_read_byte(&(kFrequencyTable[channel][1])));
666675
RfmWrite(RFM_REG_FR_LSB, pgm_read_byte(&(kFrequencyTable[channel][2])));
676+
#if defined(EU_DR6)
677+
}
678+
#endif
667679

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

897-
// Reset RX2 DR to network default
898-
// You need this if you can't control the EEPROM.
899-
// rx2_data_rate_ = RX_SECOND_WINDOW;
909+
// Set RX2 DR default
910+
rx2_data_rate_ = SF12BW125;
900911

901912
packet[0] = LORAWAN_MTYPE_JOIN_REQUEST;
902913

@@ -1987,6 +1998,11 @@ void SlimLoRa::SendData(uint8_t fport, uint8_t *payload, uint8_t payload_length)
19871998
#if DEBUG_SLIM == 1
19881999
Serial.println(F("\n*SendData"));printMAC();
19892000
#endif
2001+
2002+
// TODO: protect buffer overflow.
2003+
// EU: RP p. 28. DR0-2 (SF12-SF10), 51 bytes, DR3 (SF9): 115 bytes, DR4-5 (SF8, SF7): 222 bytes
2004+
// We have to also subtract frame options
2005+
19902006
Transmit(fport, payload, payload_length);
19912007

19922008
if (ProcessDownlink(1)) {

SlimLoRa.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@
6464
// if you you want to save 6 bytes of RAM and you don't need to provision the Duty Cycle
6565
// because you transmitting only on high Data Rates (DR). You save 76 byte of flash memory if you comment this. RAM is the same.
6666
#define COUNT_TX_DURATION 1
67+
68+
// uncomment to save some byte if you don't use SF7BW250. You gain 32 bytes if you comment this
69+
#define EU_DR6 // applicable for EU RU AS CN
6770
// END OF USER DEFINED OPTIONS
6871

6972
// 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.
@@ -216,6 +219,8 @@
216219

217220
// LoRaWAN delays in seconds
218221
#define RX_SECOND_WINDOW SF12BW125
222+
223+
// Usefull for ABP devices only. OTAA devices grab RX2 window DR in after join.
219224
#if NETWORK == NET_TTN
220225
#define RX_SECOND_WINDOW SF9BW125
221226
#define LORAWAN_JOIN_ACCEPT_DELAY1_MICROS NET_TTN_RX_DELAY * MICROS_PER_SECOND
@@ -261,8 +266,8 @@
261266
// LoRaWAN spreading factors
262267
// TODO for other regions. Example: DR0 for US902 is SF10BW125 and DR8 is SF12BW500
263268
// check https://www.thethingsnetwork.org/docs/lorawan/regional-parameters/
264-
#define FSK 7 // TODO
265-
#define SF7BW250 6
269+
#define FSK 7 // TODO only 868.8 Mhz
270+
#define SF7BW250 6 // only 868.3 Mhz
266271
#define SF7BW125 5
267272
#define SF8BW125 4
268273
#define SF9BW125 3
@@ -299,6 +304,8 @@ class SlimLoRa {
299304
uint16_t tx_frame_counter_ = 0;
300305
uint16_t rx_frame_counter_ = 0;
301306
uint8_t adr_ack_counter_ = 0;
307+
uint8_t NbTrans = NBTRANS; // changed by the LNS or by DEFINE
308+
uint8_t NbTrans_counter; // if NbTrans_counter is the same with NbTrans, send new message
302309
uint8_t pseudo_byte_;
303310
uint8_t tx_power;
304311
uint16_t GetTxFrameCounter();
@@ -352,8 +359,6 @@ class SlimLoRa {
352359
#endif
353360

354361
uint16_t ChMask;
355-
uint8_t NbTrans = NBTRANS;
356-
uint8_t NbTrans_counter;
357362

358363
static const uint8_t kFrequencyTable[9][3];
359364
static const uint8_t kDataRateTable[7][3];

examples/SlimLoRa-feather32u4-battery-complicated/SlimLoRa-feather32u4-battery-complicated.ino

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ void setup() {
5656

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

library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "SlimLoRa",
3-
"version": "0.6.6",
3+
"version": "0.6.7",
44
"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.",
55
"keywords": "LoRaWAN, rfm95w, hoperf, SX1276, radio, communication",
66
"repository":

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=SlimLoRa
2-
version=0.6.6
2+
version=0.6.7
33
author=clavisound
44
maintainer=clavisound
55
sentence=SlimLoRa Library

0 commit comments

Comments
 (0)