/******************************************************************************* * Copyright (c) 2015 Thomas Telkamp and Matthijs Kooijman * * 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. * * This example sends a valid LoRaWAN packet with payload "Hello, * world!", using frequency and encryption settings matching those of * the (early prototype version of) The Things Network. * * Note: LoRaWAN per sub-band duty-cycle limitation is enforced (1% in g1, * 0.1% in g2). * * Change DEVADDR to a unique address! * See http://thethingsnetwork.org/wiki/AddressSpace * * Do not forget to define the radio type correctly in config.h. * *******************************************************************************/

// Set static session parameters. Instead of dynamically establishing a session // by joining the network, precomputed session parameters are be provided. #ifdef PROGMEM // On AVR, these values are stored in flash and only copied to RAM // once. Copy them to a temporary buffer here, LMIC_setSession will // copy them into a buffer of its own again. uint8_t appskey[sizeof(APPSKEY)]; uint8_t nwkskey[sizeof(NWKSKEY)]; memcpy_P(appskey, APPSKEY, sizeof(APPSKEY)); memcpy_P(nwkskey, NWKSKEY, sizeof(NWKSKEY)); LMIC_setSession (0x1, DEVADDR, nwkskey, appskey); #else // If not running an AVR with PROGMEM, just use the arrays directly LMIC_setSession (0x1, DEVADDR, NWKSKEY, APPSKEY); #endif

// 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.

// Disable link check validation LMIC_setLinkCheckMode(0);

// Set data rate and transmit power (note: txpow seems to be ignored by the library) LMIC_setDrTxpow(DR_SF7,14);

// In the original LMIC code, these config values were defined on the// gcc commandline. Since Arduino does not allow easily modifying the// compiler commandline, use this file instead.

#define CFG_eu868 1//#define CFG_us915 1// This is the SX1272/SX1273 radio, which is also used on the HopeRF// RFM92 boards.//#define CFG_sx1272_radio 1// This is the SX1276/SX1277/SX1278/SX1279 radio, which is also used on// the HopeRF RFM95 boards.#define CFG_sx1276_radio 1

// Set this to 1 to enable some basic debug output (using printf) about// RF settings used during transmission and reception. Set to 2 to// enable more verbose output. Make sure that printf is actually// configured (e.g. on AVR it is not by default), otherwise using it can// cause crashing.#define LMIC_DEBUG_LEVEL 0

// Enable this to allow using printf() to print to the given serial port// (or any other Print object). This can be easy for debugging. The// current implementation only works on AVR, though.//#define LMIC_PRINTF_TO Serial

// Any runtime assertion failures are printed to this serial port (or// any other Print object). If this is unset, any failures just silently// halt execution.#define LMIC_FAILURE_TO Serial

// Uncomment this to disable all code related to joining//#define DISABLE_JOIN// Uncomment this to disable all code related to ping//#define DISABLE_PING// Uncomment this to disable all code related to beacon tracking.// Requires ping to be disabled too//#define DISABLE_BEACONS

// In LoRaWAN, a gateway applies I/Q inversion on TX, and nodes do the// same on RX. This ensures that gateways can talk to nodes and vice// versa, but gateways will not hear other gateways and nodes will not// hear other nodes. By uncommenting this macro, this inversion is// disabled and this node can hear other nodes. If two nodes both have// this macro set, they can talk to each other (but they can no longer// hear gateways). This should probably only be used when debugging// and/or when talking to the radio directly (e.g. like in the "raw"// example).//#define DISABLE_INVERT_IQ_ON_RX

// This allows choosing between multiple included AES implementations.// Make sure exactly one of these is uncommented.//// This selects the original AES implementation included LMIC. This// implementation is optimized for speed on 32-bit processors using// fairly big lookup tables, but it takes up big amounts of flash on the// AVR architecture.// #define USE_ORIGINAL_AES//// This selects the AES implementation written by Ideetroon for their// own LoRaWAN library. It also uses lookup tables, but smaller// byte-oriented ones, making it use a lot less flash space (but it is// also about twice as slow as the original).#define USE_IDEETRON_AES