NodeJS REST API to authenticate a device and to track objects by publishing positioning data to the IOTA tangle. You can use this repo together with my other repository tracking_app.
Prerequisites
- Raspberry Pi (I used the model 3B+) with internet connection
- GNSS-Module SAM-M8Q from u-blox
- NodeJS installed on your Raspi
- The Node process manager PM2 installed on your Raspi (
npm install pm2 -g
)
Installation
You can download this repo to your Raspberry Pi and then run npm install
to install all dependencies automatically.
npm-modules (also visible in package.json-file):
- @iota/mam v.0.7.3
- cors v.2.8.5
- crypto-js v.3.1.9-1
- express v.4.17.1
- gps v.0.5.3
- jsonwebtoken v.8.5.1
- serialport v.0.8.3
- uuid v.3.3.3
To install a npm module run npm install module_name
.
To connect your GNSS-module SAM-M8Q you can use a UART-connection:
Check this tutorial to see how GPS-data from the serial port can be viewed on the Raspberry Pi.
Run
To run your API run node api.js
. You should see something like this in your browser if successful:
If you want to keep your API running and start it automatically when the Raspi is booting, you can use PM2: pm2 start api.js
To view if your API is running, run: pm2 list
For more commands visit the pm2 official website
These API-functions are currently available:
Authenticate To authenticate the raspberry by receiving a credential from the Raspberry Pi (which can be compared with a hashed credential on the IOTA tangle)
call: http://raspi_url:3000/authenticate
returns a credential in form of a JSON web token. The token is signed using a private key (available in this repo - NOT safe for production)
Start tracking
To start a tracking (publish GNSS data over the tangle) with pm2
call: http://raspi_url:3000/create-tracking
returns true if the tracking could be started and false if an error occured (e.g. a tracking process is already running)
Stop tracking
To stop tracking with pm2
call: http://raspi_url:3000/stop-tracking
returns true if the tracking could be stopped and false if an error occured (e.g. no tracking process is running that could be stopped)
Please open an issue for support.
Please contribute using Github Flow. Create a branch, add commits, and open a pull request.
Credits to the IOTA foundation whose tutorials helped me to realize this project.