Device Simulation - "Advanced" Custom Devices
We want to utilise the device simulation service to replicate real iot hardware. Ideally we would be able to mirror the dataflow (telemetry messages, Device Twin Reported Property Updates) and control interface (Direct Methods, C2D Message, Device Twin Desired Property Updates) 1 to 1.
We currently use custom devices to send custom telemetry data and IoT Hub direct methods to control the simulated device.
Is it possible to pass a payload with the direct method call, and if yes, how can this payload be accessed in a custom device configuration javascript file?
Is it possible to change reported properties and have them updated to the device twin reported property? As far as we see, changing and updating the properties object in the simulated device state.js has no effect at all. (Also, neither the Tags or Properties node in the simulated device json are written to the iot hub device twin.)
Is it possible to have the simulated device react to changes in the device twin desired properties?
If there is documentation about any of the above questions please point us in the right direction.

1 comment
-
Troy Hopwood commented
Yes, it is possible to pass parameters to a Direct Method and use this within the simulated device. 1. This info is passed to the script in the context. So if you call a setFuelLevel method and pass the payload {"fuellevel":10]} the context. fuellevel will = 10 and can be used in your script. See an example here: https://github.com/Azure/device-simulation-dotnet/blob/6f0d0737135bac17aeaf413cbff7f10c7588fcda/Services/data/devicemodels/scripts/SetFuelLevel-method.js
2. There was a regression where simulation quit updating the twin. This has been fixed and it should behave the way you are expecting.
3. There is currently no support for the script to respond to desired properties. But this is something we should look at.