Receive MQTT from multiple servers using Mosquitto brokier - mqtt

I have three VMs (VirtualBox, Ubuntu 18.04). All of them with Mosquitto broker (configured as default localhost:1883). Two VMs are PUB with private IPs and a "server" is a SUB (assigned via DHCP -bridged-). What I have is:
VM1 (PUB) [192.168.1.66]
VM (SUB) [192.168.1.55]
VM2 (PUB) [192.168.1.74]
The idea is the SUB to receive MQTT from all PUBs, however, it only works if the MQTT client is configured as following
VM1 [192.168.1.66:1883] --> VM [192.168.1.66:1883] <-- VM2 [192.168.1.74:1883]
So, the SUB will only receive messages from VM1 but not from VM2 neither other VMs (PUB). How can I configure the mosquitto and the client at the SUB to receive messages from all PUBs?

A MQTT client instance can only connect to a single MQTT Broker.
You have 2 options.
Run just one broker on any of the 3 machines and have all the publishing clients just publish to that broker and likewise the subscriber .
You can configure one of the brokers to bridge to all the other brokers and subscribe to any messages published on those broker so they they will appear in the topic hierarchy of that single broker.
Details of how to configure mosquitto bridges can be found in the man page here

Related

Thins board as MQTTT Broker

If I was using thinsboard.cloud then I was putting MQTT broker name as thingsboard.cloud . But as of now I have deployed things board at GKE so what MQTT broker I can use to communicate. I tried to put public Ip address of the same but not working
The Public IP Address should be correct. Unless you changed it, the default port for MQTT in ThingsBoard is 1883.
Probably there are network restrictions, which not allow you to make connections via MQTT port 1883.

How to send LoRaWAN device data to FIWARE LoRaWAN IoT Agent from postman or MQTT Publisher client

I have created an application in Things Network for LoRaWAN. Also registered a device within that application.
Already register a service in LoRaWAN IoT Agent and provisioned a device with provider as TTN in LoRaWAN IoT Agent.
Created a HTTP integration in Things Network Stack for my IoT Agent.
I also received data sent from Things Network Uplink client in my registered IoT agent.
Uplink payload from Things Network
01 67 00 FF
Now i want to send uplink message from postman or MQTT publisher client.
I tried to create a payload for postman i.e. Url : http://MyMachineIP:4061/iot/json?=MyDeviceId&k=APIKEY
JSON PAYLOAD
{
"app_id": "MyApplicationID",
"dev_id": "MyDeviceId",
"hardware_serial": "AAAAAAAAAAAAAAAA",
"payload_raw": "AWcA/w==",
"metadata": {
"gateways": [
{
"gtw_id": "TEST_1",
"rssi": 0,
"snr": 0
}
]
}
}
but got error Cannot POST /iot/json.
I also tried using MQTT Publisher Client:
Installed Eclipse Mosquitto providers a CLI to subscribe and to publish
messages.
Start Mosquitto Service.
MQTT command to publish uplink measure:
mosquitto_pub -h eu.thethings.network -p 1883 -u applicationid-P ttn-account-v2.xXXXXXXXXXXXXXXXXXXXXXXXXX -t applicationid/devices/deviceid/up -m '{"port":1,"payload_raw":"AWcAuw=="}' -d
MQTT command to subscribe uplink measure:
mosquitto_sub -h eu.thethings.network -p 1883 -u applicationid -P ttn-account-v2.x2Q20IXXXXX
I recommend you reading this IoT Agent LoRaWAN guide https://fiware-lorawan.readthedocs.io/en/latest/users_manual/index.html
Device provisioning, config and read this part:
In this case, the IoTA will subscribe to any observation coming from the LoRaWAN application server. Whenever a new update arrives, it will create the corresponding device internally and also in the Context Broker using the pre-provisioned configuration. Finally, it will forward appropriate context update requests to the Context Broker to update the attributes' values.
Regards!

mqtt broker bridge (in windows machine)

I'm working in mqtt broker bridge, I have to connect local mosquitto to remote mosquitto.
connection remote-mosquitto-bridge
address 10.1.0.9:1883
topic test both 1
Above code is added in mosquitto.conf file for connect remote machine(10.1.0.9 is my remote)
its enough for message sharing to local to remote
You need config the listener port
ex:
if your diagram is like that
broker 1 => broker 2
Broker 1 mosquitto.config:
connection remote-mosquitto-bridge
address 10.1.0.9:1883
topic # both 0
Broker 2 mosquitto.config:
port 1883
listener 8883
This work for me.
source:
https://medium.com/jungletronics/mosquitto-bridge-5b44e9687fb3

MQTT data handling when bridge connection is down

I have established a MQTT bridge connection between Mosquitto and EMQ.
1) Is the bridge connection between 2 MQTTs always stable?
2) If not, how does it handle the Data Communication when the bridge is down?!
We have no idea how stable your network is, so we can't comment on how stable a bridge connection will be. But just like other MQTT connections they are a persistent connection (not per message)
It depends... on many things, such as what QOS the messages are published/consumed at. But with the right settings the messages should be queued on the which ever end of the broker they arrive at and then be pushed over the bridge when it is re-established.
The stability of emqx depends on the network status between two mqtt brokers. In the implementation of the emqx bridge, if the connection between emqx and mosquitto is broken, the messages which would be forwarded to mosquitto will be cached in disk or memory, and when the connection is resumed, the cached offline messages will be forwarded to mosquitto.

Cant connect to mqtt musquitto on AWS EC2 instance

When I publish and subscribe at localhost its work fine.
When I try from my PC at home I just can't connect to the broker.
open TCP port in/out at security group - 1883 8883 8080
open the ports also at my ec2 instance firewall...
what is the problem? I use the public DNS by amazon as I think I should...
This is an exercise at diagnosing network problems:
1) netstat -a -n | grep 1883
will tell you whether your broker is configured correctly
2) wireshark packet capture will tell you whether your system is receiving packets at the specific port
You will not get an answer until you at least do those.

Resources