SimpleLMIC

  • by

LMIC means LoRaWAN-MAC-in-C and the most popular is the arduino-lmic library, the problem is the library is a little low level and for noobs is a little confusing to work with.

One solution is to use the arduino-lorawan library that uses the main arduino-lmic and provides a higher level, more Arduino-like wrapper which may be useful. But it is not noob friendly.

That’s the idea of the SimpleLMIC library, which uses the same arduino-lmic library behind but cut some corners and make it easy to connect to the TTN.

#include <SimpleLMIC.h>

const char *devAddr = "11111111";
const char *nwkSKey = "11111111111111111111111111111111";
const char *appSKey = "11111111111111111111111111111111";

const lmic_pinmap lmic_pins = {
  .nss = SS,
  .rxtx = LMIC_UNUSED_PIN,
  .rst = LMIC_UNUSED_PIN,
  .dio = {DIO0, DIO1, LMIC_UNUSED_PIN}
};

SimpleLMIC ttn;

void setup() {
  Serial.begin(115200);
  Serial.println();
  
  ttn.begin();
  ttn.onMessage(message);
  ttn.personalize(devAddr, nwkSKey, appSKey);
}

void loop() {
  ttn.loop();
  if (!ttn.isBusy())
  {
    Serial.println("Not Busy!");
    delay(5000);
    ttn.print("Hello World");
    ttn.send();
  }
}

void message(uint8_t *payload, size_t size, uint8_t port)
{
  Serial.println("Received " + String(size) + " bytes on port " + String(port));
  switch (port) {
    case 1:
      break;
  }
}

This example show the ABP connection using the credential of the TTN network. Of course, you need to select yours and change the SS, DIO0, and DIO1 of your board.

The library is in work progress, but the main code already works.

https://github.com/ricaun/SimpleLMIC

If you want to use this library with some Arduino board, be award it uses a lot of memory and it should not possible to make work.

See yaa!