Is there a way to get an event when a device twins reported properties change? - azure-iot-hub

Looking through the apis for DeviceClient, ServiceClient, and RegistryManager it doesn't look like there is any obvious way to get an event/callback when the reported properties for a device have changed. Therefore it seems like something consuming the IoTHub information wouldn't have any idea properties have changed without constantly polling. That seems rather inefficient and error prone. What am I missing?

The device twins has built-in an event driven notification model when the changes on the tags and properties are published via the Azure IoT Hub Routes path to the custom endpoints. See more details here.
The following screen snippet shows an example of the Azure IoT Hub Routes for TwinChangeEvents notifications:

Related

Writing data to Azure Iot hub device

I am currently doing a POC where I would like to know if this is possible using Azure Services. I get certain data from Iot hub in my Event hub which triggers a logic app, and based on the message received from Event hub, My logic app would send a message to IoT Edge device. i would like to know if it is possible to send message to IoT hub device from logic app? and if yes how can we do that?
I am more looking Yes or No answer to my question and If I get the services to be used to achieve this.. It will be great
Yes, this is possible. Logic Apps have an Event Hub connector that you can use to start your app when a message comes in.
To send a message to your Azure IoT Edge device from a logic app, you could use the REST API. It allows you to send a direct method to a specific module on the device. The device needs to be online for it to receive the message, otherwise, the REST call will result in an error.
The challenge is that you will need to get a valid security token to complete this call, you could certainly add this to your app as a variable, but you shouldn't. You also run the risk of exposing this secret value in your run history. You could write an Azure Function to generate this security token and retrieve it with the Logic App. At this point you're writing code anyway, the problem you're trying to solve with a Logic App would be a better fit for an Azure Function.

Sonos event subscription without cloud service to receive events

I'm trying to wrap my head around how to subscribe to events in the new Sonos API for an iOS app.
It seems like a cloud service is needed to receive events from the Sonos Cloud.
As described here:
[Subscribing to events with Sonos API
[https://developer.sonos.com/build/direct-control/connect]
Is there any way for an iOS app to subscribe to events (volume and grouping change) without having to run a cloud service?
If not, any features based on event subscriptions will not be able to work if there is trouble connecting to the cloud for whatever reason.
No, there's no way to run without a cloud service. You must have a reliable cloud service for events and subscriptions.
Each device also has a super fast / local / undocumented, UPNP service that also supports events.
this answer should give you some pointers on how to get it working in node.
In a nutshell:
Setup an http endpoint on the device (not sure how that works in Swift)
Tell (in node) the speaker to start sending events for a specific service
Handle the received XML events.
Sample event from RenderingControlService (yes it has nested encoded xml in the <LastChange> property):
<e:propertyset xmlns:e="urn:schemas-upnp-org:event-1-0"><e:property><LastChange><Event xmlns="urn:schemas-upnp-org:metadata-1-0/RCS/"><InstanceID val="0"><Volume channel="Master" val="15"/><Volume channel="LF" val="100"/><Volume channel="RF" val="100"/><Mute channel="Master" val="0"/><Mute channel="LF" val="0"/><Mute channel="RF" val="0"/><Bass val="0"/><Treble val="0"/><Loudness channel="Master" val="1"/><OutputFixed val="0"/><HeadphoneConnected val="0"/><SpeakerSize val="3"/><SubGain val="0"/><SubCrossover val="0"/><SubPolarity val="0"/><SubEnabled val="1"/><SonarEnabled val="1"/><SonarCalibrationAvailable val="1"/><PresetNameList val="FactoryDefaults"/></InstanceID></Event></LastChange></e:property></e:propertyset>

Can an IoT Edge module twin's properties be used for message enrichment?

IoT Hub has the ability to enrich messages prior to being sent to an endpoint. It appears that the device twin's information can be added, but I don't see anything about the module twins online.
The use case here would be we will likely version a module data model contained within the messages at some point in the future. We would like to enrich the messages sent to endpoints with metadata about the state of the module it came from.
Another option that doesn't seem to exist is the ability to update device twin properties on deployment. Were this doable, then potentially we could update a modules version information at the device twin level.
Is this the wrong way to think about twins? Aka were such functionality even available, would the enrichment take the point in time twin reported value? Could there even be any guarantee that the twin has the correct reported value at the time the module sent the message? It that is the case, is the only real reliable way to send metadata about a module's message is within the message itself?
If you send an event from within a module using a module client, the keyword $twin in the message enrichment will refer to the module twin.

How does an IoT client report a changed property to the IoT Hub?

I'm using the azure-iot-sdk-c library for an iot device to talk to an IoT hub. I use IoTHubDeviceClient_LL_SetDeviceTwinCallback() to register a callback function in my client code that gets called whenever a device twin state property changes. In that code, I modify my device's properties and call IoTHubDeviceClient_LL_SendReportedState() to notify the hub that I did the changes that were requested.
But what happens if someone walks into the room where my device lies and changes one of those properties. My device code gets a notification of that property change but I would like to use that opportunity to let the IoT hub know that a property changed. How do I do that? There is no "set_desired_property" in the client sdk.
You would send it back as a reported state. For example, if the device is monitoring a light and someone physically turns it off then the light's state is off. You send that as the light's reported state.

Android C2DM Source Code or Implementation

I have a requirment to use Android C2DM functionality.
However, the restriction is that there should be no data that goes outside organization network.
Does the server side implementation send data to Google servers?
Is there an option to implement C2DM service within a closed network, where the data is not sent to Google servers?
Thanks,
RR
The purpose of C2DM is that you "Notify" the device that new data is available, and then your application is starting a sync (or something else, eg showing a message).
In general you don't submit the data (sometimes called payload) using C2DM. It is limited to 1024 chars only.
This way no "company" data is sent to Google.