LoRaWAN

 
 
LoRaWAN (Long Range Wide Area Network) is a specification for a telecommunication network suitable for long-distance communication with little power. The technology is used for machine-to-machine communication (Internet of Things).

The architecture consists of gateways, network servers and application servers. There are RF chips from Semtech used to transmit a spread spectrum.

More information about LoRaWAN can be found at:
https://www.lora-alliance.org/
https://www.thethingsnetwork.org/

rss feed






Build LoRa node using Arduino Uno and HopeRF RFM95 LoRa transceiver module



Information
none

Operating system used
macOS Sierra

Hardware used
  • Arduino Uno rev3.0

    Arduino uno rev 3.0 front

  • The HopeRF RFM95 LoRa transceiver module is marked RF96 which means the chip is using the SX1276 chip. The RFM95 and RFM95W are the same.
    W=CE/FCC version for worldwide, without W=internal Chinese market only.

    HopeRF RFM95 LoRa transceiver module top view

    Bottom view. The frequency used in Europe is 868 MHz, for North America 915 MHz and for Asia 433 MHz. Make sure your HopeRF RFM95 LoRa transceiver module has the correct frequency.

    HopeRF RFM95 LoRa transceiver module bottom view

    HopeRF naming rules, see: http://www.hoperf.com/faqs/410.html

    HopeRF naming rules

    More information about the HopeRF RFM95(W) LoRa transceiver module:
    The RFM95(W) Data Sheet

  • ESP8266 module adapter plate.

    ESP8266 module adapter plate

  • Solderless breadboard MB-102

    Solderless breadboard MB-102

  • Solderless breadboard SYB-170

    Solderless breadboard SYB-170

  • Jumper wires 20 cm long (6x male-male and 3x male-female)

    Jumper wires

  • Breakable male pin headers (only need 2 pins)

    Breakable male pin headers

  • USB 2.0 cable type A/B


    USB 2.0 cable type A/B

  • Insulated stranded copper wire 30AWG (conductor diameter = 0.254 mm).
    The wire will be used as an antenna.
    The wire must have a length (L) of:
    • 173 mm (f = 433 MHz, for Asia)
    • 86 mm (f = 868 MHz, for Europe)
    • 82 mm (f = 915 MHz, for North America)

    The antenna length (L) is calculated as follow:

    c = λ x f
    L = ¼ x λ

    c = speed of light = 299792458 m/s
    λ = wavelength (m)
    f = frequency = 868000000 Hz (This frequency applies to Europe)
    L = antenna length (m)

    299792458 = λ x 868000000
    λ = 0.34538 m
    λ = 345.38 mm
    L = ¼ x λ = 86 mm (This antenna applies for Europe)

    Insulated copper wire

Software prerequisites
none


Procedure
  1. Create a LoRa node, part 1: HopeRF RFM95 LoRa transceiver module v1.2



  2. Create a LoRa node, part 2: Prepare the module adapter plate



  3. Create a LoRa node, part 3: Solder the LoRa module on the adapter plate



  4. Create a LoRa node, part 4: Attach antenna to the LoRa module



  5. Make the following jumper wire connections between the HopeRF RFM95 LoRa transceiver module and the Arduino Uno (R3).

    HopeRF RFM95 LoRa transceiver module Arduino Uno    HopeRF RFM95 LoRa transceiver module Arduino Pin
    ANT -    GND -
    GND GND    DIO5 -
    DIO3 -    RESET 5
    DIO4 -    NSS 10
    3.3V 3.3V    SCK 13
    DIO0 2    MOSI 11
    DIO1 3    MISO 12
    DIO2 -    GND -


    ANT = Antenna
    GND = Ground
    DIO = Digital Input/Output
    NSS = Slave Select
    SCK = Serial Clock (output from master)
    MOSI = Master Out Slave In (data output from master)
    MISO = Master In Slave Out (data output from slave)


    Note:
    • Attach wire antenna to ANT pin.
    • The HopeRF RFM95 LoRa transceiver module has 3 GND pins. It does not matter which GND pin you use. Use at least one.
    • Do not use DIO2
    • The Arduino Uno uses SPI (Serial Peripheral Interface) to communicate with the LoRa transceiver module. The Arduino Uno is the Master and the LoRa transceiver module is the Slave.

    Wiring HopeRF RFM95 LoRa transceiver module and Arduino Uno (R3).
    Click on the image for a larger image.

    Wiring HopeRF RFM95 LoRa transceiver module and Arduino Uno (R3)



    Arduino Uno and LoRa module wiring 1

    Arduino Uno and LoRa module wiring 2

    Arduino Uno and LoRa module wiring 3

    Arduino Uno and LoRa module wiring 4

    Arduino Uno and LoRa module wiring 5

    Arduino Uno and LoRa module wiring 6

  6. Create an account on https://www.thethingsnetwork.org/.

  7. Goto The Things Network console and register a Gateway.

    The Things Network console

    I assume you already have a Gateway.
    If not, checkout my tutorial Build LoRa gateway using Raspberry Pi 3 model B and Dragino LoRa shield v95 or watch my YouTube tutorial Single channel gateway with The Things Network

  8. Goto The Things Network console and add an application and register a device.

    For example: A "DIY Node" application is added.

    A Diy Node application is added

    For example: An "arduino_device" is added.

    An Arduino device is added

    When you register a device, make sure activation method "ABP" (Activation By Personalization) is selected and not OTAA (Over-the-Air Activation).

    Activation method ABP is selected

    Copy the Device Address (you will need it in step 16), for example: 26011622

    Device address

    Copy the Network Session Key (you will need it in step 16), for example: { 0x20, 0x59, 0x50, 0xE2, 0x28, 0xEA, 0x7E, 0x31, 0x02, 0x96, 0x5E, 0x71, 0xA9, 0xDF, 0x4F, 0x70 }

    Copy the App Session Key (you will need it in step 16), for example: { 0x0D, 0x8C, 0x58, 0xEC, 0x33, 0x64, 0x3F, 0x9E, 0x76, 0x60, 0xED, 0x96, 0xD4, 0x45, 0xB5, 0x6A }

    Note: To get these values, press the < > button until you see msb, then copy the values.

    Device address

    More information about this step, checkout my YouTube tutorial: Changes made by The Things Network.
    Watch timestamp 4:02 - 8:12.

  9. Start your Gateway. In this tutorial i am using a Single Channel LoRa Gateway

  10. Download the arduino-lmic library as zip file from:https://github.com/matthijskooijman/arduino-lmic

    Note:
    • Do not unzip the downloaded arduino-lmic-master.zip file
    • lmic = LoraMac in C

  11. If you are using MacOS Sierra (v10.12.1) install Arduino IDE 1.6.13 or the latest Arduino IDE 1.8.2.

  12. Install the arduino-lmic library in the Arduino IDE:
    • Select menu: Sketch | Include Library | Add .Zip Library

      Arduino IDE include Library

    • Select the downloaded arduino-lmic-master.zip file
    • Close and start the Arduino IDE
    • The arduino-lmic library can be found under menu: Sketch | Include Library | IBM LMIC framework

      IBM LMIC framework


  13. The arduino-lmic library is installed in folder (in MacOS):
    homedir/Documents/Arduino/libraries/arduino-lmic-master

  14. Modify file:
    ../arduino-lmic-master/src/lmic/config.h

    Make the following changes:
    • If you live in Europe, set: #define CFG_eu868 1
    • If you use a HopeRF RFM95 module, set: #define CFG_sx1276_radio 1
    • If you want logging in the serial monitor, set:
      #define LMIC_DEBUG_LEVEL 2
      #define LMIC_FAILURE_TO Serial
    • Uncomment line: #define DISABLE_PING
    • Uncomment line: #define DISABLE_BEACONS

  15. Select menu: File | Examples | IBM LMIC framework | ttn-abp

    Sketch ttn_abp.ino

  16. Modify sketch ttn-abp.ino:

    • Copy the Network Session Key in constant variable:

      static const PROGMEM u1_t NWKSKEY[16] = { 0x20, 0x59, 0x50, 0xE2, 0x28, 0xEA, 0x7E, 0x31, 0x02, 0x96, 0x5E, 0x71, 0xA9, 0xDF, 0x4F, 0x70 };

    • Copy the App Session Key in constant variable:

      static const u1_t PROGMEM APPSKEY[16] = { 0x0D, 0x8C, 0x58, 0xEC, 0x33, 0x64, 0x3F, 0x9E, 0x76, 0x60, 0xED, 0x96, 0xD4, 0x45, 0xB5, 0x6A };

    • Copy the Device Addres in constant variable (Do not forget the 0x prefix):

      static const u4_t DEVADDR = 0x26011622;

    • Change the Pin mapping.

      const lmic_pinmap lmic_pins = {
          .nss = 10,
          .rxtx = LMIC_UNUSED_PIN,
          .rst = 5,
          .dio = {2, 3, LMIC_UNUSED_PIN},
      };


      Explanantion:
      • LoRa module pin NSS (=.nss) is connected to Arduino pin 10

      • LoRa RFM95 module has no rxtx pin.

      • LoRa module pin RESET (.rst) is connected to Arduino pin 5

      • The 3 values in the .dio array {...}, refers to DIO0, DIO1 and DIO2 respectively.
        LoRa module pin DIO0 is connected to Arduino pin 2.
        LoRa module pin DIO1 is connected to Arduino pin 3.
        LoRa module pin DIO2 is not used.

    • The line static uint8_t mydata[] = "Hello, world!";
      contains the message which will be send fom the Lora module to the Gateway.

  17. Save this sketch file as ttn-abp-diy-arduino.ino.

  18. Connect the Arduino Uno to your computer, using the USB 2.0 cable type A/B.

  19. Select Arduino menu: Tools | Board | Arduino/Genuino Uno

    Select Arduino board

  20. Select Arduino menu: Port | /dev/cu.usbmodemFD131 (Arduino/Genuino Uno)

    Select port

  21. Load sketch ttn-abp-diy-arduino.ino and press the Arduino Verify button. There should be no errors and warnings.

  22. Upload the sketch to the Arduino Uno. There should be no errors and warnings.

  23. Open the Serial Monitor, select menu: Tools | Serial Monitor
    Select 115200 baud

    Open serial monitor

  24. Every 9 min the Single Channel LoRa Gateway will receive a message from the LoRa module.
    The message is encrypted.

    Single Channel LoRa Gateway received messages

  25. Login to the Things Network console and goto the "DEVICE OVERVIEW" screen.
    Press the link "reset frame counters"

    Reset frame counters on the Things Network console

  26. Select "Data" in the top right corner (see previous image). The received data is:
    48 65 6C 6C 6F 2C 20 77 6F 72 6C 64 21

    These are the hex values for "Hello, world!"

    Received data

  27. If you want to convert it into a readable text. Select your application for example "diy_node" and in the "APPLICATION OVERVIEW" screen, select "Payload Formats".

    Select "decoder" and paste the decoder payload format function in the textbox.

    Decoder payload function

    In the bottom of the page press the "save payload function" button.

    If you go back to "Data" you will see:

    Data decoded with payload format function