This repository will contain the Pyrrha solution sensor simulator.
This Apache OpenWhisk serverless function creates a MQTT client for the Pyrrha solution. The client sends the following message as an IoT device to the IoT platform every minute:
{
"firefighter_id": params.IOT_FIREFIGHTER_ID,
"device_id": params.IOT_DEVICE_ID,
"device_battery_level": (Math.random() * (0.00 - 100.00) + 0.0200).toFixed(2),
"temperature": (Math.random() * 50).toFixed(2),
"humidity": (Math.random() * 100).toFixed(2),
"carbon_monoxide": (Math.random() * 150).toFixed(2),
"nitrogen_dioxide": (Math.random() * 10).toFixed(2),
"formaldehyde": (Math.random() * 10).toFixed(2),
"acrolein": (Math.random() * 10).toFixed(2),
"benzene": (Math.random() * 10).toFixed(2),
"device_timestamp": getUTCTime()
}
This solution was built to make use of Pyrrha's MQTT broker service VerneMQ. Device authentication is handled directly with the VerneMQ service along with a database table, as well as MQTT broker duties.
Device information can be inserted directly into this table by first connecting to the database service and running INSERT statements. The instructions for this can be found in the Docker Compose deployment instructions in the pyrrha-simulator
section.
The following parameters need to be set as local environment variables or as Github Actions environment secrets for the code to work. You can fill out .example.sh
and run source ./.example.sh
to create the environment variables locally.
IOT_HOST=""
IOT_PROTOCOL=""
IOT_SECURE_PORT=""
The action is a simple Node.js application. Execute the following steps to run it locally:
-
Install the dependencies
npm install
-
Run the code
npm start
-
Install the dependencies
npm install
-
Deploy the code
ibmcloud fn deploy
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.