Fail to publish telemetry data to ThingsBoard Cloud - mqtt

I am new to things board and using ThingsBoard free trail account. I am getting problem when I try to publish telemetry data ThingsBoard cloud via MQTT.
I followed below document link.
https://thingsboard.io/docs/paas/reference/mqtt-api/#telemetry-upload-api
I have created device on ThingsBaord and copied accesstoken from the device then trying to send telemetry data with mqtt and mosquitto but getting following problem.
WIth MQTT:-
mqtt pub -v -q 1 -h "mqtt.thingsboard.cloud" -t "v1/devices/me/telemetry" -u 'aahhahhhahh' -m "{"temperature":42}"
Error: read ECONNRESET
at TCP.onread (net.js:659:25) errno: 'ECONNRESET', code: 'ECONNRESET', syscall: 'read' }
With mosquitto_pub
mosquitto_pub -d -q 1 -h "mqtt.thingsboard.cloud" -t "v1/devices/me/telemetry" -u " aahhahhhahh " -m "{"temperature":42}"
Client null sending CONNECT
Error: The connection was lost.
I have tried with MQTTBox chrome plugin as well. Looks like it is connecting to thingsboard cloud but failing to send message to topic.
MQTTBox screenshot
Can anyone help me why I am getting issue while publishing message to device?

Related

Hyperledger fabric: Cli Bash isn't able to connect to orderer; chaincodes not instantiating on channel

Error:
error getting broadcast client: orderer client failed to connect to
orderer.example.com:7050: failed to create new connection: context
deadline exceeded
I'm getting this error when trying to start a private collection in Fabric.
Following the docs properly and everything at the basic level seems to work (creating first app, creating first network, and extending first network - have not tried upgrading network parts yet). But as I create the private collections feature, it stops precisely at this step.
This happens when I start the network, go into the peer container using docker exec -it cli bash and instantiate the chaincode on the peer (peer chaincode install -n marblesp -v 1.0 -p github.com/chaincode/marbles02_private/go/) which works.
But when I instantiate it on the channel (peer chaincode instantiate -o orderer.example.com:7050 --tls --cafile $ORDERER_CA -C mychannel -n marblesp -v 1.0 -c '{"Args":["init"]}' -P "OR('Org1MSP.member','Org2MSP.member')" --collections-config $GOPATH/src/github.com/chaincode/marbles02_private/collections_config.json --connTimeout 30s) it produces this error and I dont know how proceed further.
Can someone help me understand what's wrong here or how to get my chaincode instantiated on my channel because I have to get the private collections to work?
Its possible this question is related to some communication between different docker images as my orderer and peer are in different containers. My commands run in the peer container (atleast thats what I think) and its unable to talk to orderer container.
Here are kinematic screenshots:
UPDATE:
This is my command: (peer chaincode instantiate -o orderer.example.com:7050 --tls --cafile $ORDERER_CA -C mychannel -n marblesp -v 1.0 -c '{"Args":["init"]}' -P "OR('Org1MSP.member')" --collections-config $GOPATH/src/github.com/marbles02_private/collections_config.json --connTimeout 30s).
I get this without sudo:
Error: error getting broadcast client: orderer client failed to connect to orderer.example.com:7050: failed to create new connection: context deadline exceeded
and with sudo I get
Error: error getting endorser client for instantiate: endorser client failed to connect to 0.0.0.0:7051: failed to create new connection: context deadline exceeded
and in sudo case, it doesn't even wait 30s, it shows error within ~2 seconds.

How to use client id in Mosquitto MQTT?

I am new to Mosquitto. I have installed Mosquitto and Mosquitto Client in Ubuntu. I am trying to subscribe with client-id also publish with client-id, please look the command that I have run in console, but unfortunately, the subscriber is not receiving the message.
Subscription
mosquitto_sub -h localhost -t temp/city1 -c -q 2 --id client-one
Publish
mosquitto_pub -h localhost -t temp/city1 -m "32 Celsius" -q 2 --id client-one
but if I Publish message without client id the subscriber is receiving message, so please help me where I did the mistake?
As mentioned in the comment, clientIds are just that, they are a unique identifier for each client connected to the broker.
ClientIds need to be totally unique, if a second client tries to connect with a clientid that is already connected the broker must disconnect the first client to allow the second to connect (this is dictated by the specification). In the example you have given the subscriber will be disconnected before it receives the message published by the second.
Messages are published to topics and clients can subscribe to these topics (or patterns of topics with wildcards)
So using the mosquitto command line tools you can do the following:
mosquitto_sub -v -t 'foo/bar'
This will subscribe to the topic foo/bar and will print out the topic and then message when ever a message is published to that topic. To publish a message containing the string testing you would use:
mosquitto_pub -t 'foo/bar' -m 'testing'
The mosquitto command line tools will generate random clientids if none are provided on the command line.

Using Mosquitto to experiment with the Watson Iot platform service

I have successfully connected a device and an application to the Watson IoT platform over MQTT protocal, the application subscribe the event published by device. example:http://iotf.readthedocs.io/en/latest/getting_started/quickstart/index.html
then I tried to let the device subscrbe a command published by the application.
device:
mosquitto_sub -h 184.172.124.189 -p 1883 -i "d:quickstart:devicetype:deviceid" -t iot-2/cmd/cid/fmt/json
application:
mosquitto_pub -h 184.172.124.189 -p 1883 -i "a:quickstart:applicationid" -t iot-2/type/devicetype/id/deviceid/cmd/cid/fmt/json -m " {\"d\" : {\"temp\" : 36 }}"
the device can't receive the message published by application.
what does the command include and how doed it work ?
Quickstart (which is completely unauthenticated, was intended to do what it says on the tin) doesn't include the ability to send commands to devices. You will have to create a device type and register a device, then something like this could work.
When you do this, in the strings you use to authenticate e.g. quickstart will be replaced by your organization id, devicetype and deviceid by the names you use for the device type and the device name.

Messages not received on first time connection

I am unable to receive messages on first time connection. for in more detail,user A is connected and publishing messages,but user B is not connected to that topic.So when user B will connect,he will not get any message from user A because there is first time connection b/w user a and user b.
How we can resolve this issue ?
Thanks
A principle of pub/sub is that the publisher and subscriber are decoupled, so you shouldn't really be thinking in terms of user a being connected to user b.
If you want a client to receive messages when they are not connected (leaving retained messages to one side), the only way to do this is:
Connect beforehand with cleansession=false
Subscribe with QoS>0 (or on mosquitto use the queue_qos0_messages option)
Ensure that messages are published with QoS>0
When the client reconnects, use cleansession=false
To test this, try:
mosquitto_sub -i prajbot-singh -h test.mosquitto.org -t prajbot-singh -c -q 1
Then quit from mosquitto_sub and run:
mosquitto_pub -h test.mosquitto.org -t prajbot-singh -m hello -q 1
And run mosquitto_sub again:
mosquitto_sub -i prajbot-singh -h test.mosquitto.org -t prajbot-singh -c -q 1

IOT Mosquitto mqtt how to test on localhost

I'm just playing around with mosquitto ans mqtt protocol
following the very good video
https://www.youtube.com/watch?feature=player_embedded&v=WE7GVIFRV7Q
trying to test it on my localhost
in a terminal window I run :
mosquitto_sub -t "nodeconf/eu" -v
but when I run this snippet:
var mqtt = require('mqtt');
var client = mqtt.connect();
client.on('connect', function () {
client.subscribe('nodeconf/eu');
client.publish('nodeconf/eu','Hello');
});
client.on('message', function (topic, message) {
// message is Buffer
console.log(message.toString());
client.end();
});
I don't see (in my terminal window) any Hello.
What's wrong, please ?
BTW
I'm also looking for good tutorial and guide on the topic thanks.
You have to add a console.log to your second (the javascript) client to see why it doesn't publishes the Hello properly.
But you can do a typical test with the mosquitto clients:
1) Subscribing to a topic:
mosquitto_sub -d -h localhost -p 1883 -t "myfirst/test"
2) Other client publishes a message content to that topic:
mosquitto_pub -d -h localhost -p 1883 -t "myfirst/test" -m "Hello"
3) All the subscribed clients to this topic will automatically get the message.

Resources