IOTA

 
 
IOTA is an open-source distributed ledger. It uses a directed acyclic graph (DAG) instead of a blockchain.
IOTA's DAG is referred to as the tangle, and is a generalization of the block chain protocol.

More information about IOTA can be found at:
http://iota.org/







Send DHT11 sensor data using the Arduino Uno, HopeRF RFM95 LoRa transceiver and The Things Network to IOTA Tangle using Masked Authenticated Messaging (MAM)



Information
The source codes used in this tutorial can be found at:
https://github.com/robertlie/dht11-ttn-rfm95

Operating system used
macOS 10.13 High Sierra

Hardware used
  • The Things Gateway
    https://www.thethingsnetwork.org/docs/gateways/gateway/

    Specification:
    • LoRaWAN compatible
    • 868 MHz (EU) or 915 MHz (US) Microchip LoRa module
    • Provides up to 10 km / 6 miles radius of network coverage
    • Can serve up to 10000 nodes (depending on traffic)
    • Connects easily to your WiFi or Ethernet connection
    • Contains a XBEE slot for future connectivity protocols or homebrew add-ons
    • Security through the https connection and embedded in the LoRaWAN protocol
    • Devices can freely communicate over all gateways connected to The Things Network
    • Bluetooth 4.2 included
    • Engage with a global community of IoT developers
    • Easy cloud integration with popular IoT platforms
    • Based on open source hardware and software standards
    • Use a 868 MHz / 915 MHz tuned, 50 Ohm impedance antenna for use with the SMA connector

    The Things Gateway top view

    The Things Gateway bottom view

    The Things Gateway cover removed

    The Things Gateway board

    The Things Gateway LoRa module

    The Things Gateway antenna connector

    The Things Gateway antenna length

    The Things Gateway power and ethernet connection

  • The Things Gateway power supply (length: 1.50 m)

    The Things Gateway power supply

  • LoRa node: Arduino Uno rev3.0 + HopeRF RFM95 LoRa transceiver module + copper 868MHz coil antenna

    Arduino Uno rev 3.0 with HopeRF RFM95 LoRa transceiver module

    How to create a LoRa node using Arduino Uno and HopeRF RFM95 LoRa transceiver module, see:
    Build LoRa node using Arduino Uno and HopeRF RFM95 LoRa transceiver module

    How to create a copper 868MHz coil antenna, see:
    Build a copper 868MHz coil antenna

  • Jumper wires (3x female-male; 20 cm long, 2x male-male; 20 cm long)

    Jumper wires female-male

  • DHT11 sensor module (DHT = Digital Humidity Temperature)

    Specification:
    Supply voltage: 3.3 ~ 5.5V DC
    Output: single-bus digital signal
    Measuring range: humidity 20-90% RH, temperature 0 ~ 50°C
    Accuracy: humidity ±5% RH, temperature ±2°C
    Resolution: Humidity 1% RH, temperature 1°C
    Long-term stability: < ±1% RH / Year

    DHT11 sensor

Software prerequisites
none


Procedure
  1. Before you start, please note this tutorial was specifically written for macOS users.

    A. I asume you have The Things Gateway and have activated it, see:



    Note:
    You do not need The Things Gateway (= LoRa Gateway) if there is one nearby and is connected to The Things Network.
    To check if a LoRa Gateway is nearby and is connected to The Things Network:
    https://www.thethingsnetwork.org/map

    B. I asume you already created a LoRa node using Arduino Uno and HopeRF RFM95 LoRa transceiver module with a copper 868MHz coil antenna attached, see:
    Build LoRa node using Arduino Uno and HopeRF RFM95 LoRa transceiver module
    Build a copper 868MHz coil antenna

    This LoRa node works on 868mhz. Do not use this LoRa node if your region does not support it, otherwise you break the law!

    If you have followed step B tutorials you will end up with the HopeRF RFM95 LoRa transceiver module wired to the Arduino Uno (R3) as described in the wiring diagram below:

    HopeRF RFM95 LoRa transceiver module Arduino Uno Pin    HopeRF RFM95 LoRa transceiver module Arduino Uno 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 coil 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)



  2. Connect the DHT11 sensor module to the Arduino Uno using the jumper wires.

    Arduino Uno DHT11
    GND GND
    pin 7 DATA
    3.3V VCC

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

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



    DHT11 sensor module connected to Arduino Uno

  3. I assume you already have created an account on The Things Network and created an application in the Things Network console (eg: diy_node_otaa).

  4. Here is an example how a device is registered.

    Register a device

    Enter the Device ID: arduino_rfm95
    Enter Device EUI: 0011AABBCCDDEEBB (arbitrary chosen id)
    The App Key and App EUI are auto generated.

    Note:
    The HopeRF RFM95 LoRa transceiver module has NO hardcoded EUI like the Things Uno.
    You just need to enter an arbitrary unique Device EUI, consisting of 16 hex characters (0-9A-F).

  5. Download the dht11-ttn-rfm95 project on your computer:
    Type: git clone https://github.com/robertlie/dht11-ttn-rfm95.git

  6. We need to modify the dht11-ttn-rfm95/sketches/ttn-otaa-dht11/ttn-otaa-dht11.ino sketch.
    • Start Arduino IDE.
    • Modify the ttn-otaa-dht11.ino sketch, select menu: File > Select the ttn-otaa-dht11.ino file.
      Update the APPEUI, DEVEUI and APPKEY according to your situation.

      static const u1_t PROGMEM APPEUI[8]={ 0x38, .. };
      static const u1_t PROGMEM DEVEUI[8]={ 0xBB, .. };
      static const u1_t PROGMEM APPKEY[16] = { 0xD4, .. };


      You can find these values in The Things console (Devices).
      For APPEUI and DEVEUI make sure you select lsb (least significant byte first) display.
      For APPKEY make sure you select msb (most significant byte first) display.

      APPEUI, DEVEUI and APPKEY

    • Use the Arduino IDE Library Manger and install the following libraries:
      • IBM LMIC framework (by IBM)
      • DHT sensor library (by Adafruit)

    • The IBM LMIC framework library is installed in folder (in MacOS):
      homedir/Documents/Arduino/libraries/arduino-lmic-master

    • 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
        Disable this feature. It is not needed and space is freed up.
      • Uncomment line: #define DISABLE_BEACONS
        Disable this feature. It is not needed and space is freed up.

    • Select menu: Tools > Board > Arduino/Genuino Uno
    • Select the port, select menu: Tools > Port > /dev/cu.usbmodem1421
      Note: Your port name may differ.
    • Press the verify button to verify the sketch. Make sure there are no errors.
    • Press the upload button to upload the sketch to the Arduino Uno.
    • Open the Serial monitor, select menu: Tools > Serial Monitor.
      Make sure the baud rate is set to 9600 baud (bottom right)

      Sketch output displayed in serial monitor

      The temperature and humidity is displayed every 60 second.

    • Log into The Things Network console.
      Select the correct app and device to see the logged data.

      The Things Network console

      Note:
      To display readable data, the following decoder payload function format is used:

      function Decoder(bytes, port) {
         var humidity = (bytes[0]<<8) | bytes[1];
         var temperature = (bytes[2]<<8) | bytes[3];
         return {
            humidity: humidity/ 100,
            temperature: temperature/100
         }
      }


      As demonstrated The Things Network server receives the temperature and humidity data.

    • Close the serial monitor

  7. Test if the temperature and humidity data can be extracted from The Things Network server using a nodeJS application. This node application in turn stores the sensor data on the Tangle using Masked Authenticated Messaging.
    • Open a terminal
    • Type: cd dht11-ttn-rfm95
    • Modify the dht_ttn_mam.js file by entering your appID and accessKey.

      The appID can be found here:
      Application ID

      The accessKey can be found here:
      Access key

    • Type: node dht_ttn_mam.js

      dht_ttn_mam.js output

    • Open another terminal and type: node mam_receive.js your_root
      The stored data is displayed.

      mam_receive.js output