first exercise complete
This commit is contained in:
1
EventToMqttBroker_flow.json
Normal file
1
EventToMqttBroker_flow.json
Normal file
@@ -0,0 +1 @@
|
|||||||
|
[{"id":"a4d39c43.9680a","type":"tab","label":"Event to mqtt broker","disabled":false,"info":""},{"id":"7c41fc5c.45b1e4","type":"inject","z":"a4d39c43.9680a","name":"","topic":"","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":140,"wires":[["c2545350.3ab83"]]},{"id":"c2545350.3ab83","type":"function","z":"a4d39c43.9680a","name":"Device Payload","func":"\nvar longitude1 = 24.0456;\nvar latitude1 = 60.123;\n\n// Array of pseudo random temperatures\nvar temp1 = [15,17,18.5,20,21.5,23,24,22.2,19,18];\n\n// Array of pseudo random relative humidities\nvar humidity1 = [50,55,61,68,65,60,53,49,45,47];\n\n// Counter to select from array.\nvar counter1 = context.get('counter1')||0;\ncounter1 = counter1+1;\nif(counter1 > 9) counter1 = 0;\ncontext.set('counter1',counter1);\n\n// Create MQTT message in JSON\nmsg = {\n payload: JSON.stringify(\n {\n d:{\n \"temp\" : temp1[counter1],\n \"humidity\" : humidity1[counter1],\n \"location\" :\n {\n \"longitude\" : longitude1,\n \"latitude\" : latitude1\n },\n }\n }\n )\n};\nreturn msg;","outputs":1,"noerr":0,"x":330,"y":140,"wires":[["8d37ce66.b744c","94cc95b7.c99178"]]},{"id":"8d37ce66.b744c","type":"debug","z":"a4d39c43.9680a","name":"Debug Payload","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":440,"y":240,"wires":[]},{"id":"94cc95b7.c99178","type":"mqtt out","z":"a4d39c43.9680a","name":"MQTT Server","topic":"EnvSensor1","qos":"0","retain":"false","broker":"426dbfae.68222","x":610,"y":140,"wires":[]},{"id":"542e969c.575488","type":"mqtt in","z":"a4d39c43.9680a","name":"","topic":"EnvSensor1","qos":"0","datatype":"auto","broker":"426dbfae.68222","x":170,"y":380,"wires":[["3ba89c69.9fd7c4"]]},{"id":"5bebcd36.b77124","type":"debug","z":"a4d39c43.9680a","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":580,"y":380,"wires":[]},{"id":"3ba89c69.9fd7c4","type":"delay","z":"a4d39c43.9680a","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":370,"y":380,"wires":[["5bebcd36.b77124"]]},{"id":"271d28a0.ec3218","type":"comment","z":"a4d39c43.9680a","name":"Simulating a sensor device publishing mqtt topic, payload to mqtt broker","info":"","x":310,"y":100,"wires":[]},{"id":"ae768fab.a644e","type":"comment","z":"a4d39c43.9680a","name":"Publishing to and subscribing from a mqtt broker","info":"","x":240,"y":40,"wires":[]},{"id":"572aefd6.38ff9","type":"comment","z":"a4d39c43.9680a","name":"Subscribing topic, payload for processing further in the Node-RED flow","info":"","x":300,"y":320,"wires":[]},{"id":"426dbfae.68222","type":"mqtt-broker","z":"","name":"LocalInstallation","broker":"0.0.0.0","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]
|
||||||
41
README.md
Normal file
41
README.md
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## Setup environment
|
||||||
|
**20 October 2022**
|
||||||
|
> Arch
|
||||||
|
```
|
||||||
|
sudo pacman -S nodejs npm
|
||||||
|
```
|
||||||
|
|
||||||
|
> Check installation
|
||||||
|
```
|
||||||
|
╭─ehofmann@ncc-1733 in repo: iot-architeture on master [?] took 341ms
|
||||||
|
[🔴] × node --version && npm --version
|
||||||
|
v16.16.0
|
||||||
|
8.19.2
|
||||||
|
```
|
||||||
|
|
||||||
|
> install node-red
|
||||||
|
```
|
||||||
|
╭─ehofmann@ncc-1733 in repo: iot-architeture on master [?] took 15s
|
||||||
|
╰─λ sudo npm install -g --unsafe-perm node-red
|
||||||
|
```
|
||||||
|
> start node-red
|
||||||
|
```
|
||||||
|
node-red
|
||||||
|
```
|
||||||
|
> install mosquitto
|
||||||
|
```
|
||||||
|
sudo pacman -S mosquitto
|
||||||
|
sudo systemctl start mosquitto
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
> load the test code
|
||||||
|
```
|
||||||
|
[{"id":"6aa3baf4.0d1874","type":"tab","label":"Event to mqtt broker","disabled":false,"info":""},{"id":"63e03741.5d6cf8","type":"inject","z":"6aa3baf4.0d1874","name":"Injecting true","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":"10","topic":"","payload":"true","payloadType":"bool","x":110,"y":120,"wires":[["398df5fb.e9e4ea"]]},{"id":"398df5fb.e9e4ea","type":"function","z":"6aa3baf4.0d1874","name":"Device Payload","func":"\nvar longitude1 = 24.0456;\nvar latitude1 = 60.123;\n\n// Array of pseudo random temperatures\nvar temp1 = [15,17,18.5,20,21.5,23,24,22.2,19,18];\n\n// Array of pseudo random relative humidities\nvar humidity1 = [50,55,61,68,65,60,53,49,45,47];\n\n// Counter to select from array.\nvar counter1 = context.get('counter1')||0;\ncounter1 = counter1+1;\nif(counter1 > 9) counter1 = 0;\ncontext.set('counter1',counter1);\n\n// Create MQTT message in JSON\nmsg = {\n payload: JSON.stringify(\n {\n d:{\n \"temp\" : temp1[counter1],\n \"humidity\" : humidity1[counter1],\n \"location\" :\n {\n \"longitude\" : longitude1,\n \"latitude\" : latitude1\n },\n }\n }\n )\n};\nreturn msg;","outputs":1,"noerr":0,"x":290,"y":120,"wires":[["8f56361b.779e98","36e34c50.b57c04"]]},{"id":"8f56361b.779e98","type":"debug","z":"6aa3baf4.0d1874","name":"Debug Payload","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":330,"y":280,"wires":[]},{"id":"36e34c50.b57c04","type":"mqtt out","z":"6aa3baf4.0d1874","name":"MQTT Server","topic":"EnvSensor1","qos":"0","retain":"false","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"2b5d47f073ec1fb5","x":570,"y":120,"wires":[]},{"id":"772b8d63.6c67f4","type":"mqtt in","z":"6aa3baf4.0d1874","name":"","topic":"EnvSensor1","qos":"0","datatype":"auto","broker":"2b5d47f073ec1fb5","nl":false,"rap":false,"inputs":0,"x":140,"y":380,"wires":[["8e9a06ec.bdd718"]]},{"id":"5064e11f.dedc2","type":"debug","z":"6aa3baf4.0d1874","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":550,"y":380,"wires":[]},{"id":"8e9a06ec.bdd718","type":"delay","z":"6aa3baf4.0d1874","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"outputs":1,"x":340,"y":380,"wires":[ ["5064e11f.dedc2"]]},{"id":"2b5d47f073ec1fb5","type":"mqttbroker","name":"","broker":"127.0.0.1","port":"1883","clientid":"","autoConnect":true,"usetls":false,"protocolVersion":"4","keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willPayload":"","willMsg":{},"sessionExpiry":""}]
|
||||||
|
```
|
||||||
|
|
||||||
Reference in New Issue
Block a user