Is it possible to send messages to azure to any custom topic via mqtt. All example that I've found so far work with standard topics
'devices/' + hubName + '/messages/events/'
'devices/' + hubName + '/messages/devicebound/#'
Btw, I tried to send/subscribe on the topic/subscription above with MQTT.fx application and never received messages, although the connection was successful.
The topic filter of devices/{device_id}/messages/devicebound/# is to subscribe receiving message from IoT Hub(Cloud-To-Device message), it think you need to understand the difference about device-to-cloud message and cloud-to-device message from here.
The topic of devices/{device_id}/messages/events/ is for sending a device-to-cloud message from device.
You can use Device Explorer to test this issue. When you send a message to device with the tool, MQTT.fx will receive the message.
Related
I'm working Azure Function that sends data to few devices via IoT hub. I'm trying to log whole process and I am unsure if my current solution is sufficient.
So far I'm using message feedback(as mentioned in documentation) to log if device received send message.
"The IoT hub doesn't generate a feedback message. If the cloud-to-device message reaches the Completed state, the IoT hub generates a feedback message." As I understand it if I receive said feedback it is confirmation that message was successfully/unsuccessfully received by device.
Is my understanding that this is absolute confirmation that message was or wasn't received by device correct? Or is there another option to get is confirmation?
I recommend reading through the section Receive Cloud to Device Delivery feedback for better understanding on this. The section explains how you can set the Acknowledgment feedback option. The Azure IoT Hub provides feedback in both Positive and Negative scenarios.
If you have set the message Ack to full as indicated in the article using the following code commandMessage.Ack = DeliveryAcknowledgement.Full;, you will receive a message in both Completed as well as Dead lettered scenarios (Positive and Negative outcome).
If you are specifically targeting the success messages, you would need to set the acknowledgement to Positive. The feedback you then receive is a confirmation proving that message was successfully received by device.
Hope this helps!
I followed the below steps to send a message to an IoT device using azure function.
Additional answer wrto #LeelaRajesh_Sayana.
Created a IoT hub and added the device
Add the device name and click on save
Select the device you created and click on send message
Enter the message to send
To create a particular condition, we have code it. I have used C# function time trigger to send message IoT Hub messages and added the below condition .
try
{
log.Loginformation($"Message sent : {message}");
}
catch (Exception ex)
{
log.LogError($"Error sending message :{ex.Message});
}
using System;
using Microsoft.Azure.Devices;
using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.Logging;
namespace AzureFunctionIoT
{
public static class SendMessageToIoTDevices
{
[FunctionName("SendMessageToIoTDevices")]
public static void Run([TimerTrigger("0 0 0 * * *")]TimerInfo myTimer, ILogger log)
{
string connectionString = Environment.GetEnvironmentVariable("IoTHubConnectionString");
ServiceClient serviceClient = ServiceClient.CreateFromConnectionString(connectionString);
var message = new Microsoft.Azure.Devices.Message(System.Text.Encoding.ASCII.GetBytes("Hello IoT Devices"));
serviceClient.SendAsync("<DeviceId>", message).GetAwaiter().GetResult();
log.LogInformation("Message sent successfully");
}
}
}
Run the messages with Azure IoT Hub (.NET) Code
I want to implement Azure Service Bus Topic/Subscription. Something like this
I'm looking at the Python implementation in the Azure Docs. What I don't understand, is when the message is sent, how does it know which subscription to go to?
def send_single_message(sender):
# create a Service Bus message
message = ServiceBusMessage("Single Message")
# send the message to the topic
sender.send_messages(message)
print("Sent a single message")
# create a Service Bus client using the connection string
servicebus_client = ServiceBusClient.from_connection_string(conn_str=CONNECTION_STR, logging_enable=True)
with servicebus_client:
# get a Topic Sender object to send messages to the topic
sender = servicebus_client.get_topic_sender(topic_name=TOPIC_NAME)
with sender:
# send one message
send_single_message(sender)
print("Done sending messages")
print("-----------------------")
What I don't understand, is when the message is sent, how does it know
which subscription to go to?
This is accomplished through topic filters. Each message that gets sent to a Topic is "kind of broadcasted" (for the lack of better term) to every Subscription and the Subscription only accepts a message when that message matches one of the filter rules specified for that Subscription.
You can learn more about it here: https://learn.microsoft.com/en-us/azure/service-bus-messaging/topic-filters.
When sending notifications to FCM, either from my Azure Service via Azure Notification Hub or it's test send, I am not getting any error messages, but the notification is not delivered to the specified device. The hub's test send reports "Message was successfully sent, but there were no matching targets." However, from the FCM portal test send it is, so I know the device is configured correctly.
Is it FCM reporting "no matching targets" or the hub?
I have tried a variety of device ids as targets, both the token received from FCM by the device and variations of the FCM Token generated by the GetFMToken method.
Using VS, I see in the hub registrations for APNS; I don't see any for FCM, even though I have seen registration events for my pushes in the hub's Overview Monitoring.
An example of the latest notice semantics:
"{ "priority": "high", "data": { "Raw": "PIDMe54*****64Test190801142953088468/1/2019 2:29:53 PM"}, "notification": {"channel_id": "MyNotications"}, "to" : "f-E6xD_YkFs:APA91bEsHI_Fc9zNKFfYWm2b5-ebVuS-Kp8WLMM0YgWVv6fc6dXpqvwJGUNedE9ZfaBpiDC69IQJt4hjizm98l7Lbo3RzyeHi5dAzKnFvKNZ4nCgEIoQShEGfgB5AkhS-2j7LXtcjudC"}
I expect just ""Message was successfully sent" and the notification delivered.
I am looking for a way to see which device has sent which message in Azure.
Via "IoT-hub" we can get a list of the devices but I cannot seem to find a way to correlate the messages to the devices.
Doe anyone have any idea?
Thanks in advance.
Regards
Have a look at this document for more details about the message format.
The device id is a part of the IoT Hub message system properties such as ConnectionDeviceId.
The following example shows a query of the ASA job. You can see how to get the device id from the telemetry message via the stream pipeline:
WITH subquery as (
SELECT
System.Timestamp as time,
counter,
temperature,
humidity,
EventProcessedUtcTime,
IoTHub.ConnectionDeviceId as deviceId,
IoTHub.MessageId as messageId
FROM iot Timestamp by time
)
SELECT
*
INTO
outBlob
FROM
subquery
another example is for Azure EventHubTrigger Function (AF). The telemetry message from the stream pipeline (events endpoint) is serialized into the EventData object and pushed to the AF:
public static async Task Run(EventData ed, TraceWriter log)
{
log.Info($"Label = {ed.SystemProperties["iothub-message-source"]} -{ed.SystemProperties["iothub-connection-device-id"]}/{ed.SequenceNumber}");
// ...
}
You could try Azure IoT Toolkit extension for VS Code to monitor all the messages sent to Azure IoT Hub. You could see which device has sent what message to Azure IoT Hub.
You could also refer to this blog post for more details about how to use this extension to monitor messages.
When a message arrives in IoT Hub, the hub adds a number of system properties to the message, including the deviceid of the device that sent the message - for more information about message properties, see https://learn.microsoft.com/en-us/azure/iot-hub/iot-hub-devguide-messages-construct
If you're using C# to read the messages, see the ConnectionDeviceId property of this class: https://learn.microsoft.com/en-us/dotnet/api/microsoft.azure.devices.messagesystempropertynames?view=azure-dotnet
I want to use REST API to send message to a servicebus topic.
Everything's working fine, the message is sent on the topic.
My client received an ACK fron servicebus by receiving an HTTP code 201, a void body, and some headers.
But I didn't received the messageId. I need it to retrieve treatment status in my internal product.
However, as at described into the documentation (https://learn.microsoft.com/en-us/rest/api/servicebus/message-headers-and-properties), the MessageId should be returned.
Is it normal? And how can I retrieve the MessageId?
The only other option is to set the MessageId by the client way, but I don't like this solution because it is not the responsability of the client to do that.