Eduardo Luis Hofmann b9a5b66c61 to get a basic mqtt
2023-08-09 23:16:26 +03:00
2022-11-06 02:28:14 +02:00
2022-11-06 02:28:14 +02:00
2022-11-06 02:28:14 +02:00
2022-11-06 02:28:14 +02:00
2022-11-06 02:28:14 +02:00
2023-08-09 23:16:26 +03:00
2022-10-22 00:38:01 +03:00
2022-11-06 02:28:14 +02:00
2023-08-09 23:16:26 +03:00

Setup MQTT broker

Create and Setup VM

Install latest fedora [35] Setup connection to internet

install mosquitto

sudo dnf install mosquitto

setup log on sudo nano /etc/mosquitto/mosquitto.conf

listener 1883 0.0.0.0
allow_anonymous true

log_dest syslog
log_type all
log_facility 5

Nginx router

In case mosquitto is not facing internet directly, a proxy server may needed. Caddy do not work, only nginx.

To install nginx

sudo dnf install nginx  nginx-mod-stream

conf file here

check firewal and selinux in case of problem
sudo firewall-cmd --permanent --zone=public --add-port=8883/tcp
sudo firewall-cmd --reload

change in Node-RED

add the server address mqtt.33co.de por 8883 and select use TLS

Setup test local 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":""}]

MQTT

to subscribe using mqttx

mqttx sub -t 'Attacker/#' -h 'mqtt.33co.de' -p 8883 -l mqtts -v
Description
No description provided
Readme 17 MiB
Languages
Python 100%