I am writing a simple mqtt client which will connect with a mosquitto broker.
I have used the C++ wrapper (mosquittopp) of the mosquitto library to write the mqtt client. However, I don't know how to authenticate a client with username and password through functions provided by the mosquittopp wrapper while connecting.
I am looking for the implementation of following client-tool command with the help of mosquittopp.
mosquitto_pub -m "testing" -t test -u sheheryar -P coke
You can set user and password before connecting with
mosquittopp::username_pw_set(sUser, sPassword);
Related
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!
I have this setup
in Remote server. I tried
mosquitto_sub -h 127.0.0.1 -t 'myTopic' -i 'myId'
in My computer I tried
mosquitto_pub -h 'remote_ip_here' -t 'myTopic' -m 'the message'
the remote server was able to get the message I published from my computer
the remote server has these keys
certificate file = cert.pem
certificate key file = privkey.pem
certification chain file = chain.pem
If I want to have a ssl/tls communication between my computer and the remote computer.
- How do I use those keys ?
- Am I suppose to copy those keys from the remote computer and put them also in my computer ?
- can someone please help what's the proper command to execute in order to have an ssl and tls communication.
In the remote server I tried
mosquitto_sub -h 127.0.0.1 -t 'myTopic' -i 'myId' --capath /etc/myPemPath -p 1883
While in my computer, I tried
mosquitto_pub -h remote_ip -t 'myTopic' -m 'the message' --capath /etc/localPemPath -p 1883
it didn't work, so how ?
You seem to have miss understood how MQTT works. Both mosquitto_sub and mosquitto_pub are MQTT clients which communicate with a MQTT broker (mosquitto). It is not a direct client/server relationship.
In order to have TLS secured MQTT connection you first need to configure the broker to use the certificates to identify it's self, then configure the clients to verify that certificate as part of the TLS handshake.
The mosquitto documentation on how to configure TLS is available here. You need to add either a cafile or capath and certfile and keyfile options to your mosquitto.conf file. Be aware that TLS settings apply to the last listener configured, so you will probably need to set up a new listener on a different port to 1883.
As for the clients, assuming you are not doing mutual authenticated TLS then you only need to pass the -cafile/-capath option to mosquitto_pub and mosquitto_sub to enable a TLS session.
My router's static IP is set for Raspberry Pi.
mosquitto_sub -t he -u "hello" -p "world"
Error:
Invalid port given: 0
he --------topic name
The above error is occurring - please guide me. Thanks in advance.
From the mosquitto_sub man page:
-p, --port
Connect to the port specified. If not given, the default of 1883 for plain MQTT or 8883 for MQTT over TLS will be used.
-P, --pw
Provide a password to be used for authenticating with the broker. Using this argument without also specifying a username is invalid. See
also the --username option.
I'm trying to subscribe to mqtt broker in aws.
For subscribing i'm using mosquitto client (Ver 1.4.11).
Command goes like this
mosquitto_sub.exe --cafile "path_to_ca" --cert "path_to_cert" --key "path_to_key" -h id1234.iot.ap-northeast-1.amazonaws.com -p 8883 -q 1 -d -t '$aws/things/DeviceTokyo/shadow/get' -i DeviceTokyoCMD
But I'm getting the following response
Client DeviceTokyoCMD sending CONNECT
Error: The connection was lost.
I figured the issue.There was something wrong with the policy resource ARN. So I made the change allowing to accept it from anywhere as *
I have the Contiki web demo running on a CC2650 and I'm trying to troubleshooting MQTT and want to make sure I'm properly pointing the node to a local MQTT broker (Mosquitto). Is there anything else I need to do but change the broker IP on the node to the bbbb:: IPv6 address of the broker? I've tested publishing and subscribing between Linux machines using the bbbb:: IPv6 address and it is working. Is there anything I need to do with the Org Id or auth token? I've done an exhaustive search but can't seem to find any specific documentation. Here is the link to the TI tutorial for reference http://processors.wiki.ti.com/index.php/Cc26xx_sw_examples Thanks in advance.
I am now able to answer my question on this and yes you can just point a node a local MQTT broker by pointing to the IPv6 address of the Mosquitto broker. I'm troubleshooting some 6LowPAN packet loss issues which was making the reception of published messages take a long time. Subscribing to the broker for all topics with mosquitto_sub -h localhost -v -t “#” and doing a tcpdump on port 1883 (tcpdump -i eth0 -v -X port 1883) were both helpful in seeing that there was activity.