Skip to content

Commit

Permalink
Merge pull request #38 from CivicTechTO/platformio-only
Browse files Browse the repository at this point in the history
Remove Arduino IDE support
  • Loading branch information
tcsullivan authored Nov 2, 2024
2 parents 0307c10 + bd9d926 commit 6319bfd
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 79 deletions.
1 change: 0 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ jobs:
- name: Create header files
run: |
cp "${GITHUB_WORKSPACE}/noisemeter-device/config.h.example" "${GITHUB_WORKSPACE}/noisemeter-device/config.h"
python "${GITHUB_WORKSPACE}/noisemeter-device/certs.py" -s api.tracket.info > "${GITHUB_WORKSPACE}/noisemeter-device/certs.h"
- name: Build PlatformIO Project (esp32-pcb)
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/ota-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ jobs:
OTA_KEY: ${{ secrets.OTA_SIGNING_KEY }}
run: |
echo "$OTA_KEY" > "${GITHUB_WORKSPACE}/priv_key.pem"
cp "${GITHUB_WORKSPACE}/noisemeter-device/config.h.example" "${GITHUB_WORKSPACE}/noisemeter-device/config.h"
python "${GITHUB_WORKSPACE}/noisemeter-device/certs.py" -s api.tracket.info > "${GITHUB_WORKSPACE}/noisemeter-device/certs.h"
- name: Build signed firmware
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ The source code is released under the [GNU GPL v3 license](/noisemeter-device/LI

## Hardware Files

The [hardware](/hardware) folder contains design files and documentation for each iteration of the noisemeter hardware. The PCBs are designed using [KiCAD](https://www.kicad.org/).
The [hardware](/hardware) folder contains design files and documentation for each iteration of the sensor hardware. The PCBs are designed using [KiCAD](https://www.kicad.org/).

The hardware design files are released under an [open hardware license](/hardware/pcb-rev2/LICENSE).

## For Developers

* Check out the [Issues page](https://github.com/CivicTechTO/proj-noisemeter-device/issues) to see current bugs and feature requests. Any contributions are welcome!
* Check out the [Issues page](https://github.com/CivicTechTO/tRacket-sensor/issues) to see current bugs and feature requests. Any contributions are welcome!
* Online documentation of the firmware [is available here](https://civictechto.github.io/tRacket-sensor/).

40 changes: 15 additions & 25 deletions noisemeter-device/BUILD.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,28 @@
python certs.py -s api.tracket.info > certs.h
```

2. Copy `config.h.example` to `config.h`; if compiling with the Arduino IDE, edit the file to select your board type.

## Code compiling and upload

### PlatformIO
## Code compilation and upload

1. [Install PlatformIO](https://platformio.org/install).

2. Run `pio run` to compile for the PCB. A breadboard target is available too: `pio run -e esp32-breadboard`.

3. Run `pio run -t upload` to upload to the device (this also compiles the code if there have been any changes).

### Arduino

1. Install the Arduino IDE and [follow these instructions](https://docs.espressif.com/projects/arduino-esp32/en/latest/installing.html) to add support for ESP32 microcontrollers.

2. Under "Tools" > "Board: " > "ESP32 Arduino", select either "ESP32C3 Dev Module" for the PCB boards or "ESP32-WROOM-DA Module" for the ESP32 breadboard prototype.

3. Compile the sketch and upload it to the device.

## HMAC encryption key

Data stored on the device (e.g. WiFi credentials) are encrypted with an "eFuse" key. This key can only be written once, and is not be read or written after that.

Using PlatformIO:
Data stored on the device (e.g. WiFi credentials) are encrypted with an "eFuse" key. This key can only be configured once, and cannot be read or written after that.

```bash
dd if=/dev/urandom of=hmac_key bs=1 count=32
pio pkg exec -- espefuse.py --port /dev/ttyACM0 burn_key BLOCK4 hmac_key HMAC_UP
rm hmac_key
```

This is done in the `bringup.sh` script that is used to program new sensors.

**Please generate a unique hmac_key for each device.**

## Enable secure download mode

Enabling secure download mode prevents users from using USB/serial download mode to dump memory contents (WiFi credentials and API token):
Expand All @@ -54,21 +45,20 @@ pio pkg exec -- esptool.py write_flash 0x10000 .pio/build/esp32-pcb/firmware.bin

## Signing OTA updates

A 4096-bit RSA key is used to sign OTA updates. Whoever controls the private OTA signing key can create a public key with this command and include its contents in `noisemeter_device/ota_update.cpp`:
OTA updates must be signed for deployed tRacket sensors to accept them. The
GitHub repo is configured to automatically sign firmware updates when releases
are published.

```bash
openssl rsa -in priv_key.pem -pubout > rsa_key.pub
```
Signing requires a 4096-bit RSA key. To sign an update (assuming you have the
private key), run `pio run -t ota`.

They may also sign a firmware update with these commands (the signature is prepended to the firmware binary):
The public key is to be stored in `noisemeter_device/ota_update.cpp`. To obtain
the public key (assuming you have the private key), run:

```bash
openssl dgst -sign priv_key.pem -keyform PEM -sha256 -out firmware.sign -binary .pio/build/esp32-pcb/firmware.bin
cat firmware.sign .pio/build/esp32-pcb/firmware.bin > firmware_signed.bin
openssl rsa -in priv_key.pem -pubout > rsa_key.pub
```

`firmware_signed.bin` is then uploaded to the OTA server.

## Operation Overview:

* After initial programming or a factory reset, the device will enter Hotspot mode once it is powered on. This is indicated by a blinking LED.
Expand Down
2 changes: 1 addition & 1 deletion noisemeter-device/Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -1003,7 +1003,7 @@ RECURSIVE = YES
# Note that relative paths are relative to the directory from which doxygen is
# run.

EXCLUDE = doc certs.h secret.h config.h
EXCLUDE = doc certs.h secret.h

# The EXCLUDE_SYMLINKS tag can be used to select whether or not files or
# directories that are symbolic links (a Unix file system feature) are excluded
Expand Down
6 changes: 1 addition & 5 deletions noisemeter-device/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
///
/// Each supported board must have a defined section here to specify the
/// hardware pins and peripherals being used. Selecting a board for
/// compilation is done either through PlatformIO or config.h.
/// compilation is done through PlatformIO.
/* noisemeter-device - Firmware for CivicTechTO's Noisemeter Device
* Copyright (C) 2024 Clyne Sullivan, Nick Barnard
*
Expand All @@ -23,8 +23,6 @@
#ifndef BOARD_H
#define BOARD_H

#include "config.h"

#undef SERIAL

#if defined(BOARD_ESP32_PCB)
Expand Down Expand Up @@ -52,10 +50,8 @@
/** Serial instance to use for logging output. */
#define SERIAL USBSerial

#if defined(BUILD_PLATFORMIO)
#include <HWCDC.h>
extern HWCDC USBSerial;
#endif

#elif defined(BOARD_ESP32_BREADBOARD)

Expand Down
37 changes: 0 additions & 37 deletions noisemeter-device/config.h.example

This file was deleted.

5 changes: 1 addition & 4 deletions noisemeter-device/noisemeter-device.ino
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,10 @@
#include <list>
#include <optional>

#if defined(BUILD_PLATFORMIO) && defined(BOARD_ESP32_PCB)
#ifdef BOARD_ESP32_PCB
HWCDC USBSerial;
#endif

// Uncomment these to disable WiFi and/or data upload
//#define UPLOAD_DISABLED

/** Maximum number of seconds to wait for successful WiFi connection. */
constexpr auto WIFI_CONNECT_TIMEOUT_SEC = MIN_TO_SEC(2);
/** Maximum number of seconds to try making new WiFi connection. */
Expand Down
1 change: 0 additions & 1 deletion noisemeter-device/storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "config.h"
#include "storage.h"

#include <Arduino.h>
Expand Down
12 changes: 10 additions & 2 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,18 @@ build_unflags =
-std=gnu++11
build_flags =
-std=gnu++17
-DBUILD_PLATFORMIO
-DNO_GLOBAL_EEPROM
-DNOISEMETER_VERSION=\"0.2.2\"
-DNOISEMETER_VERSION=\"0.2.2\"
-Wall -Wextra

# Optional build flags:
# Print credentials over serial (for debugging):
# -DSTORAGE_SHOW_CREDENTIALS
# Print verbose API logging over serial (for debugging):
# -DAPI_VERBOSE
# Disable WiFi and data upload:
# -DUPLOAD_DISABLED

[env:esp32-pcb]
board = esp32-c3-devkitm-1
board_build.f_cpu = 80000000L
Expand All @@ -40,3 +47,4 @@ build_flags = ${env.build_flags} -DBOARD_ESP32_PCB
[env:esp32-breadboard]
board = upesy_wroom
build_flags = ${env.build_flags} -DBOARD_ESP32_BREADBOARD

0 comments on commit 6319bfd

Please sign in to comment.