IoTManagement System
- About
- Getting Started
- RPiClient Installation
- Server Details
- MQTT Topic Details
- API Details
- Usage
- Test
- Built Using
- Demo Video
- Authors
This repo contains
- Backend
- RPiClient Software
- Client auto-Installer script
- Detailed instructions
for IoTManagement System.
These instructions will get you a copy of the project up and running on you raspberry pi.
Turn on your Raspberry Pi and execute the following commands
- sudo apt update
- sudo apt upgrade
-
Download Raspberry Pi iamge with RPiClient-rs pre-configured and flash it to your Raspberry Pi.
-
ssh into the Raspberry Pi and execute the following command to get the MAC Address:
sudo systemctl status RPiClient-rs.service
- ssh into your Raspberry Pi and execue the following command
curl -sSL https://raw.githubusercontent.com/Nauman3S/IOTManagementSystem/main/installer.sh | bash
- After the installation is complete, you will be presented with the
MAC Address
of your device which you can use in the webapp.
- ssh into your Raspberry Pi and execue the following command
curl -sSL https://raw.githubusercontent.com/Nauman3S/IOTManagementSystem/main/uninstall.sh | bash
The server parameters can be monitored using NetDataMonitor dashboard. https://captain.prod.dev-pci.com/net-data-monitor/
- Mosquitto Broker
- NodeJS, NPM, Node, NVM
- PM2
- ufw
- mongod
- mongo-express
- Node v12.16.1
- NPM v6.13.4
-
MQTT Broker Link: 50.19.43.139:1883
-
Dashboard Link: https://smart-iot-management-system.prod.dev-pci.com/
- Dashbaord Username: [email protected] - Dashboard Password: 12345678
- Backend is based on NodeJS and it is being managed by CapRover. It starts automatically on server start.
For containers management and deployment, CapRover is used.
https://captain.prod.dev-pci.com/
For Docker Containers detailed management, portainer is deployed on the server
https://portainer.prod.dev-pci.com/
Portainer username/password: admin/portainer@321
- iotm-sys/device/logs
(all log messages are published to this topic) READ-ONLY
- iotm-sys/device/firmware/file/all
(global firmware update files are received at this topic) WRITE-ONLY
- iotm-sys/device/firmware/file/[macaddress]
(the fimrware file for specific device are received at this topic {replace [macaddress] with the Mac address of the device without : in the address}) WRITE-ONLY
- iotm-sys/device/firmware/script/all
(global user-script update file is received at this topic) WRITE-ONLY
- iotm-sys/device/firmware/script/[macaddress]
(the user-script file for specific device are received at this topic {replace [macaddress] with the Mac address of the device without : in the address}) WRITE-ONLY
- iotm-sys/device/firmware/url/all
(global firmware update files via URL received at this topic) WRITE-ONLY
- iotm-sys/device/firmware/url/[macaddress]
(the fimrware file URL for specific device are received at this topic {replace [macaddress] with the Mac address of the device without : in the address}) WRITE-ONLY
- iotm-sys/device/client/url/all
(global client update .tar file via URL received at this topic) WRITE-ONLY
- iotm-sys/device/client/url/[macaddress]
(the client update .tar file URL for specific device are received at this topic {replace [macaddress] with the Mac address of the device without : in the address}) WRITE-ONLY
- iotm-sys/device/heartbeat/[macaddress]
(MAC Address of the online device is sent to this topic {replace [macaddress] with the Mac address of the device without : in the address}) READ-ONLY
- iotm-sys/device/add
(for adding a new device message format 'deviceName;macAddress;updatedAt') WRTIE-ONLY
- iotm-sys/device/upgrade/*
(global device OS upgrade) WRITE-ONLY
- iotm-sys/device/upgrade/[macaddress]
(specific device OS upgrade, replace [macaddress] with device mac address without : chars ) WRITE-ONLY
- iotm-sys/device/osug/all
(global OS upgrade instructions are received at this topic) READ-ONLY
- iotm-sys/device/osug/[macaddress]
(OS upgrade instructions for specific device are received at this topic {replace [macaddress] with the Mac address of the device without : in the address}) READ-ONLY
- iotm-sys/device/info/[macaddress]
(device and os info of specific device can be requested from this topic) WRITE-ONLY
- iotm-sys/device/config/[macaddress]
(device and os info of specific device can be requested from this topic) WRITE-ONLY. Acceptable parameters in the table below
Config | Description |
---|---|
command;[bash command] |
executes any bash command. Use the command in place of [bash command] place holder |
logs=stdout |
Reads and sends the stdout logs of the RPiClient-rs to the *logs* topic |
logs=stdout-user-script |
Reads and sends the stdout logs of the user script to the *logs* topic |
logs=stderr |
Reads and sends the stderr logs of the RPiClient-rs to the *logs* topic |
logs=stderr-user-script |
Reads and sends the stderr logs of the user script to the *logs* topic |
logs=update-status |
Reads and sends the last OS update status to the *logs* topic |
POST http://44.195.192.158:3000/v1/addDevice
Parameter | Type | Description |
---|---|---|
operation |
string |
Required. value of operation should be 'add' |
name |
string |
Required. value of param could be a name |
macAddress |
string |
Required. value of param should be a MAC Address of your RPi Device being displayed by RPiClient Installer |
updatedAt |
string |
Required. value of param should be the current timestamp |
POST http://44.195.192.158:3000/v1/upgrade
Parameter | Type | Description |
---|---|---|
operation |
string |
Required. value of operation should be 'upgrade' |
devices |
string |
Required. value of devices param could be 'all' or 'device MAC Address' |
POST http://44.195.192.158:3000/v1/update
Parameter | Type | Description |
---|---|---|
operation |
string |
Required. value of operation should be 'update' |
devices |
string |
Required. value of devices param could be 'all' or 'device MAC Address' |
programFile |
multipart/form-data |
Required. a Firmware file to be sent to repective device(s) |
POST http://44.195.192.158:3000/v1/update-url
Parameter | Type | Description |
---|---|---|
operation |
string |
Required. value of operation should be 'update' |
devices |
string |
Required. value of devices param could be 'all' or 'device MAC Address' |
fileName |
string |
Required. name of the file along with the directory |
url |
string |
Required. a valid url. Could be S3 or any other CDN. |
POST http://44.195.192.158:3000/v1/update-script
Parameter | Type | Description |
---|---|---|
operation |
string |
Required. value of operation should be 'update' |
devices |
string |
Required. value of devices param could be 'all' or 'device MAC Address' |
programFile |
multipart/form-data |
Required. a valid bash script file to be sent to repective device(s) |
POST http://44.195.192.158:3000/v1/update-ota
Parameter | Type | Description |
---|---|---|
operation |
string |
Required. value of operation should be 'update' |
devices |
string |
Required. value of devices param could be 'all' or 'device MAC Address' |
url |
string |
Required. a valid url. Could be S3 or any other CDN. |
POST http://44.195.192.158:3000/v1/config
Parameter | Type | Description |
---|---|---|
operation |
string |
Required. value of operation should be 'update' |
devices |
string |
Required. value of devices param could be 'all' or 'device MAC Address' |
command |
string |
Required. any valid bash command |
GET http://44.195.192.158:3000/v1/listAll
Parameter | Type | Description |
---|---|---|
nothing |
Many API endpoints return the JSON representation of the resources created or edited. However, if an invalid request is submitted, or some other error occurs, Gophish returns a JSON response in the following format:
{
"status" : int,
"message" : string
}
The message
attribute contains a message commonly used to indicate errors or to return the logged status/
The status
attribute describes if the transaction was successful or not.
IoTManagementSystem Backend returns the following status codes in its API:
Status Code | Description |
---|---|
200 | OK |
201 | CREATED |
400 | BAD REQUEST |
404 | NOT FOUND |
500 | INTERNAL SERVER ERROR |
-
Download Raspberry Pi iamge with RPiClient-rs pre-configured and flash it to your Raspberry Pi.
-
ssh into the Raspberry Pi and execute the following command to get the MAC Address:
sudo systemctl status RPiClient-rs.service
- Add the device with the MAC Address collected in the previous step to the database using addDevice API endpoint mentioned above
- Interact with the device with using MAC Address, or interact with all the devices in the system by using
all
in devices parameter of the API.
There are two systemd services running in the background:
RPiClient-rs
RPiClient-rs-user-script
The first one is the Client program managing all sort of updates and communication related stuff while the second one is the user-script sent by the user to the device. Both of these service recover themselves from any errors automatically and both of them start running on the system boot.
Use MQTT Explorer to test the remote communication over the internet. You can run MQTT Explorer or any computer placed anywhere on the internet.
Install and Open MQTT Explorer
- Add a new connection with following details
- Then add follwoing advaced options
-
ssh into the Raspberry Pi and execute the following command to get the MAC Address:
sudo systemctl status RPiClient-rs.service
- Then you can publish to various topics and see the response on the same screen. You can get the topics list from the MQTT Topic Details section above.
- NodeJS - JS Framework for Backend Programming
- Eclipse Paho MQTT - MQTT Client for Backend and RPiClient Software
- MongoDB - Database for Managing devices
- Rust - Systems Programming Language. For programming RPi Client
- Complete Demo Part 1: This is a part 1 of complete demo of IoT Management System, showing how to install the Client on Raspberry Pi and run it.
- Complete Demo Part 2: Part 2 of complete demo showing how to interact with all the devices or specific devices in the system using API.
- Demo of Rust-based RPiClient: A complete re-write of the Client in Rust Programming Language
- Complete Demo 3: Updated backend with multiple new features. See CHANGELOG.md for more details.
- Client and User-Script Failure-saftey test: Fail-saftey features test.
- @Nauman3S - Development and Deployment