A REST API to complement the Smart Lego Truck Project
- Java JVM (>= 11)
- Maven (Apache Maven)
- DOCKER
-
Compile JAVA code
mvn clean package
-
Build dockers
docker-compose build
In order for the application to work, a Timescale DB, which is an extension of PostGresSQL, needs to be set up before the first run, in order to do that:
-
Start database
docker-compose up -d mypostgres
-
Copy the timescaleSetup.sql to your database
docker cp /FULL/PATH/TO/timescaleSetup.sql YOURCONTAINER:/timescaleSetup.sql
-
Connect to your database in the PostGresSQL container
docker exec -it myContainer psql -U demouser mydb
-
Run the setup script
\i timescaleSetup.sql
-
Start the application
docker-compose up
To access the Swagger documentation, using a browser connect to:
http://localhost:8080/lego/swagger-ui.html
http://localhost:8080/lego/v2/api-docs
The following environment variables have to be provided when executing the docker image:
#MQTT BROKER
MQTT_HOST=tcp://<host>
MQTT_PORT=<PORT>
MQTT_USER=<USERNAME>
MQTT_PASS=<PASSWORD>
# TIMESCALE DB
DB_INSTANCE=<HOST IP>
DB_PORT=<HOST PORT>
DB_USER=<USERNAME>
DB_PASS=<PASSWORD>
DB_NAME=<name of the database inside host>
# Security
SECURITY_USERNAME=<basic auth username>
SECURITY_PASSWORD=<basic auth password>
In the case that the Lego Truck project be expanded in the future to contain more sensors, their data can be acquired easily by adding it the message received method in MqttCallback class and well as implementing a handler for its message, alongside its extension of the Event class and its repository handler.