Skip to content

This repository contains the Pyrrha (created by Prometeo) solution MQTT client that sends device readings from the mobile app.

License

Notifications You must be signed in to change notification settings

Pyrrha-Platform/Pyrrha-MQTT-Client

Repository files navigation

Pyrrha MQTT client

License Slack

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.

Technologies used

  1. Node.js
  2. npm
  3. WebSocket Server

Prerequisites

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.

  1. Pyrrha MQTT Server (VerneMQ)
  2. Pyrrha Database Service
  3. Pyrrha Websocket Server

MQTT Server integration

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.

Run locally with Node.js

You can run this solution locally as follows:

  1. Copy .env.sample to .env and fill out the values. The following values can be obtained from the IBM IoT platform as explained under the Connect an application to IBM Watson IoT Platform section here. The IOT_CLIENTID needs to be of the format a:{orgId}:{application_name}. The orgId can be obtained from the IoT platform. The application_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=
    
  2. Install the dependencies

    npm install
    
  3. Start the server

    npm start
    

Run locally with Docker

  1. Build the image

    docker build . -t mqttclient
    
  2. 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.

  3. You should see the application logs

    > mqtt-client@1.0.0 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/+
    

Run on Kubernetes

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

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting Pyrrha pull requests.

License

This project is licensed under the Apache 2 License - see the LICENSE file for details.

About

This repository contains the Pyrrha (created by Prometeo) solution MQTT client that sends device readings from the mobile app.

Topics

Resources

License

Stars

Watchers

Forks