Get list of direct methods registered with IotHub device - azure-iot-hub

I am working on one sample IoT project. Where 1 IoT device is registered on IotHub. It is exposing 1 direct method to control device temperature. On, device startup it is registering callback on IoTHub to listen for method invocation requests.
As per my understanding and knowledge, there is no way on cloud side that we can know that particular device is exposing this many direct methods and what is name of that method. (Because of MQTT/AMQP use internally).
Still, to be sure of if there is any work around to get direct methods registered by end device. Is there any SDK function or REST API to get list of direct methods registered by end-device.

You're correct in assuming there is no built-in support that lists the direct methods of your device. A device doesn't publish what methods it has implemented by default.
Options:
IoT PnP
Microsoft created IoT Plug and play, which focuses on "device models". When a Plug and Play device connects to the IoT Hub, it can make its device model known. Part of this model is the concept of "commands", which translates to a direct method for IoT Hub. Your device probably doesn't have this device model yet, as PnP is pretty new. A device manufacturer/developer can integrate this model into the device.
Create your own index command
If you are the one writing code for this device, and you don't want to do PnP, you could create a direct method that lists all the methods supported by your device. Of course, you would need to know the name of that direct method to call it.

Recently, the Azure IoT Hub (version 2020-09-30) has been publicly enabled for IoT Plug and Play, where the device model is the "glue" between the device and service facing sides. See more details about this concept here. The device twin has been extended for new property such as modelId, which it represents an identifier of the pnp model in the repository, see more details here.
Once, the modelId has been populated in the device twin, the device knows all expected direct methods included their request/response schemas, c2d messaging, reported and desired properties and telemetry data. On the other side such as a service side, the invoker knows how to invoke a direct method on the device, etc.
The following is an example of the short pnp model with one telemetry data (Temperature) and one command for invoking a direct method SetTemp on the device in the synchronous manner (no c2d message). It has been created in the IoT Central App:
pnp model (modelId = "dtmi:rk2021iotcfree:Test6vj;1"):
{
"#id": "dtmi:rk2021iotcfree:Test6vj;1",
"#type": "Interface",
"contents": [
{
"#id": "dtmi:rk2021iotcfree:Test6vj:Temperature;1",
"#type": [
"Telemetry",
"Temperature"
],
"displayName": {
"en": "Temperature"
},
"name": "Temperature",
"schema": "double",
"unit": "degreeCelsius"
},
{
"#id": "dtmi:rk2021iotcfree:Test6vj:SetTemp;1",
"#type": "Command",
"commandType": "synchronous",
"displayName": {
"en": "SetTemp"
},
"name": "SetTemp",
"request": {
"#id": "dtmi:rk2021iotcfree:Test6vj:SetTemp:__request:temp;1",
"#type": "CommandPayload",
"displayName": {
"en": "temp"
},
"name": "temp",
"schema": "double"
}
}
],
"displayName": {
"en": "Test"
},
"#context": [
"dtmi:iotcentral:context;2",
"dtmi:dtdl:context;2"
]
}
Based on the modelId, the simulated device10 has been connected as a pnp device to the Azure IoT Hub and the screen snippet shows a received message on the direct method SetTemp invoked from the Azure IoT Explorer tool:
the following screen snippet shows a device twin of the device10, as you can see there is a modelId property:
I do recommend to use the pnp model for your solution. if you are interesting only for commands, you can create a small subset of the model just only for that, see the following example:
{
"#id": "dtmi:rk2021iotcfree:Test6vj;1",
"#type": "Interface",
"contents": [
{
"#type": "Command",
"commandType": "synchronous",
"name": "SetTemp"
}
],
"#context": [
"dtmi:dtdl:context;2"
]
}
where:
"#id": "dtmi:rk2021iotcfree:Test6vj;1"
represents the modelId
"commandType": "synchronous"
represents the direct method call
"name": "SetTemp"
represents the method name

Related

Google Home doesn't send UDP broadcast to my smart home device

I am trying to develop a smart home action that works with local fulfillment but my device doesn't receive the UDP broadcast request. I have a google home device at home which is connected to my account.
I have made the next steps:
add otherDevicesIds field to my sync response
add device scan configuration (I have chosen UDP )
implement UDP server on the device. it listens on 8888 ports and responds to echo -n "test data" | nc -u -b 255.255.255.255 8888
Packets from my laptop are received by my DIY smart home device but I don't see any packets from the google home assistant device(it is in the same network as my laptop). It seems that google assistant does not send UDP broadcast at all.
I have added an example of my sync response and a screenshot of Device Scan Configuration for this action.
How to make my device receive UDP broadcast? Tell me if I have understood the local fulfillment wrong.
SYNC response example below
{
"payload": {
"agentUserId": "fas87df6a8s7d6f",
"devices": [
{
"otherDeviceIds": [
{
"agentId": "fasf87da",
"deviceId": "sdfta87sd6f"
}
],
"deviceInfo": {
"model": "LIGHT",
"manufacturer": "87sd6f87asd",
"swVersion": "1.0",
"hwVersion": "LIGHT"
},
"customData": {},
"id": "light-1234112",
"attributes": {},
"type": "action.devices.types.LIGHT",
"name": {
"defaultNames": [
"light"
],
"nicknames": [
"light"
],
"name": "7f6as87fa8"
},
"traits": [
"action.devices.traits.OnOff",
"action.devices.traits.Brightness"
],
"willReportState": false
}
]
},
"requestId": "7298347129347192374"
}
Below is the example of google action UDP config.
As mentioned in the comments by you, you didn’t create a local fulfillment app which is necessary for developing & testing local fulfillment for any of your existing Smart Home Actions. You can find more information about this at https://developers.google.com/assistant/smarthome/develop/local?hl=en
Additionally, make sure that you have added the devices correctly after enabling the test suite.

Cloudwatch event for out of region creation

I am trying to create a auto-remediation process that will stop/delete any VPC, Cloudformation Stack, VPC, Lambda, Internet Gateway or EC2 created outside of the eu-central-1 region. My first step is to parameter a CloudWatch event rule to detect any of the previously mentioned event.
{
"source": [
"aws.cloudtrail"
],
"detail-type": [
"AWS API Call via CloudTrail"
],
"detail": {
"eventSource": [
"ec2.amazonaws.com",
"cloudformation.amazonaws.com",
"lambda.amazonaws.com"
],
"eventName": [
"CreateStack",
"CreateVpc",
"CreateFunction20150331",
"CreateInternetGateway",
"RunInstances"
],
"awsRegion": [
"us-east-1",
"us-east-2",
"us-west-1",
"us-west-2",
"ap-northeast-1",
"ap-northeast-2",
"ap-south-1",
"ap-southeast-1",
"ap-southeast-2",
"ca-central-1",
"ap-south-1",
"eu-west-1",
"eu-west-2",
"eu-west-3"
"sa-east-1"
]
}
}
For now, the event should only trigger an SNS topic that will send me an email, but in the future there will be a lambda fonction to do the remediation.
Unfortunately, when I go create an Internet Gateway in another region (let's say eu-west-1), no notification occur. The Event does not appear if I want to set an alarm on it either, while it does appear in CloudWatch Events).
Any idea what could be wrong with my event config?
OK, I figured it out. The source of the event changes even if the notification comes from CloudTrail. The "source" parameters should therefore be:
"source": [
"aws.cloudtrail",
"aws.ec2",
"aws.cloudformation",
"aws.lambda"
]

How do I automate adding a custom Iot Hub Endpoint (and route to it)?

In order to receive Azure IotHub Device Twin change notifications, it appears that it's necessary to create a custom endpoint and create a route to send notifications to that endpoint. This seems straightforward enough on the Azure Portal, but as one might expect we want to automate it.
I haven't been able to find any documentation for the the az cli or even the REST API, though I might have missed something. I didn't find anything promising looking in the SDKs either.
How do I automate adding a custom endpoint and then setting up the route for device twin notifications?
You can check IotHubs template to see if it helps.
Route:
"routing": {
"endpoints": {
"serviceBusQueues": [
{
"connectionString": "string",
"name": "string",
"subscriptionId": "string",
"resourceGroup": "string"
}
]
},
"routes": [
{
"name": "string",
"source": "string",
"condition": "string",
"endpointNames": [
"string"
],
"isEnabled": boolean
}
],
Consumer group:
{
"apiVersion": "2016-02-03",
"type": "Microsoft.Devices/IotHubs/eventhubEndpoints/ConsumerGroups",
"name": "[concat(parameters('hubName'), '/events/cg1')]",
"dependsOn": [
"[concat('Microsoft.Devices/Iothubs/', parameters('hubName'))]"
]
},
For more detailed information you can reference:
Microsoft.Devices/IotHubs template reference
Create an IoT hub using Azure Resource Manager template (PowerShell)

Set a custom domain for an azure Storage Account through an ARM template

I'm trying to setup an ARM template to set a custom domain for an Azure storage account. I am only running this portion of my ARM template after the storage account is initially setup and a DNS record has been created, but it still fails with this error:
: The custom domain name could not be verified. CNAME mapping from myStorage.mydomain.com to .blob.core.windows.net does not exist.
I've replaced my domain in the error, but the rest is exact. I notice that it looks suspicious since it doesn't list the name of my storage account, but the storage account is named, so I can't figure out how to affect that. Here's the resource definition (again, the account name and domain are replaced, but all else is the same)
"resources": [
{
"name": "myStorageAccount",
"type": "Microsoft.Storage/storageAccounts",
"location": "[resourceGroup().location]",
"apiVersion": "2017-06-01",
"sku": {
"name": "Standard_LRS"
},
"dependsOn": [],
"tags": {
"displayName": "Storage Account"
},
"kind": "BlobStorage",
"properties":{
"customDomain":{
"name":"myStorage.mydomain.com",
"useSubDomain":false
}
}
}
]
I can set it to the same custom domain through the Azure portal. It validates fine there. I'm sure I could do it through a separate PowerShell script, but I prefer to do it in the ARM, so as to minimize the need for additional scripts when setting up my environment.
Any thoughts would be appreciated.

How can I use the "avContent" API service in Multi mode?

How can I access the complete avContent API service in a Sony ActionCam AS-200V when operating the camera in WiFi mode? This avContent API responds to "getMethodTypes" with only the following methods when the camera is operating in WiFi mode. When operating the camera in direct attached mode this API shows all of its methods.
Results in WiFi mode:
{
"results": [
[
"getMethodTypes",
[
"string"
],
[
"string",
"string*",
"string*",
"string"
],
"1.0"
],
[
"getVersions",
[],
[
"string*"
],
"1.0"
]
],
"id": 1
}
The HDR-AS200 supports single connection and multi connection as the way to connect to the other device for end-users, but for Camera Remote API beta, we only support single connection which is the one-to-one access of the camera and the other device.
So any functionality of the avContent service while in WiFi mode is not officially supported.