Got examples/join working

This commit is contained in:
Wolfgang Klenk 2017-04-12 21:50:17 +02:00
parent fab63d4796
commit baf7df4a54
4 changed files with 2305 additions and 6 deletions

View File

@ -1,7 +1,6 @@
# lmic-rpi-lora-gps-hat # lmic-rpi-lora-gps-hat
# 2017-04-12 WORK UNDER CONSTRUCTION
# 2017-04-12 WORK UNDER CONSTRUCTION - DO NOT CLONE OR DOWNLOAD
Hardware Abstraction Layer (HAL) for IBM's LMIC 1.6 communication stack Hardware Abstraction Layer (HAL) for IBM's LMIC 1.6 communication stack
targeted to RPi and Dragino LoRA/GPS HAT. targeted to RPi and Dragino LoRA/GPS HAT.
@ -34,7 +33,7 @@ the BSD License.
## Example "hello" ## Example "hello"
Directory: /examples/hello Directory: /examples/hello
Modifications neccessary: None Modifications necessary: None
This example does not use radio, it just periodically logs a counter value. This example does not use radio, it just periodically logs a counter value.
Can be used to checked if the timer implementation on RPi works as expected. Can be used to checked if the timer implementation on RPi works as expected.
@ -66,3 +65,63 @@ Possible output:
000003034 Debug: Label 'cnt = ' value 0x3 000003034 Debug: Label 'cnt = ' value 0x3
## Example "join"
Directory: /examples/join
Modifications necessary:
File /examples/join/main.c:
* Adapt "application router ID (LSBF)" according for your network infrastructure.
In case of The Things Network, this is the "Application EUI" of the application
created in the TTN console. Double check that you use the LSB (least significant
byte first) notation of the Application EUI.
* Adapt "unique device ID (LSBF)" according for your network infrastructure.
In case of The Things Network, you need to register a new device using TTN console.
Copy this "Device EUI" from the console and make sure you use the LSB notation.
* Adapt "device-specific AES key (derived from device EUI)".
This is the secret shared between your device and The Things Network. In TTN
terms this is known as "(LoRa) App Key".
Copy this 16 bytes and stick to MSB notation (Most significant byte first)
File /lmic/lmic.c:
The LMIC 1.6 stack randomly chooses one of six frequencies to send the "join" message
to the network. Tesing with a Kerlink IoT Station, only the following frequencies
worked: 868.1 868.3 868.5 MHz
The following default frequency did not work: 864.1 864.3 864.5
For this reason, I modified the code to only randomly choose between the three
working join frequencies.
This example verifies that the radio is working and that the node settings are
correct and match your network infrastructure. It uses OTAA (Over the Air Activiation)
to register the node. Note that this example _won't_
work with a Single Channel Gateway.
cd examples/join
make clean
make
sudo ./build/join.out
Possible outpout:
000000000 HAL: Initializing ...
000000001 HAL: Set radio RST pin to 0x00
000000002 HAL: Wait until 000000002 ms
000000003 HAL: Set radio RST pin to 0x02
000000003 HAL: Wait until 000000008 ms
000000008 HAL: Receiving ...
000000020 Debug: Initializing
000000020 Debug: JOINING
000002625 Debug: EV_TXSTART
000002626 HAL: Sending ...
000007689 HAL: Receiving ...
000007689 HAL: Wait until 000007690 ms
000007762 Debug: JOINED
What can be seen is that after sending the "join" message, the LMIC stack waits
5 seconds for the receive window and receives the acknowledgement from the LoRa gateway.

View File

@ -33,13 +33,13 @@
////////////////////////////////////////////////// //////////////////////////////////////////////////
// application router ID (LSBF) // application router ID (LSBF)
static const u1_t APPEUI[8] = { 0x02, 0x00, 0x00, 0x00, 0x00, 0xEE, 0xFF, 0xC0 }; static const u1_t APPEUI[8] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
// unique device ID (LSBF) // unique device ID (LSBF)
static const u1_t DEVEUI[8] = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF }; static const u1_t DEVEUI[8] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
// device-specific AES key (derived from device EUI) // device-specific AES key (derived from device EUI)
static const u1_t DEVKEY[16] = { 0xAB, 0x89, 0xEF, 0xCD, 0x23, 0x01, 0x67, 0x45, 0x54, 0x76, 0x10, 0x32, 0xDC, 0xFE, 0x98, 0xBA }; static const u1_t DEVKEY[16] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
////////////////////////////////////////////////// //////////////////////////////////////////////////

View File

@ -697,6 +697,23 @@ static void initJoinLoop (void) {
LMIC.txChnl = 0; LMIC.txChnl = 0;
#else #else
LMIC.txChnl = os_getRndU1() % 6; LMIC.txChnl = os_getRndU1() % 6;
// 2017-04-12 Wolfgang Klenk
// Instead to choose a random frequence for joining the network,
// you can use a fixed frequency.
// LMIC.txChnl = 0; // EU868: 868.1 MHz
// LMIC.txChnl = 2; // EU868: 868.3 MHz
// LMIC.txChnl = 4; // EU868: 868.5 MHz
// LMIC.txChnl = 1; // EU868: 864.1 MHz -- Seems not to work with Kerlink IoT Station
// LMIC.txChnl = 3; // EU868: 864.3 MHz -- Seems not to work with Kerlink IoT Station
// LMIC.txChnl = 5; // EU868: 864.5 MHz -- Seems not to work with Kerlink IoT Station
// 2017-04-12 Wolfgang Klenk
// Workaround for Kerlink IoT Station Join Frequencies
if (LMIC.txChnl == 1) LMIC.txChnl = 0;
if (LMIC.txChnl == 3) LMIC.txChnl = 2;
if (LMIC.txChnl == 5) LMIC.txChnl = 4;
#endif #endif
LMIC.adrTxPow = 14; LMIC.adrTxPow = 14;
setDrJoin(DRCHG_SET, DR_SF7); setDrJoin(DRCHG_SET, DR_SF7);

2223
lmic/lmic.c.original Normal file

File diff suppressed because it is too large Load Diff