Over-the-Air Updates Demo
This example demonstrates how to use over-the-air (OTA) updates with the Embedded Coder® Support Package for Linux® Applications to update deployed applications on the target machine. OTA updates are crucial for deploying software updates remotely to devices running embedded Linux, ensuring that they are up to date with the latest features, security patches, and bug fixes without requiring physical access to the device. Embedded Coder Support Package for Linux Applications uses Eclipse[tm] hawkBit server to roll out the software updates to the target machines over the air.
This example uses an AUTOSAR adaptive architecture model LightControlSystem
. The model initially has three components, OutdoorLightSensor,
LightController
, and LightActuator
. The OutdoorLightSensor
component processes the data received from a sensor and sends the data to the LightController
component by using adaptive events. The LightController
component calls the method from the LightActuator
component by using adaptive methods and the LightActuator
component turns the car headlights on or off based on the input received from the LightController
component.
In this example:
The
LightControlSystem
model is deployed to the target machine.The model is updated by adding one more
BrakeSensor
components.
The BrakeSensor
component processes the data received from the sensor and sends the data to LightController
by using adaptive events. The LightController
component calls the method from the LightActuator
component by using adaptive methods and the LightActuator
component turns the brake ights on or off based on the input received from the LightController
component.
For the updated model, the application package is generated and sent as an update to the target machine over the air. The updated package replaces the previously deployed application on the target machine.
Create and Deploy AUTOSAR Adaptive Architecture Model
Enter into the LightControlSystem folder in the example directory.
Open the
LightControlSystem
model.From the model toolstrip, click Apps > Linux Runtime Manager to open the Linux Runtime Manager app.
In the Target Configuration pane, specify the target details and connect to the target machine. For more information on setting up the target computer, see Setup Linux Target Computer.
In the Linux Runtime Manager toolstrip, in the Prepare section, click Create & Deploy Application Package. Select the
LightControlSystem
model to deploy it on the target. For more information, see Build Simulink Model and Deploy Application.
Verify the deployed application including the executables that are shown in the Targets Tree pane.
In the Targets Tree pane, select the
LightControlSystem
.In the Linux Runtime Manager toolstrip, in the Run on Target section, click Start Application to launch the executables of the adaptive application on the target.
Observe the logs in the Linux Runtime Manager that shows the headlight status.
Click Stop Application to stop the executables of the adaptive application on the target.
Close the
LightControlSystem
model.Get back into the example directory.
Setup Eclipse hawkBit Server
Eclipse hawkBit server has to be installed on a Linux x86_64 machine. Install the hawkBit server by creating the docker container and start it by using this command on a Linux terminal.
docker run -p 8080:8080 hawkbit/hawkbit-update-server:0.3.0
OTA clients on target machines connect to the hawkBit server through port 8080 as specified by this command. You can change this port number as desired.
You can ignore any logs in the docker container related to the connection. For more options to install the hawkBit server, see Eclipse hawkBit.
Access the hawkBit Server Management user interface by using this URL:
http://
IpAddress
:8080
IpAddress
is the IP address of the machine runining the hawkBit server.Use the following default credentials.
username — admin
password — admin
Generate a key to use as a gateway token. In the hawkBit Server Management user interface, go to System Config > Authentication Configuration and select the Allow a gateway to authenticate and manage multiple targets through a gateway security token checkbox. The key appears below the checkbox.
Click Save to save the settings.
The gateway token is required to set up the OTA client. Consequently, OTA clients running on the target machines use this token to connect to the hawkBit server for installs and updates.
Setup OTA Client on Target
Enable the OTA client on target. Specify the target name as
targetName
and the poll interval in seconds. For every specified poll interval, the OTA client polls the OTA Server for updates.
enableOTAClient('targetName', 10)
Set OTA Server configuration details.
setupOTAServerConfiguration();
In the dialog box that opens, enter the details of the hawkBit server.
IP Address — Specify the IPv4 address of the machine on which the hawkBit server runs.
Port — Specify the port number used by the hawkBit server. The default port number is 8080.
Gateway Token — Specify the gateway token of the hawkBit server from the hawkBit Server Management UI.
Click OK.
In the Linux Runtime Manager, disconnect and connect the target again.
Reconnecting to the target results in an error with an option to restart the docker container. Use that option to restart the docker container and connect again.
The hostname of the machine on which the OTA client runs appears in the Targets table of the Deployment section of the hawkBit Server Management user interface after it is connected.
Provide Required Permissions
Get the deployment location of the target.
tg = linuxTarget('targetName')
tg.DeploymentLocation
Log in to the target machine and run this command in a terminal to provide the required permissions for the OTA client.
sudo chmod -R 777 <deploymentLocation>
Create Application Package from Updated Architecture Model
Verify that the model LightControlSystem
is closed before creating the application package for the updated model. Ensure that you are in the LightControlSystemUpdated folder in the example directory to perform the following steps.
In the Linux Runtime Manager:
In the toolstrip, in the Prepare section, click Create & Deploy Application Package > Create to create the application package containing the executable from the updated architecture model.
In the dialog box that opens, select the
LightControlSystem
model in theLightControlSystemUpdated
folder.
Get back into the example directory.
Create an Update
Upload Application Package
In the hawkBit Server Management user interface, go to the Upload section from the left pane.
Create a software module of type Application.
Specify the application package name in Name field, specify a value in the Version field, and then click Save.
The specified version used here is not considered by the OTA client in Linux target.
Click the Upload file button, select the application package (.mldatx file) created in the above step, and upload it.
Add a Distribution
In the hawkBit Server Management user interface, go to the Distributions section from the left pane.
Create a distribution of type
App(s) only
.Specify a name and specify the version as
'1.0'
.Drag and drop the software module on the right pane onto the created distribution on the left pane.
Add a Target Filter
In the hawkBit Server Management user interface, go to the Target Filters section from the left pane.
Create a new filter.
Specify the Name field as
'Default filter
'
'name==*'
.Click Save.
This is a one-time setup and can be reused by other rollouts.
Create a Rollout
To create a rollout, the OTA client has to be identified in the hawkBit Server Management user interface. If not, then you cannot create a rollout. Go to the Deployment section to check if the OTA client has been identified.
Once you have verified that the OTA client has been identified, create the rollout:
In the hawkBit Server Management UI, go to the Rollout section from the left pane.
Create a new rollout campaign. In the Create new Rollout dialog box, specify a name.
Select the distribution set you created.
Set the Custom Target Filter to
Default,
specify Number of groups as 1, and then click Save.Click Run on the right side of your rollout campaign to activate the deployment.
Apply the Update
Wait for the OTA client to poll for updates and find the new deployment campaign. When the update is downloaded, you can check the hawkBit Server Management user interface and see that the status of your rollout campaign has changed.
The deployed application in the Linux Runtime Manager is updated with four components.
Disable OTA Client
Disable the OTA client on the target.
disableOTAClient(targetName);
See Also
Linux Runtime Manager | linux.createApplicationPackage
| deployApplicationPackage