Unable to read Azure IoT hub MQTT subscription message data - azure

I have successfully connected my ESP8266 Arduino project to the Azure IoT hub by following the steps outlined here:
https://azure.microsoft.com/en-gb/documentation/articles/iot-hub-mqtt-support/
The MQTT library that I am using is the following library:
https://github.com/Imroy/pubsubclient
Using the code I have been able to publish events to azure. The problem starts when trying to read the messages that are passed to the device.
Here is the code:
http://pastebin.com/7AVLQfFh
When I sue the Azure Device Explorer to send a message to the device the I get the following results:
As you can see the payload length is the same as the number of characters in the message but the characters are not the same. And also if I vary the string sent then the vales in the result are the same.
As a sanity check I have tried the code against a different MQTT service (Adafruit IO) and the results are as to be expected (here the message is 'ON' or 'OFF'):
The Azure MQTT service must be doing something different when it sends the messages to the device, what I needs to know is what it does differently.

Just a couple of hours ago I managed to get the messages flowing from Azure IoT hub to my ESP8266 using the original PubSubClient - link here. You are using the fork of that library that has been made more object oriented and probably has more enhancements.. but if you aren't very hooked on using the newer version I'd recommend getting the original one and trying it out.
I have my code on github if you need some reference: link
One important mention: the PubSubClient.h needs changing the #defineMQTT_MAX_PACKET_SIZE 128 to #defineMQTT_MAX_PACKET_SIZE 256 or more if you work with big packets
Also, I haven't tried to send any messages so I don't know how that'll work.
Update: I've also written a short blog post on how to set it up: link

According to this documentation page, property_bag is RFC2396 encoded.
RFC 2396-encoded(<PropertyName1>)=RFC 2396-encoded(<PropertyValue1>)&RFC 2396-encoded(<PropertyName2>)=RFC 2396-encoded(<PropertyValue2>)…
But isn't ABCD the same in plain text vs URI encoded you ask... Well, yes.
Install stunnel (https://www.stunnel.org/index.html), open a TLS 1.2 connection to IoT Hub on 8883/TCP and then point MQTT.fx or Paho to it and sniff the traffic with Wireshark, see what you get.
I was able to read all messages in plain ASCII text while talking to IoT Hub over REST, so whatever this is i think it's MQTT specific.
If you haven't done so already you should open an issue on their GitHub. They seem to be quite responsive: https://github.com/Azure/azure-iot-sdks/issues

Related

Send data using over bluetooth using different protocols

I have an app that communicates with a bluetooth device, and I'm trying to replace that app with some code.
I tried using C# InTheHand nuget, Microsoft's Bluetooth LE Explorer, python's sockets and others to send data and see what happens.
But there's something I still don't understand - in each way using different libraries I saw in wireshark a different protocol: ATT, RFCOMM, L2CAP...
When I sniffed my bluetooth traffic from my phone using the app mentioned before, I saw mostly HCI_CMD protocol traffic.
How can I choose the protocol I want to send? Is there a simple package for that? something to read?
Do I need to build the packet myself? including headers and such?
Thank you!
Update:
Using Microsoft's Bluetooth LE Explorer I was able to send a packet that lit up my lamp, starting with 02010e10000c00040012(data)
Using bleak I was able to send a packet starting with 02010e10000c00040052(data)
the difference makes the lamp not ligh up and I'm not sure if I can change it via bleak as it's not part of the data I send
I think what you are showing is that bleak does a write without response while MS BLE Explorer does a write_with_response.
Looking at the Bleak documentation for write_gatt_char that seems to be consistent as response is False by default
write_gatt_char Parameters:
char_specifier (BleakGATTCharacteristic, int, str or UUID). The characteristic to write to, specified by either integer handle, UUID
or directly by the BleakGATTCharacteristic object representing it.
data (bytes or bytearray) – The data to send.
response (bool) – If write-with-response operation should be done. Defaults to False.
I would expect the following to have the desired effect:
await client.write_gatt_char(LIGHT_CHARACTERISTIC, b"\x55\xaa\x03\x08\x02\xff\x00\xff\xf5", True)

How to set iot Hub (or AzFunction) to send message to a IOT edge input route?

I'm trying to send C2D messages using Azure,
however, I can’t get all the information in the Microsoft Documentation (and internet in general) on "How to send message from the cloud to an IOT-EDGE module input ?"
I have already found some bits of answer, but I can’t find this last piece of information.
step 1 send message :
I found a bunch of good examples and sample explaining how to send C2D message to a regular IOT device. but none on an edge one? Is it even possible ?
step 2 receiver:
I have an IOT-Edge custom module that have an output to the "$upstream". For the input I tried :
"FROM $upstream INTO BrokeredEndpoint(\"/modules/edgeModule/inputs/input1\")" and as expected it doesn’t work.
Do you have any leads ?
thanks.
PS: English is not my native language, Sorry for the mistakes if found any.
IoT Edge modules can only receive Direct Method calls but not async Cloud-to-device messages. You can find examples how to implement the DM calls for instance here: https://github.com/Azure-Samples/iotedge-end2end-messageflow

Thingsboard; Data about same sensor, but from a different (multiple) gateway

I have just started using Thingsboard and made some good progress in understanding how some of the basic stuff works ( mainly sending sensor data using mqtt ). But I have come to a complete halt at one point. Here is an explanation of the problem. Thingsboard version is 1.3.1
My setup:
4x RPi (Raspberry Pi) used as gateways to gather data from bluetooth
beacons
A set of bluetooth beacons
Here's what the system is supposed to do:
Send periodic data from the gateways ( RPi ) to inform thingsboard that the gateway is alive
The above part is working fine. I have set up the gateways to connect to thingsboard using access token, and post the data ( both the attributes and telemetry ). For sending attributes I use "v1/devices/me/attributes" and for telemetry data I use "v1/devices/me/telemetry", as mentioned in the documentation.
A typical string from the gateway indicating that it is alive is
{"gwA.macid": "00:00:00:00:00:00", "gwA.timestamp": "2018-02-16T19:20+01:00"}
The above part is working well. This is just for an indication that the gateway is well and able to communicate with the Thingsboard server. All the gateways connect to thingsboard using it's own respective access token and posts the above data.
Now the problem part ( or where I got halted )
The gateways gather the data about the nearby bluetooth beacons and post it too.
The data format in which the gateways posts the beacon data is
{"bcn000001.mac": "00:00:00:00:00:00", "bcn000001.timeepoch": 1518939044}
The gateway ensures that each beacon data will have the correct prefix. For example
{"bcn000001.mac": "50:80:25:AA:BB:CC", "bcn000001.timeepoch": 1518939044}
{"bcn000002.mac": "50:80:25:RR:AA:DD", "bcn000002.timeepoch": 1518939039}
{"bcn000003.mac": "50:80:25:GG:33:EE", "bcn000003.timeepoch": 1518939020}
But the data about the same sensor can also come from another gateway. How do I show it on a single widget irrespective of which gateway the data comes from. If I choose "entity list" then either it does not work, or shows up all the 4 RPi gateways on the widget. This is not what I want. I have attached an image. I am not sure if I am able to explain this well but pls do let me know if there is any other information that I can furnish. I am adding an image to point to some things that I just mentioned. I have even separated the data out by using a prefix ( as mentioned in one of the earlier SO posts ). I have spent close to couple of days on this. This was not supposed to be difficult. At least that's what I thought when I got started.
Note: As I explore, I just learnt (realized) one more thing. I think this part was a little confusing so I thought I should inform others. When one adds a device in Thingsboard, there is an option to specify if the device "Is a Gateway". What it is trying to tell(ask?) is that whether thingsboard gateway service is installed on that device. In my case I made the mistake(?) of thinking that a device that gathers data from sensors and posts it to the server is a gateway device. I guess I'll try to install thingsboard gateway service on the raspberry pi, then see how it goes. I'll post an update once I am done but in the meantime any useful comments or suggestions - please keep em coming.
I have seen others ask very similar question on SO. Something fundamental like this shouldn't be so difficult. No point in have a hundred pages of documentation without a clear explanation of most basic steps towards setting up an IoT backend/dashboard. All I wanted to do is to display the same sensor data ( say Sensor A ) coming from "any one of the devices", to show on the same widget. If I choose single entity, the widget won't update if the data comes from other device. If I choose entity list, and turn on "Resolve as multiple entities", then I end up with the widget showing all the devices
you are using wrong API. The API you are looking for is gateway API which allows to push telemetry and other messages on behalf of other devices. Please use this API https://thingsboard.io/docs/reference/gateway-mqtt-api/ on the Raspberry Pi gateways. You can also use our Gateway project and modify it for your needs.

How to push information to all users from many horizontal EC2 servers?

One of the requirements of my app is that when one user makes any insert/update/delete, all users viewing a page with a list of that record type get pushed an update containing the change. The user should not be expected to repeat an API call to refresh the dozens of records that did not change, because the push should contain a short summary of the change that occurred.
I accomplished this in my small dev server using SocketIO. I can't scale this across more than one server. My target infrastructure is AWS, and I know AWS has a push notification service, but I believe it's mobile-only and not what I'm looking for. The huge number of data streams being subscribed to is the reason I haven't consider a server-less infrastructure.
I'm new to AWS and have never attempted horizontal scaling either, so please forgive me if my entire question is ignorant.
Have you taken a look at using AWS IoT MQTT messaging protocol? Each browser is a 'device' and you have javascript listening in the browser for messages published via a socket protocol. Each service pushes a message to MQTT when it has an update. There's some good POCs out there (i.e. medium.com/#jparreira/…)

Stable Node JS AMQP 1.0 Client (Event Hub)

I'm looking for a stable AMQP 1.0 client for NodeJS so that I can consume events from Azure Event Hubs.
I have tried using https://github.com/noodlefrenzy/node-amqp10, but it chokes sporadically on certain payloads with messages like malformed payload: Unknown code prefix: 0x30 and malformed payload: Unable to decode bytes from message body: 005375b00002810c5b7b226576656e7474797065223 (...).
I would appreciate any direction people can offer for a stable AMQP 1.0 client in NodeJS. I am surprised that I have not been able to find one so far, since otherwise it seems Azure is failing to support an entire developer base.
I'm the (co-)author of https://github.com/noodlefrenzy/node-amqp10. The error you were seeing was due to large messages being split across multiple transfer frames - something we hadn't encountered before, so hadn't implemented. We just added support for this in v2.1.0, so please check out our library again.
My co-author uses this in production against QPID and has been for months, and we both actively support it as we have time, so if there are any instabilities or missing features, we will try our best to address them. Often they are just issues where we haven't needed a feature of the (incredibly large) spec or have misinterpreted the (incredibly scattered) spec details.
You can also use the official JavaScript SDK for Azure Event Hubs, #azure/event-hubs which internally uses rhea

Resources