Hello World

Estimated time: ~5 minutes

What you need

  1. EE-04, nRF52 DK with mBed Semtech shield or EE-02 with programming cable attached.
  2. EE-0x firmware source
  3. Development environment set up and working
  4. Account for CloudConnect or another LoRa backend

Configure the board

Open up the file config/nrf52_pins.h and ensure you’ve configured your firmware for your hardware. If you’ve got the EE-04 board or the EE-02 with a programming cable make sure EE02 is defined. If you are using the nRF52 DK make sure NRF52_DK is defined.

// Use this #define if you are using the nRF52 DK 
//#define NRF52_DK
// Use this #define if you are using EE-02 with a programming cable or EE-04
#define EE02

Create device credentials

If you haven’t created an account in your backend you should do so now. Create a new OTAA device (Instructions for Cloud Connect can be found here and open the file config/lora_config.h. A bit down you’ll find this section:

#define LORAWAN_OTAA 1

/* ==========================================================================
 * OTAA provisioning. This includes the device EUI, application EUI and 
 * application key. The application and network session keys will be 
 * negotiated when the device joins the network.
 * ========================================================================== */
// Device provisioning - replace this with EUI/device address and NwkSKey + AppSKey as required.
#define LORAWAN_DEVICE_EUI { 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08 }
#define LORAWAN_APP_KEY { 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F,0x10 }
#define LORAWAN_APP_EUI { 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08 }

Replace the values LORAWAN_DEVICE_EUI, LORAWAN_APP_EUI and LORAWAN_APP_KEY with the values from the backend.

Add hello world

Open up the file jobs/lora_job.c and modify the send_func function to look like this:

static void send_func(osjob_t* job) {
    uint8_t len = 0;
    LMIC.frame[len++] = 'H';
    LMIC.frame[len++] = 'e';
    LMIC.frame[len++] = 'l';
    LMIC.frame[len++] = 'l';
    LMIC.frame[len++] = 'o';
    LMIC.frame[len++] = '!';

    if (LMIC_setTxData2( PORTNO, LMIC.frame, len, LORAWAN_CONFIRMED_MSG_ON ) != 0) {
        NRF_LOG("LoRa: *** Error sending frame!\n");
    } else {
        NRF_LOG_PRINTF("LoRa: %d bytes scheduled for output", len);

Make and deploy

Build the firmware with make and ensure there are no errors or warnings. Plug your board into an USB port and make sure the USB drive appears. It should be named JLINK.

Deploy the new firmware to the device by running the command make deploy. After a few seconds the firmware will have deployed.

Check output

Launch the Segger debug viewer and check the output. It should say this after a few seconds:

EE0x Firmware. nRF52 serial 10322E23E51A30A3
LoRa: Init ...using OTAA
LoRa: Sending message...
LoRa: 6 bytes scheduled for output

Note that the serial number will be different for each nRF52 chip. You should now be able to see the output from your device in the backend. Depending on your backend the format will be different but this is a typical output:

      "DevAddr": "00000003",
      "Timestamp": 1489755705,
      "Data": "48656c6c6f21",
      "AppEUI": "00-09-09-00-00-00-00-00",
      "DeviceEUI": "00-09-09-00-00-00-00-03",
      "RSSI": -38,
      "SNR": 9,
      "Frequency": 868.3,
      "GatewayEUI": "02-4b-08-ff-ff-06-02-75",
      "DataRate": "SF7BW125"

That’s it!