The mgt_portal is responsible for mapping real devices into virtual things. Furthermore, it should be used to manage virtual and real sensors (not fully implemented).
The portal was devised using Flask and uWSGI. The webservice is deployed into NGINX. The deployment follow the instructions in this website.
sudo cp -vf mgt_portal.service /etc/systemd/system/
sudo systemctl enable mgt_portal
sudo systemctl start mgt_portal
sudo apt install nginx-light
sudo nano /etc/nginx/sites-available/mgt_portal
Add the following configuration:
server {
listen 80;
server_name detimotic www.detimotic;
location / {
include uwsgi_params;
uwsgi_pass unix:/home/detimotic/git/pei-2018-2019-g12/servers/mgt_portal/mgt_portal.sock;
}
}
To enable the Nginx server block configuration you've just created, link the file to the sites-enabled directory:
sudo rm /etc/nginx/sites-enabled/default
sudo ln -s /etc/nginx/sites-available/mgt_portal /etc/nginx/sites-enabled
With the file in that directory, we can test for syntax errors by typing:
sudo nginx -t
If this returns without indicating any issues, restart the Nginx process to read the new configuration:
sudo systemctl restart nginx
Tenants are used to groups devices together, and ease the burden of management. If the devices do not have enough resources to deal with the API provided by Hono, they can use a gateway to forward the data. Nevertheless, the gateway is optional.
The devices have feedback from the platform regarding the whether the data is accepted or not. The main reasons for a refused message are: invalid authentication, wrong topic or tenant or event a missing consumer (for the Telemetry queue).
Before sending data to the platform it is necessary to create a tenant and a device.
curl -i -X POST -H 'Content-Type: application/json' -d '{
"tenant-id":<TENANT>
}' http://192.168.85.107:28080/tenant/
curl -i -X DELETE http://192.168.85.107:28080/tenant/<TENANT>
curl -i -X GET http://192.168.85.107:28080/tenant/<TENANT>
curl -i -X POST -H 'Content-Type: application/json' -d '{
"device-id": <DEVICE>
}' http://192.168.85.107:28080/registration/<TENANT>
curl -i -X DELETE http://192.168.85.107:28080/registration/<TENANT>/<DEVICE>
curl -i -X GET http://192.168.85.107:28080/registration/<TENANT>/<DEVICE>
curl -i -X POST -H 'Content-Type: application/json' --d '{
"device-id": <DEVICE>,
"type": "hashed-password",
"auth-id": <DEVICE_LOGIN>,
"secrets": [{
"pwd-plain": <PASSWORD>
}]
}' http://192.168.85.107:28080/credentials/<TENANT>
curl -i -X DELETE http://192.168.85.107:28080/credentials/<TENANT>/<DEVICE>
curl -X PUT -i -u detimotic:detimotic -H 'Content-Type: application/json' -d '{
"attributes": {"location": "DETI"},
"features": {
"temperature":
{"properties": {"value": null}},
"rpm":
{"properties": {"value": null}}}
}' http://192.168.85.204:8080/api/2/things/<TENANT>:<DEVICE>
curl -X POST -i -u devops:foobar -H 'Content-Type: application/json' -d '{
"targetActorSelection": "/system/sharding/connection",
"headers": {
"aggregate": false
},
"piggybackCommand": {
"type": "connectivity.commands:createConnection",
"connection": {
"id": "hono-demo-laptop",
"connectionType": "amqp-10",
"connectionStatus": "open",
"uri": "amqp://consumer%40HONO:verysecret@192.168.85.107:15672",
"failoverEnabled": true,
"sources": [{
"addresses": [
"telemetry/<TENANT>",
"event/<TENANT>"
],
"authorizationContext": ["nginx:detimotic"]
}],
"mappingContext": {
"mappingEngine": "JavaScript",
"options": {"loadBytebufferJS":true,"loadLongJS":true,
"incomingScript": "function mapToDittoProtocolMsg(headers, textPayload, bytePayload, contentType) {\n var jsonData;\n if (contentType == \"application/json\") { jsonData = JSON.parse(textPayload); }\n else {\n var payload = Ditto.asByteBuffer(bytePayload);\n jsonData = JSON.parse(payload.toUTF8()); }\n value = {temperature: {properties: {value: jsonData.temp}},rpm: {properties: {value: jsonData.rpm}}};\n return Ditto.buildDittoProtocolMsg(\"demo\", headers[\"device_id\"], \"things\", \"twin\", \"commands\", \"modify\", \"/features\", headers, value);\n }"}
}
}
}
}' http://192.168.85.204:8080/devops/piggyback/connectivity?timeout=8000