This repository contains the Pyrrha solution MQTT client that receives device readings from the mobile app via the IBM IoT Platform. The service then stores the data in the database and also sends it to the WebSocket service.
You need to have the following services running to use the MQTT client. The IoT platform runs on IBM Cloud. The database and websocket services can be run locally using Docker.
In order for the MQTT Client to communicate with the MQTT broker, information for the client should be added to VerneMQ's database table. The instructions for this can be found here.
You can run this solution locally as follows:
-
Copy
.env.sample
to.env
and fill out the values. The following values can be obtained from the IBM IoT platform as explained under theConnect an application to IBM Watson IoT Platform
section here. TheIOT_CLIENTID
needs to be of the formata:{orgId}:{application_name}
. TheorgId
can be obtained from the IoT platform. Theapplication_name
can be any string.IOT_HOST= IOT_TOPIC= IOT_PROTOCOL= IOT_USERNAME= IOT_PASSWORD= IOT_SECURE_PORT= IOT_PORT= IOT_CLIENTID= IOT_PEM=
The following values are used to store data in the database:
MARIADB_HOST= MARIADB_USERNAME= MARIADB_PASSWORD=
The following variables are used to send data to the WebSocket Server.
WS_HOST= WS_PORT=
-
Install the dependencies
npm install
-
Start the server
npm start
-
Build the image
docker build . -t mqttclient
-
Run the image and pass the .env file as environment variables
docker run --env-file .env mqttclient
You do not need to expose any port.
-
You should see the application logs
> [email protected] start /home/upkarlidder/Documents/upkar-code/call-for-code/pyrrah/Pyrrha-MQTT-Client > node mqttclient.js Reading pem file from: messaging.pem Connecting to p0g2ka.messaging.internetofthings.ibmcloud.com as client id: a:p0g2ka:my_app-1626211745471 creating mariadb connection pool on: localhost finished creating mariadb coonection pool 2021-07-13 14:29:05 debug [mqttclient.js]: connecting to IoT platform ... 2021-07-13 14:29:06 debug [mqttclient.js]: !!successfully connected to server p0g2ka.messaging.internetofthings.ibmcloud.com 2021-07-13 14:29:06 debug [mqttclient.js]: !!successfully subscribed to topic: iot-2/type/+/id/+/evt/+/fmt/+
You can run this application on Kubernetes using the charts provided in the chart
directory. The repository also provides a skaffold.yaml file that enables quick building and pushing for faster development. Read more about Skaffold here. There are two profiles provided, test
and default
. To run the solution on the test
namespace use: skaffold dev -p test
Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting Pyrrha pull requests.
This project is licensed under the Apache 2 License - see the LICENSE file for details.