AWS MQTT Broker - is it free for simple project?

Hello, I’d like to do a simple project with node-red, esp8266 and MQTT but I don’t have rasperry pi as a local mqtt broker server. I see that people on YouTube create Virtual Machine on AWS and then install there Mosquitto MQTT.

I got 8 subscribed topics:

// Subscribed Topics
#define sub1 "device1/relay1"
#define sub2 "device1/relay2"
#define sub3 "device1/relay3"
#define sub4 "device1/relay4"
#define sub5 "device1/relay5"
#define sub6 "device1/relay6"
#define sub7 "device1/relay7"
#define sub8 "device1/relay8"

So I just gotta to follow this tutorial on YT and just set up my mqtt broker server and get the IP broker and I have to assign it for each relay on Node-red?

What is the machine you are using to host Node-Red? Can you also use it to host Mosquitto MQTT Broker?

Hello, PC - Windows 10.
I tried do it locally and didn’t work.I got nodemcu board and I’d like to switching relays via node-red dashboard. When I want to test it out with local mqtt broker then I dont know what is the ip address of the mqtt broker: I tried on my Arduino IDE const char* mqtt_server = "127.0.0.1"; // tried "localhost" and didn't work too Am I supposed to put there my computer ip? IPv4 address from cmd → ipconfig and in Local_mosca’s Server attribute?
I got MOSCA MQTT broker on my node-red flow and I configured it like this:
MQTT Port: 1883
MQTT WS port 8080
username and password too
//MQTT out node settings below
Server: Local_mosca // when I click to edit it I got name:Local_mosca, Server: localhost, Port: 1883
Topic: device1/relay1 // and so on relay 2,3

On my Arduino IDE: // NETWORK CONNECTION

const char* ssid = “xxxxx”;
const char* password = “xxxxxx”;
const char* mqtt_server = “127.0.0.1”; // tried “localhost” and didn’t work too
Got this error in Git Bash all the time.
[info] [mqtt-broker:Local_mosca] Connection failed to broker: mqtt://localhost:1883

my flow to import [ { "id": "5aaaa13.ece6d6", "type": "tab", "label": "Flow 1", "disabled": false, "info": "" }, { "id": "2ae6863d.4dde9a", "type": "ui_switch", "z": "5aaaa13.ece6d6", "name": "", "label": "Relay1", "tooltip": "", "group": "d7c12b74.277828", "order": 1, "width": 0, "height": 0, "passthru": true, "decouple": "false", "topic": "", "topicType": "str", "style": "", "onvalue": "1", "onvalueType": "num", "onicon": "", "oncolor": "", "offvalue": "0", "offvalueType": "num", "officon": "", "offcolor": "", "animate": true, "x": 230, "y": 140, "wires": [ [ "6e4f621f.b2f1e4" ] ] }, { "id": "80ec7e53.05efd8", "type": "ui_switch", "z": "5aaaa13.ece6d6", "name": "", "label": "Relay2", "tooltip": "", "group": "d7c12b74.277828", "order": 2, "width": 0, "height": 0, "passthru": true, "decouple": "false", "topic": "", "style": "", "onvalue": "1", "onvalueType": "num", "onicon": "", "oncolor": "", "offvalue": "0", "offvalueType": "num", "officon": "", "offcolor": "", "x": 230, "y": 180, "wires": [ [ "31c609d9.aa546e" ] ] }, { "id": "2b95a165.3c9426", "type": "ui_switch", "z": "5aaaa13.ece6d6", "name": "", "label": "Relay3", "tooltip": "", "group": "d7c12b74.277828", "order": 4, "width": 0, "height": 0, "passthru": true, "decouple": "false", "topic": "", "style": "", "onvalue": "1", "onvalueType": "num", "onicon": "", "oncolor": "", "offvalue": "0", "offvalueType": "num", "officon": "", "offcolor": "", "x": 230, "y": 220, "wires": [ [ "400c763c.ec8bf" ] ] }, { "id": "528863e0.79eb54", "type": "ui_switch", "z": "5aaaa13.ece6d6", "name": "", "label": "Relay4", "tooltip": "", "group": "d7c12b74.277828", "order": 6, "width": 0, "height": 0, "passthru": true, "decouple": "false", "topic": "", "topicType": "str", "style": "", "onvalue": "1", "onvalueType": "num", "onicon": "", "oncolor": "", "offvalue": "0", "offvalueType": "num", "officon": "", "offcolor": "", "animate": true, "x": 230, "y": 260, "wires": [ [ "f9f33605.5751e8" ] ] }, { "id": "6e4f621f.b2f1e4", "type": "mqtt out", "z": "5aaaa13.ece6d6", "name": "", "topic": "device1/relay1", "qos": "", "retain": "", "respTopic": "", "contentType": "", "userProps": "", "correl": "", "expiry": "", "broker": "c2171c49d307eaa2", "x": 440, "y": 100, "wires": [] }, { "id": "31c609d9.aa546e", "type": "mqtt out", "z": "5aaaa13.ece6d6", "name": "", "topic": "device1/relay2", "qos": "", "retain": "", "respTopic": "", "contentType": "", "userProps": "", "correl": "", "expiry": "", "broker": "c2171c49d307eaa2", "x": 440, "y": 160, "wires": [] }, { "id": "400c763c.ec8bf", "type": "mqtt out", "z": "5aaaa13.ece6d6", "name": "", "topic": "device1/relay3", "qos": "", "retain": "", "respTopic": "", "contentType": "", "userProps": "", "correl": "", "expiry": "", "broker": "c2171c49d307eaa2", "x": 440, "y": 220, "wires": [] }, { "id": "f9f33605.5751e8", "type": "mqtt out", "z": "5aaaa13.ece6d6", "name": "", "topic": "device1/relay4", "qos": "", "retain": "", "respTopic": "", "contentType": "", "userProps": "", "correl": "", "expiry": "", "broker": "c2171c49d307eaa2", "x": 440, "y": 280, "wires": [] }, { "id": "99ad7065ff1dd3d4", "type": "ui_switch", "z": "5aaaa13.ece6d6", "name": "", "label": "Relay5", "tooltip": "", "group": "d7c12b74.277828", "order": 8, "width": 0, "height": 0, "passthru": true, "decouple": "false", "topic": "", "topicType": "str", "style": "", "onvalue": "1", "onvalueType": "num", "onicon": "", "oncolor": "", "offvalue": "0", "offvalueType": "num", "officon": "", "offcolor": "", "animate": true, "x": 220, "y": 400, "wires": [ [ "411e5124b6e9a0eb" ] ] }, { "id": "cddee8360c65a5d8", "type": "ui_switch", "z": "5aaaa13.ece6d6", "name": "", "label": "Relay6", "tooltip": "", "group": "d7c12b74.277828", "order": 3, "width": 0, "height": 0, "passthru": true, "decouple": "false", "topic": "", "topicType": "str", "style": "", "onvalue": "1", "onvalueType": "num", "onicon": "", "oncolor": "", "offvalue": "0", "offvalueType": "num", "officon": "", "offcolor": "", "animate": true, "x": 220, "y": 440, "wires": [ [ "b82f275a09c2c85a" ] ] }, { "id": "788058fe20b8b4d1", "type": "ui_switch", "z": "5aaaa13.ece6d6", "name": "", "label": "Relay7", "tooltip": "", "group": "d7c12b74.277828", "order": 5, "width": 0, "height": 0, "passthru": true, "decouple": "false", "topic": "", "topicType": "str", "style": "", "onvalue": "1", "onvalueType": "num", "onicon": "", "oncolor": "", "offvalue": "0", "offvalueType": "num", "officon": "", "offcolor": "", "animate": true, "x": 220, "y": 480, "wires": [ [ "d2cdace5db0a42cd" ] ] }, { "id": "a9184772581f2d91", "type": "ui_switch", "z": "5aaaa13.ece6d6", "name": "", "label": "Relay8", "tooltip": "", "group": "d7c12b74.277828", "order": 7, "width": 0, "height": 0, "passthru": true, "decouple": "false", "topic": "", "topicType": "str", "style": "", "onvalue": "1", "onvalueType": "num", "onicon": "", "oncolor": "", "offvalue": "0", "offvalueType": "num", "officon": "", "offcolor": "", "animate": true, "x": 220, "y": 520, "wires": [ [ "ec0d86e688fd3536" ] ] }, { "id": "411e5124b6e9a0eb", "type": "mqtt out", "z": "5aaaa13.ece6d6", "name": "", "topic": "device1/relay5", "qos": "", "retain": "", "respTopic": "", "contentType": "", "userProps": "", "correl": "", "expiry": "", "broker": "c2171c49d307eaa2", "x": 430, "y": 360, "wires": [] }, { "id": "b82f275a09c2c85a", "type": "mqtt out", "z": "5aaaa13.ece6d6", "name": "", "topic": "device1/relay6", "qos": "", "retain": "", "respTopic": "", "contentType": "", "userProps": "", "correl": "", "expiry": "", "broker": "c2171c49d307eaa2", "x": 430, "y": 420, "wires": [] }, { "id": "d2cdace5db0a42cd", "type": "mqtt out", "z": "5aaaa13.ece6d6", "name": "", "topic": "device1/relay7", "qos": "", "retain": "", "respTopic": "", "contentType": "", "userProps": "", "correl": "", "expiry": "", "broker": "c2171c49d307eaa2", "x": 430, "y": 480, "wires": [] }, { "id": "ec0d86e688fd3536", "type": "mqtt out", "z": "5aaaa13.ece6d6", "name": "", "topic": "device1/relay8", "qos": "", "retain": "", "respTopic": "", "contentType": "", "userProps": "", "correl": "", "expiry": "", "broker": "c2171c49d307eaa2", "x": 430, "y": 540, "wires": [] }, { "id": "f59f79b79b593285", "type": "mosca in", "z": "5aaaa13.ece6d6", "mqtt_port": 1883, "mqtt_ws_port": 8080, "name": "", "username": "", "password": "", "dburl": "", "x": 280, "y": 780, "wires": [ [] ] }, { "id": "d7c12b74.277828", "type": "ui_group", "name": "Controls", "tab": "f57a184e.4f4fa", "order": 1, "disp": true, "width": "6", "collapse": false }, { "id": "c2171c49d307eaa2", "type": "mqtt-broker", "name": "Local_mosca", "broker": "localhost", "port": "1883", "clientid": "", "usetls": false, "protocolVersion": "4", "keepalive": "60", "cleansession": true, "birthTopic": "", "birthQos": "0", "birthPayload": "", "birthMsg": {}, "closeTopic": "", "closeQos": "0", "closePayload": "", "closeMsg": {}, "willTopic": "", "willQos": "0", "willPayload": "", "willMsg": {}, "sessionExpiry": "" }, { "id": "f57a184e.4f4fa", "type": "ui_tab", "name": "ESP32", "icon": "dashboard", "disabled": false, "hidden": false } ]

Yes… the address the MQTT broker is installed and running on ie your PC
You need to install it of course although one is available as a HA addin

Change in arduno ide to my ip address and in Local_mosca’s Server attribute and in git bash I got:

16 Sep 21:53:06 - [info] [mosca in:edxxxxxxxxxx5e] Binding mosca mqtt server on port: 1883
16 Sep 21:53:06 - [error] [mosca in:edfexxxxxxxxxd15e] SchemaError: Expected `schema` to be an object or boolean
16 Sep 21:53:06 - [info] Started flows
16 Sep 21:53:08 - [info] [mqtt-broker:Local_mosca] Connection failed to broker: mqtt://19x.xxx.x.xx:1883


To quickly and easily debug MQTT issues, use an MQTT client, like MQTT Explorer.

Use MQTT Explorer to solve the connection problem to the broker. It’s faster to experiment with different usernames/passwords/addresses than by re-compiling code for the Arduino.

If mosquitto is running on a Windows machine, don’t forget to open the Windows firewall for incoming connections on the mosquitto ports.

So If I have mosca mqtt broker node on my node-red flow that means that it only can be used inside node-red’s flow to test commication iinside node-red’s flow and node-red dashboard, for example display a text and that’s all? I don’t really understand I just assign all the values to my localhost ip of my computer. I thought that I can use my localhost ip to a mqtt broker server and test my mqtt commuciation with esp with my local mqqt broker server on Windows PC with mosca_broker node. I haven’t found any tutorial how to do it on YT. Everyone has RPI as a broker haha :smiley:
edit: So I got to instal Mosquitto mqqt broker on my PC: How to Install The Mosquitto MQTT Broker- Windows and Linux and then in node-red’s flow in Mosca_broker node put my IPv4 address of my computer on Server attribute and so on?
edit: I mean mosca_mqtt_broker node doesn’t work like mosquitto mqtt broker installed on my PC or RPI?

it is your firewall that is blocking your esp from reaching mqtt on Windows.

image

Windows 10 Firewall Advanced settings

  • Go to Windows Firewall with Advanced Security (choose Advanced Settings in Firewall prompt)
  • Click Inbound Rules then on right hand pane add a New Rule
  • This will bring up a New Rules wizard, just follow the prompt entering the following
  • Set rule type as Port.
  • Enter a Specific local port your server is running, in this case, 1883
  • Choose TCP port
  • in the next tab Action tab, choose Allow the connection
  • next where this rule Applies choose all appropriate Domains, such as Public (entire Internet) or Private (just my local LAN traffic) or check all for complete access from outside.
  • and finally just name the Rule (Mosquitto port 1883) or something similar and press Finish.
1 Like

So it looks like Mosca MQTT Broker doesn’t work like mosquitto mqtt broker installed locally on my PC/Windows or RPI/Linux. I got to follow this tutorial which I linked above and then test it out. ;/
I thought that Mosca MQTT Broker NODE acts like mosquitto mqtt broker.
Thank you guys, I’ll try this tips and see watch I got to do.
edit: I see that I can use HIVEMQ mqtt broker but it doesn;t work with my esp code too. when I use via websockets it works (sending message to a subbed topic)

I don’t understand. All mqtt brokers work the same, whether mosquitto or hivemq.

Try with the real IP where your mqtt broker is running, not loopback or localhost.

1 Like

I tried with the ip where hivemq cloud mqtt broker is running.
edit: I got to turn TLS option >.< I’m such a newbie… It calls connected under the nodes