Install the software prerequisites
Development Environment Prerequisites
Getting The App Running (Raspberry Pi)
Getting The App Running (Linux)
Login With The User You Just Created
Test To See If The App Is Running
Add Data To The Database Using HTTP
Add Data To The Database Using MQTT
Once you have your Raspberry Pi or Server set up download the following (instructions below):
On your server or Raspberry Pi, run these commands:
$ sudo apt-get update
$ curl -fsSL get.docker.com -o get-docker.sh && sh get-docker.sh
$ sudo apt install python3-pip -y
$ sudo pip3 install docker-compose==1.12.0
$ sudo apt install git -y
Follow these commands only if you are using a Raspberry Pi.
$ sudo apt install mosquitto -y
$ sudo touch /etc/mosquitto/conf.d/bridge.conf
$ sudo nano /etc/mosquitto/conf.d/bridge.conf
add the following:
connection bridge-central
address *CENTRAL-SERVER-IP*:1883
topic forest out 0
$ sudo systemctl restart mosquitto
Make sure you have installed on your computer:
$ git clone https://github.com/saycel/black-rock-forest-store-and-forward
$ cd black-forest
Add the following to .env file
POSTGRES_PASSWORD=postgres
POSTGRES_DB=brfc
PYTHONPATH=/brfc
$ sudo docker-compose -f docker-compose.raspberry.yml build
$ sudo docker-compose -f docker-compose.raspberry.yml up -d
$ git clone https://github.com/saycel/black-rock-forest-store-and-forward
$ cd black-forest
Add the following to .env file
POSTGRES_PASSWORD=postgres
POSTGRES_DB=brfc
PYTHONPATH=/brfc
$ sudo docker-compose build
$ sudo docker-compose up
We recommend running the app in Vagrant if you are using a Mac. Follow the steps to install and run the project:
$ brew install vagrant
$ vagrant plugin install vagrant-docker-compose
$ cd black-forest
$ vagrant up
Note: the ip of the VM is 192.168.33.10
$ cd black-forest
$ git pull
$ sudo docker-compose stop
$ sudo docker-compose build
$ sudo docker-compose up
To start using the platform you need to first add a user by sending a json post request to http://SERVER-IP:2323/user/register with a username and password.
{
"email": "avalid@email.com",
"password": "4veryS4vePass!!"
}
Once you have added a user, to get a token send a post request to http://SERVER-IP:2323/user/register with the following json payload:
{
"email": "avalid@email.com",
"password": "4veryS4vePass!!"
}
you will receive a response with a JWT token like this:
{
"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJlbWFpbCI6InRlc3RlckBnZXJtYW4uY29tIiwidmFsaWRfdW50aWwiOiIyMDIwLTAzLTE2IDE1OjMzOjQ2LjEwNDEyMCJ9._g1OMeiEoLaM7e3eiSjHcV5pKi05MaMzJVzNTMq8LL8"
}
In order to know if the app's REST API is up and running,first make sure the the pc where you installed Postman and the Server or Raspberry Pi where the app is running are on the same LAN. Then follow these steps:
- Get the IP address of your Server or Raspberry Pi
- In Postman create a post request
- In the url textbox: http://RPI-IP:2323/login
- Click in the Authorization tab and choose Basic Auth type.
- The username and password are the same as the ones you added earlier.
- Click the send button next to url textbox.
- You should receive a json response: {"message": "success"}
Send a GET request using the following API format:
Generic:
http://RPI-IP:2323/sensor/collector/<app_key>/<net_key>/<device_id>/?chN=n
Example:
http://10.0.0.115:2323/sensor/collector/1234/abc/x1v3/?ch1=1&ch2=2
- open postman
- use http://RPI-IP:2323/<app_key>/<net_key>/<device_id>/?chN=n
- click the send button next to url textbox
- after send the request if everything goes ok, you will receive a success message
Send an MQTT request using the following format:
host:CENTRAL-SERVER-IP port:1883 topic: forest protocol: mqtt/tcp
Generic:
{
"app_key": "application key",
"device_id": "node unique identifier",
"net_key": "network key",
"channels": {
"ch1": "float as string",
"ch2": "float as string",
"chN": "float as string"
}
}
Example:
{
"app_key": "1",
"device_id": "3",
"net_key": "2",
"channels": {
"ch1": "1",
"ch2": "2"
}
}
Send a GET request using the following API format:
Generic: http://RPI-IP:2323/sensor/all
Example:
http://10.0.0.115:2323/sensor/all
Add the following request headers:
Authorization=JWT-TOKEN-GENERATED-BEFORE
- open postman
- use http://RPI-IP:2323/sensor/all
- click the send button next to url textbox
- In case you have records in the db you will receive a list of json
[
{
"app_key": "1",
"channels": {
"ch1": "1",
"ch2": "2"
},
"device_id": "3",
"net_key": "2"
},
{
"app_key": "dd",
"channels": {
"ch1": "1",
"ch2": "2"
},
"device_id": "ff",
"net_key": "ff"
}
]
We have swagger documentation, which you can find here: http://165.22.191.125:2323/swagger/
The first row must have the names of the columns. The second row must have the units of the columns. From the third line on, you will have your data. For example:
temperature, pressure
°C, hPa
12.0, 1000.0
The previous will be load in the database as
id | app_key | net_key | device_id | value | created_at | field_name | unit_string |
---|---|---|---|---|---|---|---|
1 | from_csv | from_csv | from_csv | 12.0 | 2014-11-2800:00:00 | temperature | °C |
2 | from_csv | from_csv | from_csv | 1000.0 | 2014-11-2800:00:00 | pressure | hPa |