[LoRaWAN] Remove pin maps from example config file (#1106)

This commit is contained in:
jgromes 2024-06-19 21:08:11 +02:00
parent 940eb07674
commit d31d9968af
4 changed files with 67 additions and 325 deletions

View file

@ -1,8 +1,21 @@
#ifndef _CONFIG_H
#define _CONFIG_H
#ifndef _RADIOLIB_EX_LORAWAN_CONFIG_H
#define _RADIOLIB_EX_LORAWAN_CONFIG_H
#include <RadioLib.h>
// first you have to set your radio model and pin configuration
// this is provided just as a default example
SX1278 radio = new Module(10, 2, 9, 3);
// if you have RadioBoards (https://github.com/radiolib-org/RadioBoards)
// and are using one of the supported boards, you can do the following:
/*
#define RADIO_BOARD_AUTO
#include <RadioBoards.h>
Radio radio = new RadioModule();
*/
// how often to send an uplink - consider legal & FUP constraints - see notes
const uint32_t uplinkIntervalSeconds = 5UL * 60UL; // minutes x seconds
@ -32,98 +45,9 @@ const uint32_t uplinkIntervalSeconds = 5UL * 60UL; // minutes x seconds
const LoRaWANBand_t Region = EU868;
const uint8_t subBand = 0; // For US915, change this to 2, otherwise leave on 0
// ============================================================================
// Below is to support the sketch - only make changes if the notes say so ...
// Auto select MCU <-> radio connections
// If you get an error message when compiling, it may be that the
// pinmap could not be determined - see the notes for more info
// Adafruit
#if defined(ARDUINO_SAMD_FEATHER_M0)
#pragma message ("Adafruit Feather M0 with RFM95")
#pragma message ("Link required on board")
SX1276 radio = new Module(8, 3, 4, 6);
// LilyGo
#elif defined(ARDUINO_TTGO_LORA32_V1)
#pragma message ("Using TTGO LoRa32 v1 - no Display")
SX1276 radio = new Module(18, 26, 14, 33);
#elif defined(ARDUINO_TTGO_LORA32_V2)
#pragma message ("Using TTGO LoRa32 v2 + Display")
SX1276 radio = new Module(18, 26, 12, RADIOLIB_NC);
#elif defined(ARDUINO_TTGO_LoRa32_v21new) // T3_V1.6.1
#pragma message ("Using TTGO LoRa32 v2.1 marked T3_V1.6.1 + Display")
SX1276 radio = new Module(18, 26, 14, 33);
#elif defined(ARDUINO_TBEAM_USE_RADIO_SX1262)
#pragma error ("ARDUINO_TBEAM_USE_RADIO_SX1262 awaiting pin map")
#elif defined(ARDUINO_TBEAM_USE_RADIO_SX1276)
#pragma message ("Using TTGO T-Beam")
SX1276 radio = new Module(18, 26, 23, 33);
// HelTec: https://github.com/espressif/arduino-esp32/blob/master/variants/heltec_*/pins_arduino.h
#elif defined(ARDUINO_HELTEC_WIFI_LORA_32)
#pragma message ("Using Heltec WiFi LoRa32")
SX1276 radio = new Module(18, 26, 14, 33);
#elif defined(ARDUINO_heltec_wifi_lora_32_V2)
#pragma message ("Using Heltec WiFi LoRa32 v2")
SX1278 radio = new Module(14, 4, 12, 16);
// Pending verfication of which radio is shipped
// #elif defined(ARDUINO_heltec_wifi_lora_32_V2)
// #pragma message ("ARDUINO_heltec_wifi_kit_32_V2 awaiting pin map")
// SX1276 radio = new Module(18, 26, 14, 35);
#elif defined(ARDUINO_heltec_wifi_lora_32_V3)
#pragma message ("Using Heltec WiFi LoRa32 v3 - Display + USB-C")
SX1262 radio = new Module(8, 14, 12, 13);
// Following not verified
#elif defined (ARDUINO_heltec_wireless_stick)
#pragma message ("Using Heltec Wireless Stick")
SX1278 radio = new Module(14, 4, 12, 16);
#elif defined (ARDUINO_HELTEC_WIRELESS_STICK)
#pragma message ("Using Heltec Wireless Stick")
SX1276 radio = new Module(18, 26, 14, 35);
#elif defined (ARDUINO_HELTEC_WIRELESS_STICK_V3)
#pragma message ("Using Heltec Wireless Stick v3")
SX1262 radio = new Module(8, 14, 12, 13);
#elif defined (ARDUINO_HELTEC_WIRELESS_STICK_LITE)
#pragma message ("Using Heltec Wireless Stick Lite")
SX1276 radio = new Module(18, 26, 14, 35);
#elif defined (ARDUINO_HELTEC_WIRELESS_STICK_LITE_V3)
#pragma message ("Using Heltec Wireless Stick Lite v3")
SX1262 radio = new Module(34, 14, 12, 13);
// If we don't recognise the board
#else
#pragma message ("Unknown board - no automagic pinmap available")
// SX1262 pin order: Module(NSS/CS, DIO1, RESET, BUSY);
// SX1262 radio = new Module(8, 14, 12, 13);
// SX1278 pin order: Module(NSS/CS, DIO0, RESET, DIO1);
// SX1278 radio = new Module(10, 2, 9, 3);
// For Pi Pico + Waveshare HAT - work in progress
// SX1262 radio = new Module(3, 20, 15, 2, SPI1, RADIOLIB_DEFAULT_SPI_SETTINGS);
#endif
// copy over the keys in to the something that will not compile if incorrectly formatted
uint32_t devAddr = RADIOLIB_LORAWAN_DEV_ADDR;
uint8_t fNwkSIntKey[] = { RADIOLIB_LORAWAN_FNWKSINT_KEY };
@ -134,8 +58,8 @@ uint8_t appSKey[] = { RADIOLIB_LORAWAN_APPS_KEY };
// create the LoRaWAN node
LoRaWANNode node(&radio, &Region, subBand);
// result code to text ...
// result code to text - these are error codes that can be raised when using LoRaWAN
// however, RadioLib has many more - see https://jgromes.github.io/RadioLib/group__status__codes.html for a complete list
String stateDecode(const int16_t result) {
switch (result) {
case RADIOLIB_ERR_NONE:
@ -160,7 +84,6 @@ String stateDecode(const int16_t result) {
return "ERR_INVALID_OUTPUT_POWER";
case RADIOLIB_ERR_NETWORK_NOT_JOINED:
return "RADIOLIB_ERR_NETWORK_NOT_JOINED";
case RADIOLIB_ERR_DOWNLINK_MALFORMED:
return "RADIOLIB_ERR_DOWNLINK_MALFORMED";
case RADIOLIB_ERR_INVALID_REVISION:
@ -198,23 +121,22 @@ String stateDecode(const int16_t result) {
case RADIOLIB_LORAWAN_SESSION_DISCARDED:
return "RADIOLIB_LORAWAN_SESSION_DISCARDED";
}
return "See TypeDef.h";
return "See https://jgromes.github.io/RadioLib/group__status__codes.html";
}
// helper function to display any issues
void debug(bool isFail, const __FlashStringHelper* message, int state, bool Freeze) {
if (isFail) {
void debug(bool failed, const __FlashStringHelper* message, int state, bool halt) {
if(failed) {
Serial.print(message);
Serial.print(" - ");
Serial.print(stateDecode(state));
Serial.print(" (");
Serial.print(state);
Serial.println(")");
while (Freeze);
while(halt) { delay(1); }
}
}
// helper function to display a byte array
void arrayDump(uint8_t *buffer, uint16_t len) {
for(uint16_t c = 0; c < len; c++) {

View file

@ -1,8 +1,21 @@
#ifndef _CONFIG_H
#define _CONFIG_H
#ifndef _RADIOLIB_EX_LORAWAN_CONFIG_H
#define _RADIOLIB_EX_LORAWAN_CONFIG_H
#include <RadioLib.h>
// first you have to set your radio model and pin configuration
// this is provided just as a default example
SX1278 radio = new Module(10, 2, 9, 3);
// if you have RadioBoards (https://github.com/radiolib-org/RadioBoards)
// and are using one of the supported boards, you can do the following:
/*
#define RADIO_BOARD_AUTO
#include <RadioBoards.h>
Radio radio = new RadioModule();
*/
// how often to send an uplink - consider legal & FUP constraints - see notes
const uint32_t uplinkIntervalSeconds = 5UL * 60UL; // minutes x seconds
@ -31,94 +44,6 @@ const uint8_t subBand = 0; // For US915, change this to 2, otherwise leave on 0
// ============================================================================
// Below is to support the sketch - only make changes if the notes say so ...
// Auto select MCU <-> radio connections
// If you get an error message when compiling, it may be that the
// pinmap could not be determined - see the notes for more info
// Adafruit
#if defined(ARDUINO_SAMD_FEATHER_M0)
#pragma message ("Adafruit Feather M0 with RFM95")
#pragma message ("Link required on board")
SX1276 radio = new Module(8, 3, 4, 6);
// LilyGo
#elif defined(ARDUINO_TTGO_LORA32_V1)
#pragma message ("Using TTGO LoRa32 v1 - no Display")
SX1276 radio = new Module(18, 26, 14, 33);
#elif defined(ARDUINO_TTGO_LORA32_V2)
#pragma message ("Using TTGO LoRa32 v2 + Display")
SX1276 radio = new Module(18, 26, 12, RADIOLIB_NC);
#elif defined(ARDUINO_TTGO_LoRa32_v21new) // T3_V1.6.1
#pragma message ("Using TTGO LoRa32 v2.1 marked T3_V1.6.1 + Display")
SX1276 radio = new Module(18, 26, 14, 33);
#elif defined(ARDUINO_TBEAM_USE_RADIO_SX1262)
#pragma error ("ARDUINO_TBEAM_USE_RADIO_SX1262 awaiting pin map")
#elif defined(ARDUINO_TBEAM_USE_RADIO_SX1276)
#pragma message ("Using TTGO T-Beam")
SX1276 radio = new Module(18, 26, 23, 33);
// HelTec: https://github.com/espressif/arduino-esp32/blob/master/variants/heltec_*/pins_arduino.h
#elif defined(ARDUINO_HELTEC_WIFI_LORA_32)
#pragma message ("Using Heltec WiFi LoRa32")
SX1276 radio = new Module(18, 26, 14, 33);
#elif defined(ARDUINO_heltec_wifi_lora_32_V2)
#pragma message ("Using Heltec WiFi LoRa32 v2")
SX1278 radio = new Module(14, 4, 12, 16);
// Pending verfication of which radio is shipped
// #elif defined(ARDUINO_heltec_wifi_lora_32_V2)
// #pragma message ("ARDUINO_heltec_wifi_kit_32_V2 awaiting pin map")
// SX1276 radio = new Module(18, 26, 14, 35);
#elif defined(ARDUINO_heltec_wifi_lora_32_V3)
#pragma message ("Using Heltec WiFi LoRa32 v3 - Display + USB-C")
SX1262 radio = new Module(8, 14, 12, 13);
// Following not verified
#elif defined (ARDUINO_heltec_wireless_stick)
#pragma message ("Using Heltec Wireless Stick")
SX1278 radio = new Module(14, 4, 12, 16);
#elif defined (ARDUINO_HELTEC_WIRELESS_STICK)
#pragma message ("Using Heltec Wireless Stick")
SX1276 radio = new Module(18, 26, 14, 35);
#elif defined (ARDUINO_HELTEC_WIRELESS_STICK_V3)
#pragma message ("Using Heltec Wireless Stick v3")
SX1262 radio = new Module(8, 14, 12, 13);
#elif defined (ARDUINO_HELTEC_WIRELESS_STICK_LITE)
#pragma message ("Using Heltec Wireless Stick Lite")
SX1276 radio = new Module(18, 26, 14, 35);
#elif defined (ARDUINO_HELTEC_WIRELESS_STICK_LITE_V3)
#pragma message ("Using Heltec Wireless Stick Lite v3")
SX1262 radio = new Module(34, 14, 12, 13);
// If we don't recognise the board
#else
#pragma message ("Unknown board - no automagic pinmap available")
// SX1262 pin order: Module(NSS/CS, DIO1, RESET, BUSY);
// SX1262 radio = new Module(8, 14, 12, 13);
// SX1278 pin order: Module(NSS/CS, DIO0, RESET, DIO1);
// SX1278 radio = new Module(10, 2, 9, 3);
// For Pi Pico + Waveshare HAT - work in progress
// SX1262 radio = new Module(3, 20, 15, 2, SPI1, RADIOLIB_DEFAULT_SPI_SETTINGS);
#endif
// copy over the EUI's & keys in to the something that will not compile if incorrectly formatted
uint64_t joinEUI = RADIOLIB_LORAWAN_JOIN_EUI;
uint64_t devEUI = RADIOLIB_LORAWAN_DEV_EUI;
@ -128,8 +53,8 @@ uint8_t nwkKey[] = { RADIOLIB_LORAWAN_NWK_KEY };
// create the LoRaWAN node
LoRaWANNode node(&radio, &Region, subBand);
// result code to text ...
// result code to text - these are error codes that can be raised when using LoRaWAN
// however, RadioLib has many more - see https://jgromes.github.io/RadioLib/group__status__codes.html for a complete list
String stateDecode(const int16_t result) {
switch (result) {
case RADIOLIB_ERR_NONE:
@ -154,7 +79,6 @@ String stateDecode(const int16_t result) {
return "ERR_INVALID_OUTPUT_POWER";
case RADIOLIB_ERR_NETWORK_NOT_JOINED:
return "RADIOLIB_ERR_NETWORK_NOT_JOINED";
case RADIOLIB_ERR_DOWNLINK_MALFORMED:
return "RADIOLIB_ERR_DOWNLINK_MALFORMED";
case RADIOLIB_ERR_INVALID_REVISION:
@ -192,23 +116,22 @@ String stateDecode(const int16_t result) {
case RADIOLIB_LORAWAN_SESSION_DISCARDED:
return "RADIOLIB_LORAWAN_SESSION_DISCARDED";
}
return "See TypeDef.h";
return "See https://jgromes.github.io/RadioLib/group__status__codes.html";
}
// helper function to display any issues
void debug(bool isFail, const __FlashStringHelper* message, int state, bool Freeze) {
if (isFail) {
void debug(bool failed, const __FlashStringHelper* message, int state, bool halt) {
if(failed) {
Serial.print(message);
Serial.print(" - ");
Serial.print(stateDecode(state));
Serial.print(" (");
Serial.print(state);
Serial.println(")");
while (Freeze);
while(halt) { delay(1); }
}
}
// helper function to display a byte array
void arrayDump(uint8_t *buffer, uint16_t len) {
for(uint16_t c = 0; c < len; c++) {
@ -219,5 +142,4 @@ void arrayDump(uint8_t *buffer, uint16_t len) {
Serial.println();
}
#endif

View file

@ -1,8 +1,21 @@
#ifndef _CONFIG_H
#define _CONFIG_H
#ifndef _RADIOLIB_EX_LORAWAN_CONFIG_H
#define _RADIOLIB_EX_LORAWAN_CONFIG_H
#include <RadioLib.h>
// first you have to set your radio model and pin configuration
// this is provided just as a default example
SX1278 radio = new Module(10, 2, 9, 3);
// if you have RadioBoards (https://github.com/radiolib-org/RadioBoards)
// and are using one of the supported boards, you can do the following:
/*
#define RADIO_BOARD_AUTO
#include <RadioBoards.h>
Radio radio = new RadioModule();
*/
// how often to send an uplink - consider legal & FUP constraints - see notes
const uint32_t uplinkIntervalSeconds = 5UL * 60UL; // minutes x seconds
@ -31,94 +44,6 @@ const uint8_t subBand = 0; // For US915, change this to 2, otherwise leave on 0
// ============================================================================
// Below is to support the sketch - only make changes if the notes say so ...
// Auto select MCU <-> radio connections
// If you get an error message when compiling, it may be that the
// pinmap could not be determined - see the notes for more info
// Adafruit
#if defined(ARDUINO_SAMD_FEATHER_M0)
#pragma message ("Adafruit Feather M0 with RFM95")
#pragma message ("Link required on board")
SX1276 radio = new Module(8, 3, 4, 6);
// LilyGo
#elif defined(ARDUINO_TTGO_LORA32_V1)
#pragma message ("Using TTGO LoRa32 v1 - no Display")
SX1276 radio = new Module(18, 26, 14, 33);
#elif defined(ARDUINO_TTGO_LORA32_V2)
#pragma message ("Using TTGO LoRa32 v2 + Display")
SX1276 radio = new Module(18, 26, 12, RADIOLIB_NC);
#elif defined(ARDUINO_TTGO_LoRa32_v21new) // T3_V1.6.1
#pragma message ("Using TTGO LoRa32 v2.1 marked T3_V1.6.1 + Display")
SX1276 radio = new Module(18, 26, 14, 33);
#elif defined(ARDUINO_TBEAM_USE_RADIO_SX1262)
#pragma error ("ARDUINO_TBEAM_USE_RADIO_SX1262 awaiting pin map")
#elif defined(ARDUINO_TBEAM_USE_RADIO_SX1276)
#pragma message ("Using TTGO T-Beam")
SX1276 radio = new Module(18, 26, 23, 33);
// HelTec: https://github.com/espressif/arduino-esp32/blob/master/variants/heltec_*/pins_arduino.h
#elif defined(ARDUINO_HELTEC_WIFI_LORA_32)
#pragma message ("Using Heltec WiFi LoRa32")
SX1276 radio = new Module(18, 26, 14, 33);
#elif defined(ARDUINO_heltec_wifi_lora_32_V2)
#pragma message ("Using Heltec WiFi LoRa32 v2")
SX1278 radio = new Module(14, 4, 12, 16);
// Pending verfication of which radio is shipped
// #elif defined(ARDUINO_heltec_wifi_lora_32_V2)
// #pragma message ("ARDUINO_heltec_wifi_kit_32_V2 awaiting pin map")
// SX1276 radio = new Module(18, 26, 14, 35);
#elif defined(ARDUINO_heltec_wifi_lora_32_V3)
#pragma message ("Using Heltec WiFi LoRa32 v3 - Display + USB-C")
SX1262 radio = new Module(8, 14, 12, 13);
// Following not verified
#elif defined (ARDUINO_heltec_wireless_stick)
#pragma message ("Using Heltec Wireless Stick")
SX1278 radio = new Module(14, 4, 12, 16);
#elif defined (ARDUINO_HELTEC_WIRELESS_STICK)
#pragma message ("Using Heltec Wireless Stick")
SX1276 radio = new Module(18, 26, 14, 35);
#elif defined (ARDUINO_HELTEC_WIRELESS_STICK_V3)
#pragma message ("Using Heltec Wireless Stick v3")
SX1262 radio = new Module(8, 14, 12, 13);
#elif defined (ARDUINO_HELTEC_WIRELESS_STICK_LITE)
#pragma message ("Using Heltec Wireless Stick Lite")
SX1276 radio = new Module(18, 26, 14, 35);
#elif defined (ARDUINO_HELTEC_WIRELESS_STICK_LITE_V3)
#pragma message ("Using Heltec Wireless Stick Lite v3")
SX1262 radio = new Module(34, 14, 12, 13);
// If we don't recognise the board
#else
#pragma message ("Unknown board - no automagic pinmap available")
// SX1262 pin order: Module(NSS/CS, DIO1, RESET, BUSY);
// SX1262 radio = new Module(8, 14, 12, 13);
// SX1278 pin order: Module(NSS/CS, DIO0, RESET, DIO1);
// SX1278 radio = new Module(10, 2, 9, 3);
// For Pi Pico + Waveshare HAT - work in progress
// SX1262 radio = new Module(3, 20, 15, 2, SPI1, RADIOLIB_DEFAULT_SPI_SETTINGS);
#endif
// copy over the EUI's & keys in to the something that will not compile if incorrectly formatted
uint64_t joinEUI = RADIOLIB_LORAWAN_JOIN_EUI;
uint64_t devEUI = RADIOLIB_LORAWAN_DEV_EUI;
@ -128,8 +53,8 @@ uint8_t nwkKey[] = { RADIOLIB_LORAWAN_NWK_KEY };
// create the LoRaWAN node
LoRaWANNode node(&radio, &Region, subBand);
// result code to text ...
// result code to text - these are error codes that can be raised when using LoRaWAN
// however, RadioLib has many more - see https://jgromes.github.io/RadioLib/group__status__codes.html for a complete list
String stateDecode(const int16_t result) {
switch (result) {
case RADIOLIB_ERR_NONE:
@ -154,7 +79,6 @@ String stateDecode(const int16_t result) {
return "ERR_INVALID_OUTPUT_POWER";
case RADIOLIB_ERR_NETWORK_NOT_JOINED:
return "RADIOLIB_ERR_NETWORK_NOT_JOINED";
case RADIOLIB_ERR_DOWNLINK_MALFORMED:
return "RADIOLIB_ERR_DOWNLINK_MALFORMED";
case RADIOLIB_ERR_INVALID_REVISION:
@ -192,23 +116,22 @@ String stateDecode(const int16_t result) {
case RADIOLIB_LORAWAN_SESSION_DISCARDED:
return "RADIOLIB_LORAWAN_SESSION_DISCARDED";
}
return "See TypeDef.h";
return "See https://jgromes.github.io/RadioLib/group__status__codes.html";
}
// helper function to display any issues
void debug(bool isFail, const __FlashStringHelper* message, int state, bool Freeze) {
if (isFail) {
void debug(bool failed, const __FlashStringHelper* message, int state, bool halt) {
if(failed) {
Serial.print(message);
Serial.print(" - ");
Serial.print(stateDecode(state));
Serial.print(" (");
Serial.print(state);
Serial.println(")");
while (Freeze);
while(halt) { delay(1); }
}
}
// helper function to display a byte array
void arrayDump(uint8_t *buffer, uint16_t len) {
for(uint16_t c = 0; c < len; c++) {
@ -219,5 +142,4 @@ void arrayDump(uint8_t *buffer, uint16_t len) {
Serial.println();
}
#endif

View file

@ -141,31 +141,12 @@ If you are using US915 or AU915 then you should change the subBand const to 2.
### The pinmap
This is the connection between the MCU (ESP32/ATmega/SAMD) and the LoRa radio (SX1276/SX1262).
This is the connection between your microcontroller (ESP32, ATmega, SAMD etc.) and the radio (SX1276, SX1262, LR1110 etc.).
You have to select the correct module and set the correct pins.
Prebuilt modules are easy - we can detect the board and setup the pinmap for you. These boards are:
* TTGO_LoRa32
* TTGO_LoRa32_V1
* TTGO_LORA32_V2
* TTGO_LORA32_v21NEW
* HELTEC_WIFI_LORA_32
* HELTEC_WIFI_LORA_32_V2
* HELTEC_WIFI_LORA_32_V3
* HELTEC_WIRELESS_STICK
* HELTEC_WIRELESS_STICK_V3
* HELTEC_WIRELESS_STICK_LITE
* HELTEC_WIRELESS_STICK_LITE_V3
If you have a TTGO T-Beam, you must choose the correct radio from the Board Revision sub-menu found under the main Tools menu.
* TBEAM_USE_RADIO_SX1262
* TBEAM_USE_RADIO_SX1276
Auto-setup for the Adafruit Feather M0 with RFM95 is included but you must solder a wire or use a jumper to link from pin 6 to io1: https://learn.adafruit.com/the-things-network-for-feather/arduino-wiring
If you have a module that's not on this list, please go to the "Pinmap How-To" below.
Pin maps for commonly used radio modules are kept in a separate library, called RadioBoards: https://github.com/radiolib-org/RadioBoards
It can automatically detect your microcontroller platform and radio, and configure things for you. If you have a board that is not supported by RadioBoards, feel free to suggest it in the RadioBoards issues, or better yet - open a pull request there!
## Observations on the main sketch
@ -197,8 +178,3 @@ Coming soon
### Device testing
The LoRaWAN code base works to a specification and once you are happy your device is able to join & send a few dozen uplinks, continuing to sit around waiting for an uplink to test your sensor code & payload format is a waste of your time. The solution is to write everything else in a different sketch, output the array to the serial console and then you can copy & paste the hex array in to the TTN console Payload Formatters section to test the decoding.
## Pinmap How-To
Coming soon