Unable to specify Device Profile using MQTT Gateway API - mqtt

We have started using ThingsBoard PE for our POC product to test if it will suit our needs.
We have an existing system which would act as a gateway between various types of IoT devices and ThingsBoard.
It seems that the communication could be implemented using MQTT Gateway API and I have successfuly used it to send connect/disconnect messages as well as telemetry upload. As stated in the gateway documentation, a new device is created if it does not yet exist in ThingsBoard. However, I am not sure how to specify device profile for each device based on device type. It seems that automatically created devices always have profile named "default" even if I have made a new profile and set it as default.
Is there any way to specify device profile in MQTT Gateway API?

Add a key "type" in your connect message.
Topic: v1/gateway/connect
Message: {"device":"Device A", "type":"Type A"}

Related

How to handle multiple device clients provisioned through DPS(Group Symmetric key) to IoT Central from a gateway device

We have a gateway device(not running IoT edge runtime). We want to connect multiple BLE or Zigbee sensors to the gateway and provision/register them through our gateway device to IoT Central as different devices using group symmetric key approach.
We have seen multiple sample codes for the provisioning and registering the devices using group symmetric key to generate device-specific SAS key. But these don't have an approach for handling multiple device clients after registering and connecting to IoT Central
python sdk provisioning with group symmetric key
iot_central_python_sample
After connecting the device we need to use device client of the SDK to send telemetry and receive commands to/from IoT Central.
Consider if we want to use the same code for multiple sensors, we need to have multiple device clients(threads) running.
Please suggest a better approach to handle multiple devices for sending telemetry and receiving commands to/from IoT Central
This might help with your use case: https://github.com/Larouex/IoTCNanoBLE33

how i can subscribe to topics in azure iot hub device to device communication

I set up an architect for my solution think that iot hub does the work of an mqtt broker, but when I started the implementation , I found that you cannot subscribe to a specific subject to retrieve messages published by another mqtt client, the notion of topic does not exist on iot hub.
I have read several articles about this subject but I have not found an appropriate alternative.
Iot hub has only two topics, and event hub endpoints are limited to 10 endpoints
Can you guide me or suggest a solution with a broker?
How can I subscribe to a specific topic?
I want a device to device communication with pub / sub
Example: a device publishes on a topic / home / room
another device subscribes to / home / room
using iot hub
I am open to all proposals
Thank you
Cloud development
IoT Hub has a limited MQTT broker implementation, because of that, you can't subscribe to device topics from other devices. You could use an Azure Function to catch all your messages and decide if it needs to send a Cloud to Device message. You could also leverage Stream Analytics to decide if a message needs to be sent before talking to that Function. This is probably your best bet if you want to play by Azure IoT Stack's rules.
No cloud development
If you really want your devices to listen to each other, there is an old blog post that describes a scenario where a device uses the service SDK to listen to messages sent to IoT Hub by a different device. It lists the pros and cons in the post.
Custom edge module
If your devices are on the same network, you could build an Edge Module that implements an MQTT broker. The devices would then connect to the edge device as they would in a normal gateway scenario, but also to your custom broker. In your routing, you would then send all the messages to your custom broker to be transmitted to any devices listening to that topic, while still sending the data to the cloud. I imagine their are a few security risks you want to look into if you go in this direction.
So in short: it's possible, probably in many other ways, but in the end you are leveraging a cloud platform that doesn't support this natively.

How can I connect a real device only accepting MQTT / TCP connection to azure IoT hub?

Context:
I have a real device that only uses MQTT and only accepts a TCP connection (The only things I can modify in the real device are the cloud address, cloud ID (username), cloud password, machine cloud ID and cloud port).
Question:
How can I connect this device to the azure IoT hub?
Can I use azure IoT edge runtime w/ transparent gateway?
In case if you want to try connectivity with IoT hub and if there is no feasibility for usage of device SDK in your device, you can try the option of using MQTT protocol directly (as a device), using which the device can still connect to the public device endpoints using the MQTT protocol on port 8883.
However, for using the MQTT protocol directly, the device must connect over TLS/SSL. Since your device has constraints in using TLS/SSL or installing certificate, the best option is usage of gateway.
In a typical IoT system, gateways are used to overcome the limitations of device capabilities. You may need to decide the suitable deployment type based on these three patterns of using IoT Edge device as a gateway as per your device capabilities and requirement in hand.
There is a scenario where you don't have to use the device SDK and connect your MQTT device directly to the IoT Hub. It is documented here. Azure IoT Hub is not a full-featured MQTT broker though, so results may vary. As per your suggestion, yes you can use a transparent gateway for this if you don't want your device to connect directly to the IoT Hub. But it's not a prerequisite.
In the case that your device needs more MQTT features than IoT Hub (or Edge for that matter) can offer, you can also consider creating an Edge module with an MQTT broker inside.

How can i get the connection string for IoT hub in Azure Digital Twin

Resource only return following object and not connection string which I need to call Direct methods on device.
[{"id":"585302d5-f4c9-4248-bb50-482657c028ba","spaceId":"b27f5aa2-ba06-4ffa-9750-b4a3655a6096","type":"IotHub","isExternallyCreated":false,"status":"Running","lastUpdatedUtc":"2019-02-21T10:22:00.0456407","properties":{"iothubUrl":"ih-46de7654-b8c5-4ddc-9e50-b455d36d4146-1.azure-devices.net"},"instanceNum":1}]
The connectionString can only be retrieved from the devices endpoint.
GET https://{{instanceName}}.{{regionName}}.azuresmartspaces.net/management/api/v1.0/devices?includes=ConnectionString
In the early preview version of Digital Twins Command and Control is not available.
Currently Azure Digital Twins doesn't support command & control to devices. You can get the device connection string but you cannot get the IoT Hub's connection string to issue commands (or device twins).
Moving forward we have heard a lot of feedback from customers that they want/need to send commands and in the next set of updates to Digital Twins we are looking at how to enable this. Stay tuned as we will have updates later in 2019. Thanks for the interest & question.

MQTT Communication Design between Multiple IoT Devices

I have this current setup:
Android app(ON/OFF button) <--> MQTT broker(mosquito) <--> NodMCU
MQTT TOPICS:
cmd/light/power - where my nodMCU receives ON/OFF command.
status/light/power - where my nodMCU returns the status of the load. This is where also the button status of the app is dependent.
The above setup works just fine and every time I add another IoT device I needed to change the mqtt topics inside the firmware before flashing to every iot device so i can control them individually and there where the problem comes in..
Maybe someone can guide me how to re-design my system that I can easily add new device to my android app and control them individually without changing the firmware of each IoT device? I'm trying to replicate the app eWeLink where it can easily add sonoff devices easily..
EDIT:
My thoughts:
design the device firmware to generate unique ID for each iot device then the id should be included in the MQTT topic. then add the device to Android app using it's ID..
topic should look like this cmd/<unique device id>/power & status/<unique device id>/power
Design the device firmware to generate unique ID for each iot device then the id should be included in the MQTT topic. then add the device to Android app using it's ID..
topic should look like this cmd/<unique device id>/power & status/<unique device id>/power

Resources