0

In Azure Remote Monitoring, you can create your own CloudToDeviceMethods. How do you add parameters to those methods?

Usually those methods look like this:

function main(context, previousState, previousProperties) { ... }

...in a .js file that has the name of a specific method. But I don't see how I can add parameters to a method like that. I also want to see those parameters in the Azure Remote Monitoring Solution Accelerator web, so I can call that method and send in some parameters.

Jon Th
  • 347
  • 2
  • 13
  • Hi Jon, if the proposed answer, was what you were looking for, would you please mark it as answer? This way it will be more helpful for others. – Alberto Vega Jul 20 '19 at 00:54

1 Answers1

1

A CloudToDeviceMethod supports exactly one parameter, and that is the JSON payload that you can give to it. Of course you can add many properties to that payload to act like separate parameters. On the device side, reading that parameter looks like this in C# and like this in JavaScript (Node example)

You mentioned that you want to be able to add those parameters in the Remote Monitoring Solution Accelerator. This is entirely possible with some changes to the ReactJS code. The main files you need to look at are the Job page, right now it calls the device method without a body. Eventually the request is built here, you can see the JsonPayload is left empty.

Matthijs van der Veer
  • 3,865
  • 2
  • 12
  • 22
  • Thanks so much, Matthijs. Just a quick related question: The reason I ask this is mostly because I have a set of IoT devices that don't really report telemetry - I just want to view their property list and change those properties through the Remote Monitoring web from Azure. So I'm unsure if I should use state or properties to keep a track of those IoT properties and I THINK I should create methods to change their properties (with a payload) but perhaps that's unnecessary? – Jon Th Jul 17 '19 at 14:32
  • It WOULD actually be good if I didn't have to use methods to change properties, but the reason I was doing it is because I got stuck with 2 problems: A) I didn't know how to specify datatypes for properties, in particular boolean and enums. And B) sometimes some properties were endlessly in a "syncing" state, i.e. it seemed like they were trying to update but couldn't. Do you know how to resolve those issues? – Jon Th Jul 17 '19 at 14:57
  • ...but maybe a device will not be notified immedially if a property is changed, like it would be with a CloudToDeviceMethod call? – Jon Th Jul 17 '19 at 15:00
  • I think I need to use this to be notified of property changes, no? IoTHubDeviceClient_SetDeviceTwinCallback() . Note that I'm talking about properties, not state. – Jon Th Jul 17 '19 at 18:37
  • If you want to change device properties, you probably want to use the device twin instead of direct methods. When the device twin changes in the IoT Hub (or programmatically), your device will be notified. This way of communication was specifically built for device properties. And yes, SetDesiredPropertyUpdateCallbackAsync is the right method to subscribe to those events. – Matthijs van der Veer Jul 18 '19 at 05:56
  • Thanks a lot. But don't you mean IoTHubDeviceClient_SetDeviceTwinCallback? I couldn't find SetDesiredPropertyUpdateCallbackAsync. I'm looking in the iothub_device_client.h file btw. – Jon Th Jul 18 '19 at 10:46
  • You're right, I was looking in the C# library and assumed they would have similar names. – Matthijs van der Veer Jul 19 '19 at 05:41