Ir al contenido

Configuración previa​

Antes de intentar enviar mensajes a través de LoRaWAN, asegúrate de haber registrado tu dispositivo en The Things Network Stack, como se vio en el capítulo de​ configuración de LoRaWAN .

Además, instala la biblioteca lmic para propósitos LoRaWAN.​


Fragmento de código

El código a utilizar se encuentra en Arduino IDE -> File -> Examples -> MCCI LoRaWAN LMIC library -> ttn-otaa. Debajo se muestra el inicio del código.

#include <lmic.h>
#include <hal/hal.h>
#include <SPI.h>

//
// 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 ttnctl can be copied as-is.
static const u1_t PROGMEM APPKEY[16] = { FILLMEIN };
void os_getDevKey (u1_t* buf) {  memcpy_P(buf, APPKEY, 16);}

static uint8_t mydata[] = "Hello, world!";
static osjob_t sendjob;

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

// Pin mapping
const lmic_pinmap lmic_pins = {
    .nss = A5,
    .rxtx = LMIC_UNUSED_PIN,
    .rst = 3,
    .dio = {LMIC_UNUSED_PIN, LMIC_UNUSED_PIN, LMIC_UNUSED_PIN},
};

En el capítulo anterior creaste el dispositivo final y generaste 3 claves diferentes (JoinEUI, DevEUI y AppKey). En este fragmento de código debes modificar las variables APPEUI (JoinEUI), DEVEUI y APPKEY con sus valores correspondientes. Ten cuidado con el formato de las variables (consulta la siguiente tabla para establecer los valores correctos).

TTN JoinEUI

0000000000000000

IDE APPEUI

{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}

TTN DevEUI

0011223344556677

IDE DEVEUI

{0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, 0x00}

TTN AppKey

00112233445566778899AABBCCDDEEFF

IDE APPKEY

{0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF}

Además de las claves, según el PLC que uses (Ardbox o M-Duino), los pines lmic_pins variarán.

  • NSS: 12 (M-Duino) o A5 (Ardbox)
  • RST: 13 (M-Duino) o 3 (Ardbox)
Calificación
0 0

No hay comentarios por ahora.

para ser el primero en comentar.