Upload files
File upload between Bosch IoT Device Management and devices implementing the Uploadable function block (e.g. Bosch IoT Edge) can enable a variety of use cases related to device diagnostics and monitoring, as well as system backup and restore. The file upload functionality gives the ability to explicitly trigger uploads of various types of files such as texts, logs, videos, audio or images from the device to the cloud through Bosch IoT Device Management, our solution's device management layer. Another added value is that with this new functionality operators will be able to view logs of all connected devices which support the Uploadable or AutoUploadable features from a single point.
See our BLOB upload conceptual page for more general information.
You already know how to create and trigger mass management rules. This guide will demonstrate how to use rules to initiate the upload of log files from a virtual device (running Bosch IoT Edge Services in our case) to Microsoft Azure. This guide will show you how should the Groovy script look like when using pre-signed URL and temporary credentials with both Azure and AWS, what are the needed arguments and how to initiate the upload from the backend.
Device-side actions
Only devices that support the Uploadable or AutoUploadable features can upload files through this mechanism.
Bosch IoT Edge supports upload of OSGi and container log files out-of-the-box. This guide continues with a virtual device running Bosch IoT Edge with enabled Bosch IoT Edge Services.
Obtain the upload.exe executable, part of the Bosch IoT Edge Agent assembly. Learn how to configure it and its capabilities from the Bosch IoT Edge user documentation.
Create the rule
The mass management rule you create here will be triggered by an uploadRequest event coming from the device and will request the credentials or the pre-defined URL from the cloud storage infrastructure. By listening for uploadRequest events it triggers the actual upload from the device:
Enter the Rules UI feature of the Bosch IoT Suite UI and click + icon on the right.
The Create a rule dialog will open. On its first step:
Type in a user friendly name for the rule.
Set the scope of the rule.
Select Device as Type.
On Device selection by, click ID and select the virtual device of your choosing from the view that opens on the right. Remember it must have the Uploadable or AutoUploadable feature.
On the Execution Options step we do not need to make any other changes. So leave them as they are.
Click Next.
On the Triggers step:
Click the + in the middle view to add a new trigger.
As Type select Event Based.
Click the Select from event browser icon on the right of the blue input field that was automatically selected.
In the dialog that opens, select UploadRequestEvent, as the rule will be listening for it.
Click Save.
At the Action step enter the Groovy script, which will be executed by the rule. In the screenshot below we are requesting a pre-signed URL from Azure thus we use AzurePresignedURLConfig.
As mentioned in the conceptual page, Bosch IoT Device Management supports two types of credential configurations. Expand a Groovy script guide depending on your preferred credentials and cloud storage infrastructure:
Pre-signed URL request
Temporary credentials request
Combination of both type of credentials
Click Finish and Enable the rule.
The upload process is initiated when the device sends an UploadRequest event and the event based trigger of your rule catches it. The rule will be fired and the log upload procedure will commence. See the flow of the procedure in our File upload conceptual page.
You can monitor the rule execution status through the Executions UI feature.
Initiate the upload from the backend
For diagnosing or monitoring purposes you may also trigger the device to send the UploadRequestEvent from the backend.
Follow the same process for creating a rule like above but this time:
On the Trigger step, select a Manual Fire trigger.
On the Action step type in the following Groovy script:
target.feature(
"com.bosch.iot.suite.manager.upload:Uploadable:1.0.0"
).trigger(
"correlationId"
,
"options: {key: <key>}"
)
where you should add the correlationId as a string and the desired request options as a map.
Find more information on request options in our File upload conceptual page.
Once the rule is created and enabled you have to manually fire it from the Fire rule icon on the right:
This will trigger the rule that we created in the steps above and the necessary credentials will be requested from Azure or AWS.