-
Notifications
You must be signed in to change notification settings - Fork 4
Installing the HTTP Streams Gateway
Now that we understand what the I2T Standard is and that we have gone through the different endpoints that the Streams Gateway mounts, we will learn how to install the IOT2TANGLE HTTP Streams Gateway.
Before we get started, keep in mind that your Gateway can be installed on your local computer, a Raspberry Pi or a VPS.
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
git clone https://github.com/iot2tangle/Streams-http-gateway.git
The config.json file is where you specify which IoT Devices are allowed to send data to the Gateway. Keep in mind that the specified Device IDs here need to match what is defined in the devices’ config file, 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
}
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
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 us use cURL to test different endpoints
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 relay server before the data is published to the Tangle.
curl --location --request POST '127.0.0.1:8080/switch_channel' --header 'Content-Type: application/json' --data-raw '{"device": "DEVICE_ID_1"}'
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 with the ID that was set as device_name in the config.json on the Gateway (see Configuration section above)!