Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 17 additions & 51 deletions examples/raw-feather/raw-feather.ino
Original file line number Diff line number Diff line change
Expand Up @@ -56,56 +56,6 @@ Author:
#define TX_INTERVAL 2000 // milliseconds
#define RX_RSSI_INTERVAL 100 // milliseconds

// Pin mapping for Adafruit Feather M0 LoRa, etc.
//
// Adafruit BSPs are not consistent -- m0 express defs ARDUINO_SAMD_FEATHER_M0,
// m0 defs ADAFRUIT_FEATHER_M0
//
#if defined(ARDUINO_SAMD_FEATHER_M0) || defined(ADAFRUIT_FEATHER_M0)
// /!\ By default Adafruit Feather M0's pin 6 and DIO1 are not connected.
// Please ensure they are connected.
const lmic_pinmap lmic_pins = {
.nss = 8,
.rxtx = LMIC_UNUSED_PIN,
.rst = 4,
.dio = {3, 6, LMIC_UNUSED_PIN},
.rxtx_rx_active = 0,
.rssi_cal = 8, // LBT cal for the Adafruit Feather M0 LoRa, in dB
.spi_freq = 8000000,
};
#elif defined(ARDUINO_AVR_FEATHER32U4)
// Pin mapping for Adafruit Feather 32u4 LoRa, etc.
// Just like Feather M0 LoRa, but uses SPI at 1MHz; and that's only
// because MCCI doesn't have a test board; probably higher frequencies
// will work.
// /!\ By default Feather 32u4's pin 6 and DIO1 are not connected. Please
// ensure they are connected.
const lmic_pinmap lmic_pins = {
.nss = 8,
.rxtx = LMIC_UNUSED_PIN,
.rst = 4,
.dio = {7, 6, LMIC_UNUSED_PIN},
.rxtx_rx_active = 0,
.rssi_cal = 8, // LBT cal for the Adafruit Feather 32U4 LoRa, in dB
.spi_freq = 1000000,
};
#elif defined(ARDUINO_CATENA_4551)
const lmic_pinmap lmic_pins = {
.nss = 7,
.rxtx = 29,
.rst = 8,
.dio = { 25, // DIO0 (IRQ) is D25
26, // DIO1 is D26
27, // DIO2 is D27
},
.rxtx_rx_active = 1,
.rssi_cal = 10,
.spi_freq = 8000000 // 8MHz
};
#else
# error "Unknown target"
#endif

// These callbacks are only used in over-the-air activation, so they are
// left empty here (we cannot leave them out completely unless
// DISABLE_JOIN is set in arduino-lmoc/project_config/lmic_project_config.h,
Expand Down Expand Up @@ -272,7 +222,23 @@ void setup() {
pinMode(LED_BUILTIN, OUTPUT);

// initialize runtime env
os_init();
// don't die mysteriously; die noisily.
const lmic_pinmap *pPinMap = Arduino_LMIC::GetPinmap_ThisBoard();

if (pPinMap == nullptr) {
pinMode(LED_BUILTIN, OUTPUT);
for (;;) {
// flash lights, sleep.
for (int i = 0; i < 5; ++i) {
digitalWrite(LED_BUILTIN, 1);
delay(100);
digitalWrite(LED_BUILTIN, 0);
delay(900);
}
Serial.println(F("board not known to library; add pinmap or update getconfig_thisboard.cpp"));
}
}
os_init_ex(pPinMap);

// Set up these settings once, and use them for both TX and RX
#ifdef ARDUINO_ARCH_STM32
Expand Down
27 changes: 17 additions & 10 deletions examples/raw/raw.ino
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,6 @@
// https://docs.google.com/spreadsheets/d/1voGAtQAjC1qBmaVuP1ApNKs1ekgUjavHuVQIXyYSvNc
#define TX_INTERVAL 2000

// Pin mapping
const lmic_pinmap lmic_pins = {
.nss = 6,
.rxtx = LMIC_UNUSED_PIN,
.rst = 5,
.dio = {2, 3, 4},
};


// These callbacks are only used in over-the-air activation, so they are
// left empty here (we cannot leave them out completely unless
// DISABLE_JOIN is set in arduino-lmoc/project_config/lmic_project_config.h,
Expand Down Expand Up @@ -137,7 +128,23 @@ void setup() {
pinMode(LED_BUILTIN, OUTPUT);

// initialize runtime env
os_init();
// don't die mysteriously; die noisily.
const lmic_pinmap *pPinMap = Arduino_LMIC::GetPinmap_ThisBoard();

if (pPinMap == nullptr) {
pinMode(LED_BUILTIN, OUTPUT);
for (;;) {
// flash lights, sleep.
for (int i = 0; i < 5; ++i) {
digitalWrite(LED_BUILTIN, 1);
delay(100);
digitalWrite(LED_BUILTIN, 0);
delay(900);
}
Serial.println(F("board not known to library; add pinmap or update getconfig_thisboard.cpp"));
}
}
os_init_ex(pPinMap);

#if defined(CFG_eu868)
// Use a frequency in the g3 which allows 10% duty cycling.
Expand Down
22 changes: 20 additions & 2 deletions examples/ttn-abp/ttn-abp.ino
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <lmic.h>
#include <hal/hal.h>
#include <SPI.h>
#include "ttn-secrets.h"

//
// For normal use, we require that you edit the sketch to replace FILLMEIN
Expand Down Expand Up @@ -208,8 +209,25 @@ void setup() {
delay(1000);
#endif

// LMIC init
os_init();
// initialize runtime env
// don't die mysteriously; die noisily.
const lmic_pinmap *pPinMap = Arduino_LMIC::GetPinmap_ThisBoard();

if (pPinMap == nullptr) {
pinMode(LED_BUILTIN, OUTPUT);
for (;;) {
// flash lights, sleep.
for (int i = 0; i < 5; ++i) {
digitalWrite(LED_BUILTIN, 1);
delay(100);
digitalWrite(LED_BUILTIN, 0);
delay(900);
}
Serial.println(F("board not known to library; add pinmap or update getconfig_thisboard.cpp"));
}
}

os_init_ex(pPinMap);
// Reset the MAC state. Session and pending data transfers will be discarded.
LMIC_reset();

Expand Down
Empty file added examples/ttn-abp/ttn-secrets.h
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
*******************************************************************************/
#include <lmic.h>
#include <hal/hal.h>
#include <arduino_lmic_hal_boards.h>

#include <SPI.h>
#include "ttn-secrets.h"

// include the DHT22 Sensor Library
#include "DHT.h"
Expand All @@ -27,57 +30,13 @@
#define DHTPIN 10
#define DHTTYPE DHT22

//
// For normal use, we require that you edit the sketch to replace FILLMEIN
// with values assigned by the TTN console. However, for regression tests,
// we want to be able to compile these scripts. The regression tests define
// COMPILE_REGRESSION_TEST, and in that case we define FILLMEIN to a non-
// working but innocuous value.
//
#ifdef COMPILE_REGRESSION_TEST
#define FILLMEIN 0
#else
#warning "You must replace the values marked FILLMEIN with real values from the TTN control panel!"
#define FILLMEIN (#dont edit this, edit the lines that use FILLMEIN)
#endif

// This EUI must be in little-endian format, so least-significant-byte
// first. When copying an EUI from ttnctl output, this means to reverse
// the bytes. For TTN issued EUIs the last bytes should be 0xD5, 0xB3,
// 0x70.
static const u1_t PROGMEM APPEUI[8] = { FILLMEIN };
void os_getArtEui (u1_t* buf) { memcpy_P(buf, APPEUI, 8);}

// This should also be in little endian format, see above.
static const u1_t PROGMEM DEVEUI[8] = { FILLMEIN };
void os_getDevEui (u1_t* buf) { memcpy_P(buf, DEVEUI, 8);}

// This key should be in big endian format (or, since it is not really a
// number but a block of memory, endianness does not really apply). In
// practice, a key taken from the TTN console can be copied as-is.
static const u1_t PROGMEM APPKEY[16] = { FILLMEIN };
void os_getDevKey (u1_t* buf) { memcpy_P(buf, APPKEY, 16);}

// payload to send to TTN gateway
static uint8_t payload[5];
static osjob_t sendjob;

// Schedule TX every this many seconds (might become longer due to duty
// cycle limitations).
const unsigned TX_INTERVAL = 30;

// Pin mapping for Adafruit Feather M0 LoRa
// /!\ By default Adafruit Feather M0's pin 6 and DIO1 are not connected.
// Please ensure they are connected.
const lmic_pinmap lmic_pins = {
.nss = 8,
.rxtx = LMIC_UNUSED_PIN,
.rst = 4,
.dio = {3, 6, LMIC_UNUSED_PIN},
.rxtx_rx_active = 0,
.rssi_cal = 8, // LBT cal for the Adafruit Feather M0 LoRa, in dB
.spi_freq = 8000000,
};
const unsigned TX_INTERVAL = (60 * 15);

// init. DHT
DHT dht(DHTPIN, DHTTYPE);
Expand Down Expand Up @@ -258,26 +217,34 @@ void do_send(osjob_t* j){
}

void setup() {
delay(5000);
while (! Serial);
Serial.begin(9600);
while (!Serial)
delay(100);

Serial.begin(115200);
Serial.println(F("Starting"));

dht.begin();

// LMIC init
os_init();
// initialize runtime env
// don't die mysteriously; die noisily.
const lmic_pinmap *pPinMap = Arduino_LMIC::GetPinmap_ThisBoard();

if (pPinMap == nullptr) {
pinMode(LED_BUILTIN, OUTPUT);
for (;;) {
// flash lights, sleep.
for (int i = 0; i < 5; ++i) {
digitalWrite(LED_BUILTIN, 1);
delay(100);
digitalWrite(LED_BUILTIN, 0);
delay(900);
}
Serial.println(F("board not known to library; add pinmap or update getconfig_thisboard.cpp"));
}
}
os_init_ex(pPinMap);
// Reset the MAC state. Session and pending data transfers will be discarded.
LMIC_reset();
// Disable link-check mode and ADR, because ADR tends to complicate testing.
LMIC_setLinkCheckMode(0);
// Set the data rate to Spreading Factor 7. This is the fastest supported rate for 125 kHz channels, and it
// minimizes air time and battery power. Set the transmission power to 14 dBi (25 mW).
LMIC_setDrTxpow(DR_SF7,14);
// in the US, with TTN, it saves join time if we start on subband 1 (channels 8-15). This will
// get overridden after the join by parameters from the network. If working with other
// networks or in other regions, this will need to be changed.
LMIC_selectSubBand(1);

// Start job (sending automatically starts OTAA too)
do_send(&sendjob);
Expand Down
57 changes: 57 additions & 0 deletions examples/ttn-otaa-feather-dht22/ttn-secrets.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
LoRa secrets file

Copyright (c) 2021,2022 P. Oldberg <[email protected]>

Permission is hereby granted, free of charge, to anyone
obtaining a copy of this document and accompanying files,
to do whatever they want with them without any restriction,
including, but not limited to, copying, modification and redistribution.
NO WARRANTY OF ANY KIND IS PROVIDED.
*/

/* Here you fill in the OTAA credentials of your TTN device */
#define APPEUI_DATA // 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
#define DEVEUI_DATA // 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xD5, 0xB3, 0x70
#define APPKEY_DATA // 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX

#define REGRESSION_TEST_DATA 0

//
// For normal use, we require that you edit the sketch to replace FILLMEIN
// with values assigned by the TTN console. However, for regression tests,
// we want to be able to compile these scripts. The regression tests define
// COMPILE_REGRESSION_TEST, and in that case we define FILLMEIN to a non-
// working but innocuous value.
//
#if defined(COMPILE_REGRESSION_TEST)
# if defined(APPEUI_DATA)
# undef APPEUI_DATA
# define APPEUI_DATA REGRESSION_TEST_DATA
# endif
# if defined(DEVEUI_DATA)
# undef DEVEUI_DATA
# define DEVEUI_DATA REGRESSION_TEST_DATA
# endif
# if defined(APPKEY_DATA)
# undef APPKEY_DATA
# define APPKEY_DATA REGRESSION_TEST_DATA
# endif
#endif

// EUI's must be in little-endian format, so least-significant-byte
// first. When copying an EUI from ttn console, this means to reverse
// the bytes. For TTN issued EUIs the last bytes should be 0xD5, 0xB3,
// 0x70.
static const u1_t PROGMEM APPEUI[8] = { APPEUI_DATA };
void os_getArtEui (u1_t* buf) { memcpy_P(buf, APPEUI, 8);}

// This should also be in little endian format, see above.
static const u1_t PROGMEM DEVEUI[8] = { DEVEUI_DATA };
void os_getDevEui (u1_t* buf) { memcpy_P(buf, DEVEUI, 8);}

// This key should be in big endian format (or, since it is not really a
// number but a block of memory, endianness does not really apply). In
// practice, a key taken from ttnctl can be copied as-is.
static const u1_t PROGMEM APPKEY[16] = { APPKEY_DATA };
void os_getDevKey (u1_t* buf) { memcpy_P(buf, APPKEY, 16);}
Loading