Skip to content

Installing the HTTP Streams Gateway

Daniel De Michele edited this page Nov 12, 2020 · 4 revisions

Now that we understand what the I2T Standard is and went through the different endpoints that the Streams Gateway mounts, we will learn how to install the IOT2TANGLE HTTP Streams Gateway

Preparation

Install Rust if you don't have it already, find the instructions here https://www.rust-lang.org/tools/install

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

After the installation, add cargo to your $HOME env vars

source $HOME/.cargo/env

Update your repositories and install the needed build dependencies.

sudo apt update && apt install build-essential pkg-config libssl-dev 

Installing the streams-gateway

Download the Repository:

git clone https://github.com/iot2tangle/Streams-http-gateway.git

Configure the streams-gateway:

The config.json file is where you will allow access to the IoT Devices you want to send data to the Gateway. Keep in mind that the Device ID you define here needs to match what you defined on the devices config files, otherwise the Gateway will reject the POST requests received, returning an "Unauthorized Device" message.

nano config.json`  

You can also define a different port for the Gateway (8080, by default) and which Full Node you will use to do the Proof of Work.

{
    "whitelisted_device_ids": [
        "DEVICE_ID_1",
        "DEVICE_ID_2"
    ],
    "port": 8080,
    "node": "https://nodes.iota.cafe:443",
    "mwm": 14,
    "local_pow": false
}

Start your Gateway

cargo run --release`  

This starts the server which will forward messages from the devices to the Tangle

The Output will be something like this:

>> Starting....

>> Listening on http://0.0.0.0:8080

Test your Gateway

Before you have your IoT Device sending data to the Gateway, run a test with Postman or cURL to be sure that the Gateway is working. Let's use cURL to test different endpoints

POST /sensor_data

curl --location --request POST '127.0.0.1:8080/sensor_data' --header 'Content-Type: application/json' --data-raw '{ "iot2tangle": [ { "sensor": "Gyroscope", "data": [ { "x": "4514" }, { "y": "244" }, { "z": "-1830" } ] }, { "sensor": "Acoustic", "data": [ { "mp": "1" } ] } ], "device": "DEVICE_ID_1", "timestamp": 1558511111 }'
Note: If the "timestamp" value is set to 0 a new timestamp will be added by the realy server before the data is published to the Tangle.

POST /switch_channel

curl --location --request POST '127.0.0.1:8080/switch_channel' --header 'Content-Type: application/json' --data-raw '{"device": "DEVICE_ID_1"}'

POST /current_channel

curl --location --request GET '127.0.0.1:8080/current_channel' \ --header 'Content-Type: application/json' \ --data-raw '{ "device": "DEVICE_ID_1" }'

REMEMBER: The device will be authenticated through the "device" field in the request (in this case we left the default DEVICE_ID_1). This has to match what was set as device_name in the config.json on the Gateway (see Configuration section above)!