Transport Tutorial Part 0: Installation and Setup

This document will explain how to prepare your computer for the workshop.

Requirements

Hardware

  • Computer

  • Raspberry Pi Zero W (running a headless Raspbian Buster lite)

  • Class 10 SDCard

  • A generic analog light sensor based on an LDR

  • Jumper cables

  • USB <→ Micro-USB cable

Software Prerequisites

Basic requirements for all machines (Installation guide by Lisk).:

  • A code editor like Visual Studio Code

  • Git

  • Python 2

  • Node.js v10 (use nvm for easy switching between versions in case you have a different version installed)

  • Postgres 10

1.0 Setup

Set up the needed software and hardware and installation of the dependencies.

Clone the repo and install the dependencies

The below steps describe how to create the initial files for this tutorial.

  1. Clone the Lisk-SDK-Examples repository locally.

    git clone https://github.com/LiskHQ/lisk-sdk-examples.git
    cd lisk-sdk-examples
    cd transport

    The basic file structure looks as following:

    Contents of lisk-sdk-examples/transport
    .
    ├── README.adoc
    ├── Workshop.adoc
    ├── client                                          (1)
    │   ├── accounts.json
    │   ├── app.js
    │   ├── package.json
    │   ├── scripts
    │   └── views
    ├── iot                                             (2)
    │   ├── README.md
    │   ├── lisk_rpi_ldr_and_temperature_sensors_wiring.png
    │   ├── light_alarm
    │   │   ├── package.json
    │   │   └── index.js
    ├── node                                            (3)
    │   ├── index.js
    │   └── package.json
    └── transactions                                    (4)
        ├── finish-transport.js
        ├── light-alarm.js
        ├── register-packet.js
        └── start-transport.js
    1 Contains the code for the client application
    2 Contains the code for the IoT application
    3 Contains the code for the node application
    4 Contains the custom transactions, that are used by the node and client app.
  2. Navigate inside transport/transactions and transport/node folders and run npm install to install the required dependencies for the node application.

    cd transactions
    npm install
    cd ../node
    npm install
  3. Setup the database:

    1. You can skip this step unless you have experimented before with Lisk. If yes, it is possible you have to first drop your database and recreate it with: dropdb lisk_dev && createdb lisk_dev --owner lisk.

  4. To verify if the setup is correct, try to run the application with

    node index.js | npx bunyan -o short

    This command will run the index.js file and pipe the outputted logs to our preferred log formatting tool Bunyan. Starting the node for the first time might require some time (up to 3 minutes)!

If everything is running fine, you can stop the node by hitting CTRL+C.

In case the node crashes or doesn’t work, follow the this guide to set up a dedicated development environment using Docker and Docker-Compose. The script will set up the whole environment. If you decide to follow this guide, you can skip the rest of this document

Prepare the IoT device

Example 1. Reference: Raspberry Pi set up
Sensor wiring

RPI Wiring

Preparing the Operating System

The operating system for the Raspberry needs to be copied from a computer into an SD card for this we recommend using https://www.balena.io/etcher/ (good tutorial in https://medium.com/@ccarnino/backup-raspberry-pi-sd-card-on-macos-the-2019-simple-way-to-clone-1517af972ca5)

For preparing the Raspberry for ssh and wifi access follow this guide: https://core-electronics.com.au/tutorials/raspberry-pi-zerow-headless-wifi-setup.html

As we want to run the Raspberry in headless mode (i.e. no keyboard, mouse and monitor) we need to also enable ssh through USB. To do so follow this guide https://desertbot.io/blog/ssh-into-pi-zero-over-usb Once all those steps are followed the SD card can be unmounted and inserted into the Raspberry SD card reader.

Already isntalled libraries for accessing sensor data

The pins in the Raspberry need some libraries before they can be used for communicating with different sensors. For installing the required libraries run:

  • sudo apt-get install wiringpi

  • sudo apt-get install pigpio

  • NodeJS can be installed with nvm

Connecting / Logging in to the Pi

For logging in into the Pi plug it using the usb port labeled usb wait about a minute for it to boot (the green light in the Pi will stop flashing when it’s done booting) and then open a terminal and:

  • ssh pi@raspberrypi.local

  • Type in the password — by default this is raspberry