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 Raspberry Pi 3 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-raspi3

Operating system used
macOS 10.13 High Sierra

Hardware used
  • Raspberry Pi 3 model B v1.2 with pin diagram

    Raspberry Pi 3 model B with pin diagram

    Note:
    To verify this pin diagram, you need to install raspbian, open a terminal and type: gpio readall

  • (Optional) Raspberry Pi 3 case to protect the Raspberry Pi


    Raspberry Pi 3 case, class 10

  • Samsung EVO micro SDHC card (32GB, 48MB/s, class 10) with adapter.
    The SD card adapter is only needed if your SD card reader only accommodates normal sized SD cards.
    You can use a micro SD card with less storage space, for example 8-16 GB.

    Samsung EVO micro SDHC card, 32GB, 48MB/s with adapter, class 10

  • Raspberry Pi power supply.

    Raspberry pi power supply

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

    Jumper wires female-female

  • 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

  • After installing the Raspbian OS on the micro SD card, the Raspberry Pi needs to be setup. During this setup proces, the Raspberry Pi is connected to a monitor using a HDMI cable. A USB keyboard and mouse are connected to the Raspberry Pi. The Raspberry Pi 3 has WiFi capability.
    Note: After the setup process, the monitor, HDMI cable, keyboard and mouse are not needed.

    • Ethernet network cable, in case you have no access to a WiFi network.

      Ethernet cable

    • Monitor with HDMI connection, USB keyboard and mouse (only needed to setup the Raspberry Pi)

    • HDMI cable (to connect Raspberry Pi to monitor, only needed to setup the Raspberry Pi)


      HDMI cable

Software prerequisites
none

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

    Download and install SD card formatter v5.0.0 on your computer:
    https://www.sdcard.org/downloads/formatter_4/

  2. Download Raspbian (NOOBS): https://www.raspberrypi.org/downloads/noobs/
    • Check its checksum.
      Type (applies to macOS): shasum -a 256 NOOBS_v2_8_2.zip
    • Unpack the zip file.

  3. Format the micro SD card.
    • Open the SD Formatter application
    • Select card
      For example: disk2: APPLE SD Card Reader Media
    • Select Quick Format (FAT)
    • Specify card name: DEMO
    • Click Format button
    • When done, you see: Card Format complete!
    • The micro SD card now appears in the Finder.

    SDCard formatter screen

  4. Install and setup Raspbian on the micro SD Card.
    • Copy the NOOB content to the micro SD card.
      ONLY copy the contents inside the NOOBS_v2_8_2 folder and not the folder itself.
      NOTE: The NOOB size is approx 1.58 GB
    • Verify that all files are copied.
    • Eject the micro SD card, by clicking the Eject icon in Finder.
    • Remove the micro SD card and insert it into the Raspberry Pi 3.
    • Connect the following hardware to the Raspberry Pi:
      • Monitor using the HDMI cable
      • Mouse and keyboard
      • If WiFi is not available, an Ethernet cable
    • Power up the Raspberry Pi by connecting the power cable.
    • After bootup you see the screen: NOOB v2.8 - Built: Apr 18 2018
    • Select Raspbian (RECOMMENDED)
      A port of Debian Stretch for Raspberry Pi (full desktop version)
    • Select Install button (takes a while to install)
    • After setup, press OK, the Raspberry Pi is rebooted.
    • Press Next button
    • Set your Country, Language and Timezone, for example:
      Country: Netherlands
      Language: Dutch
      Timezone: Amsterdam
    • Enter Raspberry Pi account information, for example:
      User: pi
      Password: mysecret
    • Check for updates
    • Reboot the Raspberry Pi
    • After reboot:
      • Select Menu: Raspberry Pi configuration
      • Select Tab: Interfaces
      • Enable: SSH and VNC
    • If Wifi is available setup WIFI, click the network symbol (top right icon)
    • Setup VNC Connect:
      More info: https://www.realvnc.com/en/connect/docs/raspberry-pi.html#raspberry-pi-setup
      • Open a terminal
      • Type: sudo apt-get update
      • Type: sudo apt-get install realvnc-vnc-server realvnc-vnc-viewer
      • Get Raspberry Pi ip address, type: ifconfig
        For example: 192.168.1.70
    • Reboot the Raspberry Pi

  5. To access the Raspberry Pi thru your computer, install VNC viewer on your computer and connect to Raspberry Pi.

    • Download and install VNC Viewer:
      https://www.realvnc.com/en/connect/download/viewer/
    • In the opened window, enter the Raspberry Pi IP address, for example: 192.168.1.70

      VNC viewer

    • Login:
      User: pi
      Password: mysecret
    • You can now access the Raspberry Pi thru your computer.
      Monitor, keyboard and mouse can be removed from the Raspberry Pi.

      Raspberry Pi 3 screen

  6. Install Node.JS on the Raspberry Pi.
    • In the Raspberry Pi open a terminal:
      Type: curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
      Type: sudo apt-get install -y nodejs
      Check the Node.js version: node -v
      For example: v8.11.3

  7. Shutdown Raspberry Pi and remove power.

  8. Connect the DHT11 sensor module to the Raspberry Pi 3 using the three jumper wires.

    DHT11 sensor GND - RaspPi, GND (Black)
    DHT11 sensor DATA - RaspPi, GPIO 4 (White)
    DHT11 sensor VCC - RaspPi, 5V PWR (Red)

    DHT11 sensor connected to Raspberry Pi 3

    DHT11 sensor and Raspberry Pi 3 wiring

  9. For the communication between DHT11 sensor module and Raspberry Pi the BCM2835 library is used. This is a C library for Raspberry Pi. It provides access to GPIO and other IO functions on the Broadcom BCM 2835 chip, as used in the Raspberry Pi, allowing access to the GPIO pins on the 26 pin IDE plug on the RPi board so you can control and interface with various external devices.
    More info: http://www.airspayce.com/mikem/bcm2835/

    Download and build the BCM2835 library on the Raspberry Pi.
    • Power up the Raspberry Pi, login and open a terminal.
    • Download http://www.airspayce.com/mikem/bcm2835/bcm2835-1.56.tar.gz
      Type: wget http://www.airspayce.com/mikem/bcm2835/bcm2835-1.56.tar.gz
    • Build and install bcm2835-1.56:
      Type: tar zxvf bcm2835-1.56.tar.gz
      Type: cd bcm2835-1.56
      Type: ./configure
      Type: make
      Type: sudo make check
      Type: sudo make install

  10. Install git on the Raspberry Pi.
    Type: sudo apt-get install git

  11. Download and install the dht11-raspi3 project on the Raspberry Pi:
    • Type: cd ~
    • Type: git clone https://github.com/robertlie/dht11-raspi3.git

      dht11-raspi3 git repo cloned

    • Type: cd dht11-raspi3
    • Type: npm install

  12. The dht11-raspi3 project has 4 javascript files:
    • mam_publish.js: Publishes randomly generated numbers to the IOTA Tangle using MAM.
    • mam_receive.js: Extract the stored data from the IOTA Tangle using MAM and display the data.
    • sensor.js: The DHT11 sensor data (temperature and humidity) is read and displayed.
    • mam_sensor.js: The DHT11 sensor data is read and published to the IOTA Tangle using MAM.

  13. First execute the mam_publish.js to check if you can store data (randomly generated numbers) on the Tangle.
    • Open a terminal and type: node mam_publish.js
      Each stored data has a separate root. Copy a root which will be used in the next step.

      mam_publish.js output

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

      mam_receive.js output


    If there are any problems, fix it before you continue with the next step.

    Note:
    The full node endpoint and sidekey are both hardcoded in the javascript files.
    To stop a script from running, press CTRL+Z.

  14. Next execute sensor.js to check if the Raspberry Pi can read temperature and humidity data from the DHT11 sensor module.
    • Open a terminal and type: node sensor.js
    • The DHT11 sensor data is displayed.

      DHT11 sensor data

    If you have problems reading the DHT11 sensor data you can enable logging:
    Type: cd ~
    Type: cd dht11-raspi3
    Type: npm uninstall node-dht-sensor
    Type: npm install node-dht-sensor --dht_verbose=true

    After you have fixed your problem, disable logging:
    Type: npm uninstall node-dht-sensor
    Type: npm install node-dht-sensor --dht_verbose=false

    Make sure the sensor data is displayed before you continue with the last step.
    Note:
    To stop the script from running, press CTRL+Z.

  15. In this final step execute mam_sensor.js. This script will store the temperature and humidity data from the DHT11 sensor module to the Tangle.
    • Open a terminal and type: node mam_sensor.js
      Each stored sensor data has a separate root. Copy a root which will be used in the next step.

      mam_sensor.js output

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

      mam_receive.js output

    Note:
    The full node endpoint and sidekey are both hardcoded in the javascript files.
    To stop a script from running, press CTRL+Z.

  16. For more information, watch this video: