Merge pull request #501 from nuthub/development

Implemented ABP configuration (on development branch)
This commit is contained in:
Verkehrsrot authored and GitHub committed 2020-03-15 22:11:05 +01:00
commit 0375185f68
4 files changed
+145 -15

No files matched your search

+52 -1
View File
@@ -1,3 +1,6 @@
#ifndef __LORACONF_H__
#define __LORACONF_H__
#if(HAS_LORA)
/************************************************************
@@ -6,6 +9,17 @@
* Read the values from TTN console (or whatever applies), insert them here,
* and rename this file to src/loraconf.h
*
* You can configure you PaxCounter to activate via OTAA (recommended) or ABP.
* In order to use ABP, uncomment (enable) the following line,
* otherwise, leave the line commented (disabled).
*
*************************************************************/
//#define LORA_ABP
/************************************************************
* OTAA configuration
*
* Note that DEVEUI, APPEUI and APPKEY should all be specified in MSB format.
* (This is different from standard LMIC-Arduino which expects DEVEUI and APPEUI
* in LSB format.)
@@ -22,6 +36,7 @@
* the DEVEUI will be overwriten by the one contained in the Microchip module
*
************************************************************/
#ifndef LORA_ABP
static const u1_t DEVEUI[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
@@ -29,5 +44,41 @@ static const u1_t APPEUI[8] = {0x70, 0xB3, 0xD5, 0x00, 0x00, 0x00, 0x00, 0x00};
static const u1_t APPKEY[16] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
#endif
#endif // HAS_LORA
/************************************************************
* ABP configuration (for development)
*
* Get your
* - Network Session Key (NWKSKEY)
* - App Session Key and your (APPSKEY)
* - Device Address (DEVADDR)
* from TTN console and replace the example values below.
*
* NOTE: Use MSB format (as displayed in TTN console, so you can cut & paste
* from there)
*
************************************************************/
#ifdef LORA_ABP
// ID of LoRaAlliance assigned Network (for a list, see e.g. here https://www.thethingsnetwork.org/docs/lorawan/prefix-assignments.html)
static const u1_t NETID = 0x13; // TTN
static const u1_t NWKSKEY[16] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
static const u1_t APPSKEY[16] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
static const u4_t DEVADDR = 0x00000000; // <-- Change this address for every node!
// set additional ABP parameters in loraconf_abp.cpp
void setABPParamaters();
#endif
#endif // HAS_LORA
#endif // __LORACONF_H__
+60
View File
@@ -0,0 +1,60 @@
#include "lorawan.h"
#include "loraconf.h"
#ifdef LORA_ABP
/** ******************************************************************
*
* See LoRaWAN Regional Parameters Document, or here:
* https://www.thethingsnetwork.org/docs/lorawan/frequency-plans.html
*
* Parameters fro TTN and comments below are taken
* from MCCI LoRaWAN LMIC library example 'ttn-abp.ino'
*
*********************************************************************/
void setABPParamaters() {
/** **************************************************************
* ************************************************************* */
#if defined(CFG_eu868)
// Set up the channels used by the Things Network, which corresponds
// to the defaults of most gateways. Without this, only three base
// channels from the LoRaWAN specification are used, which certainly
// works, so it is good for debugging, but can overload those
// frequencies, so be sure to configure the full frequency range of
// your network here (unless your network autoconfigures them).
// Setting up channels should happen after LMIC_setSession, as that
// configures the minimal channel set.
LMIC_setupChannel(0, 868100000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_CENTI); // g-band
LMIC_setupChannel(1, 868300000, DR_RANGE_MAP(DR_SF12, DR_SF7B), BAND_CENTI); // g-band
LMIC_setupChannel(2, 868500000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_CENTI); // g-band
LMIC_setupChannel(3, 867100000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_CENTI); // g-band
LMIC_setupChannel(4, 867300000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_CENTI); // g-band
LMIC_setupChannel(5, 867500000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_CENTI); // g-band
LMIC_setupChannel(6, 867700000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_CENTI); // g-band
LMIC_setupChannel(7, 867900000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_CENTI); // g-band
LMIC_setupChannel(8, 868800000, DR_RANGE_MAP(DR_FSK, DR_FSK), BAND_MILLI); // g2-band
// TTN defines an additional channel at 869.525Mhz using SF9 for class B
// devices' ping slots. LMIC does not have an easy way to define set this
// frequency and support for class B is spotty and untested, so this
// frequency is not configured here.
#elif defined(CFG_us915)
// NA-US channels 0-71 are configured automatically
// but only one group of 8 should (a subband) should be active
// TTN recommends the second sub band, 1 in a zero based count.
// https://github.com/TheThingsNetwork/gateway-conf/blob/master/US-global_conf.json
LMIC_selectSubBand(1);
#endif
// Disable link check validation
LMIC_setLinkCheckMode(0);
// TTN uses SF9 for its RX2 window.
LMIC.dn2Dr = DR_SF9;
// Set data rate and transmit power for uplink
LMIC_setDrTxpow(DR_SF7,14);
}
#endif
+32 -13
View File
@@ -136,14 +136,21 @@ void RevBytes(unsigned char *b, size_t c) {
}
// LMIC callback functions
void os_getDevKey(u1_t *buf) { memcpy(buf, APPKEY, 16); }
void os_getDevKey(u1_t *buf) {
#ifndef LORA_ABP
memcpy(buf, APPKEY, 16);
#endif
}
void os_getArtEui(u1_t *buf) {
#ifndef LORA_ABP
memcpy(buf, APPEUI, 8);
RevBytes(buf, 8); // TTN requires it in LSB First order, so we swap bytes
#endif
}
void os_getDevEui(u1_t *buf) {
#ifndef LORA_ABP
int i = 0, k = 0;
memcpy(buf, DEVEUI, 8); // get fixed DEVEUI from loraconf.h
for (i = 0; i < 8; i++) {
@@ -160,6 +167,7 @@ void os_getDevEui(u1_t *buf) {
get_hard_deveui(buf);
RevBytes(buf, 8); // swap bytes to LSB format
#endif
#endif
}
void get_hard_deveui(uint8_t *pdeveui) {
@@ -298,19 +306,30 @@ esp_err_t lora_stack_init(bool do_join) {
&lmicTask, // task handle
1); // CPU core
// Start join procedure if not already joined,
// lora_setupForNetwork(true) is called by eventhandler when joined
// else continue current session
if (do_join) {
if (!LMIC_startJoining())
ESP_LOGI(TAG, "Already joined");
} else {
#ifdef LORA_ABP
// Pass ABP parameters to LMIC_setSession
LMIC_reset();
LMIC_setSession(RTCnetid, RTCdevaddr, RTCnwkKey, RTCartKey);
LMIC.seqnoUp = RTCseqnoUp;
LMIC.seqnoDn = RTCseqnoDn;
}
uint8_t appskey[sizeof(APPSKEY)];
uint8_t nwkskey[sizeof(NWKSKEY)];
memcpy_P(appskey, APPSKEY, sizeof(APPSKEY));
memcpy_P(nwkskey, NWKSKEY, sizeof(NWKSKEY));
LMIC_setSession (NETID, DEVADDR, nwkskey, appskey);
// These parameters are defined as macro in loraconf.h
setABPParamaters();
#else
// Start join procedure if not already joined,
// lora_setupForNetwork(true) is called by eventhandler when joined
// else continue current session
if (do_join) {
if (!LMIC_startJoining())
ESP_LOGI(TAG, "Already joined");
} else {
LMIC_reset();
LMIC_setSession(RTCnetid, RTCdevaddr, RTCnwkKey, RTCartKey);
LMIC.seqnoUp = RTCseqnoUp;
LMIC.seqnoDn = RTCseqnoDn;
}
#endif
// start lmic send task
xTaskCreatePinnedToCore(lora_send, // task function
"lorasendtask", // name of task