One of the goals of having devices connected to the cloud is to be able to inspect, diagnose and manage them from anywhere, avoiding to be physically next to them to do so.
With this logic in mind, there can be times when we may want some devices to perform generic tasks upon command that don’t require extra intelligence on their side to be completed, like updating their firmware or downloading a file from a server. But most of the time, devices are doing other stuff on their own, like reading data from sensors and processing it, or generating diagnostics information based on some internal factors.
Depending on the results of these tasks, devices may need to act differently. For example, let’s imagine a streetlight, and connected to it, a device whose role is to detect unexpected changes on the status of the lightbulb. Most of the time, the information regarding the status of the lightbulb is steady (on at night and off during the day). In those cases, this information is standard and can be uploaded periodically to the cloud, for example once every hour, to keep track. But, what happens if, during the night, that lightbulb stops working? The same information becomes critical, and it is the device’s job to detect such event and, on its own, decide to alert that something is not working as expected.
These kinds of situations require devices to have some intelligence in order to decide what to do with their registered information when certain conditions occur. So, in order to achieve a similar behavior on your simulated devices, it is necessary to provide the Digi IoT Device Simulator with the means to accommodate to your specific conditions. This is done through the use of Python custom code.
Custom Python code must be implemented inside simulation.py
file in the root of the simulation directory and the user_app
object must be properly configured in the simulation.json
file.
Currently, simulated devices require custom code to: