# ref-wem-firmware
**Repository Path**: mirrors_ARMmbed/ref-wem-firmware
## Basic Information
- **Project Name**: ref-wem-firmware
- **Description**: Workplace Environment Monitor firmware
- **Primary Language**: Unknown
- **License**: Apache-2.0
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2020-08-08
- **Last Updated**: 2025-11-22
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
## Workplace Environmental Monitor
### Purpose
This is an Arm Mbed reference deployment application of a workplace environmental monitor. The monitor contains environmental sensors for light, temperature and humidity. The sensor values are uploaded to Arm Mbed Cloud 1.2. The application also demonstrates firmware updates using the firmware-over-the-air (FOTA) capabilities of Mbed and Mbed Cloud. A desktop plastic case contains the monitor. It is battery powered and has LED indicators and an LCD display.
Photo
### Prerequisites
To build this project, you need to install the following:
1. Mac OS X or Linux build system. Windows is not supported.
2. [GNU Arm Compiler](https://developer.arm.com/open-source/gnu-toolchain/gnu-rm/downloads) version 6.3.1.20170215 or greater.
Here is an example showing how to install on a Mac:
```
brew tap ARMmbed/homebrew-formulae
brew install arm-none-eabi-gcc
```
Here is an example showing how to install on a Ubuntu 16.04:
```
sudo add-apt-repository ppa:team-gcc-arm-embedded/ppa
sudo apt-get update
sudo apt-get install gcc-arm-embedded
```
3. Python 2.7.12+ and pip 9.0.3.
On a Mac, pip and virtualenv are not preinstalled. Here is how to install them:
```
sudo easy_install pip
sudo pip install virtualenv virtualenvwrapper
```
4. [Python virtualenv](https://virtualenv.pypa.io/en/stable/userguide/).
We *strongly* recommend you use a Python virtualenv to isolate your build environment from the underlying system. If you do this step before you clone the `ref-wem-firmware` repo, then the venv folder is placed outside of the ref-wem-firmware folder, which we recommend. If instead you place venv in the root of the ref-wem-firmware project, you need to add venv to `.mbedignore` to prevent Mbed CLI from attempting to build the files inside it.
```
virtualenv --no-site-packages --python=$(which python) venv
source venv/bin/activate
```
5. Copy your SSH public key to GitHub.
The build preparation step involves cloning libraries from GitHub using ssh, so you need to add an ssh key from your development system to your GitHub account. Please see [instructions](https://help.github.com/articles/connecting-to-github-with-ssh/) for more details.
### Importing `ref-wem-firmware`
Arm Mbed CLI can import the project, along with the Arm Mbed OS codebase and all dependent device drivers.
To import the project from the command-line:
1. Navigate to a workspace directory of your choice.
``cd ~/workspace``
2. Import the example:
```
git clone git@github.com:ARMmbed/ref-wem-firmware.git
cd ref-wem-firmware
```
`ref-wem-firmware` is now under `~/workspace/ref-wem-firmware`. You can look at `main.cpp` to familiarize yourself with the code.
3. Install the Python dependencies:
Some Mbed libraries rely on pip internals which were reorganized in version 10. Please make sure you are running pip
9.0.3 to avoid dependency installation failures:
```
pip install --upgrade pip==9.0.3
```
Next, you can install all the Python dependencies:
```
pip install -r requirements.txt
```
### Specifying a network configuration
The project configuration file `mbed_app.json` specifies the network configuration. Open `mbed_app.json`, and modify the following configuration values to suit the deployment environment:
```
...
"wifi-ssid": {
"help": "The SSID to connect to if using a WiFi interface",
"value": "\"MYSSID\""
},
"wifi-security": {
"help": "WPA, WPA2, WPA/WPA2, WEP, NONE, OPEN",
"value": "\"WPA2\""
},
"wifi-password": {
"help": "An optional password for wifi security authentication",
"value": "\"MYPASSWORD\""
}
...
```
You can also change the configuration at runtime by using a serial console. See the section [Serial command help](#serial-command-help) for help connecting to and using the console. See the section on [Wi-Fi commissioning](#wi-fi-commissioning) for the relevant keystore options.
### Downloading a developer certificate
A certificate is required for the end device to be able to communicate with Mbed Cloud. Log on to the Mbed Cloud portal, and navigate to `Device Identity -> Certificates`.
If creating a new certificate, select the `Actions` pulldown, and choose `Create a developer certificate`. Fill in the form, and click `Create Certificate`. At this time, you may download the certificate onto the local system. Place the certificate C file in the root folder of the project.
If downloading an existing certificate, choose the name of the appropriate certificate from the list of certificates presented on the Certificates page. Click `Download Developer C file`, and place the certificate C file in the root folder of the project.
### Compiling
The project uses a Makefile to compile the source code. The Makefile detects the toolchain and target and calls the Mbed compiler with appropriate options. To build for the current hardware, you may need to set your Mbed target to UBLOX_EVK_ODIN_W2.
If you are compiling with GCC, your `.mbed` file looks like the following:
```
$ cat .mbed
ROOT=.
TARGET=UBLOX_EVK_ODIN_W2
TOOLCHAIN=GCC_ARM
```
If the file does not exist, you can either allow the Makefile to create it with default settings or create it yourself with the following commands:
```
$ mbed config ROOT .
$ mbed target UBLOX_EVK_ODIN_W2
$ mbed toolchain GCC_ARM
```
Typing `make` builds the bootloader and application and combines them into a single image. The final images are copied into the `bin/` folder.
```
$ make
```
#### Compilation errors
The project fails to compile if a developer certificate is not present in the local source directory. This file is typically named `mbed_cloud_dev_credentials.c` and defines several key constants. Please see [Downloading a developer certificate](#GetDevCert) for more information.
A missing certificate results in compilation errors similar to the following:
```
./BUILD/UBLOX_EVK_ODIN_W2/GCC_ARM/mbed-cloud-client-restricted/factory_client/factory_configurator_client/source/fcc_dev_flow.o: In function `fcc_developer_flow':
fcc_dev_flow.c:(.text.fcc_developer_flow+0x130): undefined reference to `MBED_CLOUD_DEV_BOOTSTRAP_ENDPOINT_NAME'
fcc_dev_flow.c:(.text.fcc_developer_flow+0x138): undefined reference to `MBED_CLOUD_DEV_BOOTSTRAP_SERVER_ROOT_CA_CERTIFICATE'
fcc_dev_flow.c:(.text.fcc_developer_flow+0x13c): undefined reference to `MBED_CLOUD_DEV_BOOTSTRAP_SERVER_ROOT_CA_CERTIFICATE_SIZE'
...
```
#### Cleaning the build
```
make clean
```
`make clean` cleans the C++ compile output.
```
make distclean
```
`make distclean` removes all dependency files and generated files.
### Flashing your board
**Important:** Do not remove battery while running this firmware on the device.
**Important:** This version of the workplace environment monitor supports a software-generated Root of Trust mechanism called Software One Time Programming (SOTP). SOTP generates a random private key and stores it on the internal flash. The key is used for secure storage of configuration data related to the Mbed Cloud Client. ***Be aware that flashing your board destroys any previously existing software Root of Trust stored on the internal flash***, which means that your device is no longer able to register with Mbed Cloud. This is true of the current version of DAPLink, version 0246. Look for a future version of DAPLink to support preservation of the SOTP section during a flash.
Until DAPLink is updated, you must execute `reset certs` on the serial command-line interface or perform a factory reset after the flash is complete. You can perform a factory reset by holding down the button next to the power switch while you power on the device and releasing the button when the LCD displays **Factory Reset**. After resetting the certificates, new Mbed Cloud certificates and a new Device ID are generated using a new Root of Trust.
The Root of Trust is preserved when performing a firmware update over the air (FOTA).
For more about SOTP, [see the Mbed Cloud migration guide](https://cloud.mbed.com/docs/current/porting/changing-a-customized-porting-layer.html).
The following command copies `bin/combined.hex` to a USB-attached device.
```
make install
```
If this command fails or you have more than one device attached to your build system, you can manually copy the image to the device. For example:
```
$ cp bin/combined.hex /Volumes/DAPLINK/
```
Be sure to substitute for the correct mount point of your device.
### Update over the air
Log in to the Mbed Cloud portal, and copy your Mbed Cloud API key, which is a one-line string, into a new file called `.mbed-cloud-key`. Store this file in the root directory of this project. For more information, see [Access Mbed Cloud with API Keys](https://cloud.mbed.com/docs/v1.2/connecting/api-keys.html).
NOTE: If you are updating a device that was previously provisioned to a different Mbed Cloud account, you must `reset certs` on the local device before initiating a campaign. Otherwise, the FOTA operation encounters authorization failures. See the section ["Serial command help"](#serial-command-help) for details on how to run commands on the device.
Before starting the FOTA campaign, increment the version of your application.
Open the file `mbed_app.json` in the editor of your choice, and increment the version number.
Change from:
```
"version": {
"help": "Display this version string on the device",
"value": "\"1.0\""
},
```
to:
```
"version": {
"help": "Display this version string on the device",
"value": "\"1.1\""
},
```
Next, open your shell to your project folder.
```
make campaign
```
This launches the FOTA campaign and begins updating all the devices in your account.
### Serial command help
You can connect a serial terminal to the device for the purpose of viewing diagnostic output and issuing serial commands. Serial connection is at a baud rate of 115200.
Press enter at any time to get a command prompt:
```
>
```
Typing `help` at the prompt provides a list of the commands and a brief set of usage instructions:
```
> help
Help:
del - Delete a configuration option from the store. Usage: del