Skip to content

Commit

Permalink
remove arduino build flags and update instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
tcsullivan committed Apr 18, 2024
1 parent a869d37 commit dc721aa
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 80 deletions.
50 changes: 20 additions & 30 deletions noisemeter-device/BUILD.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Build Instructions

## Required Software

Building the noisemeter device code requires PlatformIO: [PlatformIO Installation](https://docs.platformio.org/en/latest/core/installation/methods/index.html).

Once installed, you should be able to execute a `pio` command from your terminal.

## Source code preparation

1. Update SSL certificate using the following command:
Expand All @@ -14,45 +20,29 @@ const char* API_TOKEN = "Your API token here";
```
(Replace "Your API token here" with your API token)

3. Copy `config.h.example` to `config.h` and edit the file to select your board type and set your device ID.

## Code compiling and upload

### PlatformIO

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).
From the `proj-noisemeter-device` directory, run `pio run` to compile the device's code. To compile for the "breadboard" prototype, run `pio run -e esp32-breadboard`.

### 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.
To upload the code to a device (that is plugged into your computer), run `pio run -t upload`. This command will also compile the code if any changes have been made; to skip recompilation, run `pio run -t nobuild -t upload`.

## 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.
User data stored on the device (e.g. WiFi credentials) is encrypted with a secure "eFuse" key. This key can only be programmed once, so the below steps only apply to factory-fresh devices. A device can still be used and tested without programming this key; the default key is simply all zeros.

Using PlatformIO:
1. Create a 32-byte file of random key data. This can be done either with a text editor (type in 32 random characters) or with a tool like `dd`: `dd if=/dev/urandom of=hmac_key bs=1 count=32`.

```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
```
2. Program the key to a connected device (changing port path "/dev/ttyACM0" or key filename "hmac\_key" if needed): `pio pkg exec -- espefuse.py --port /dev/ttyACM0 burn_key BLOCK4 hmac_key HMAC_UP`.

# Operating Instructions:

- Power on the device by connecting it to power. The device should start in Hotspot mode.
- Connect to device's wifi hotspot, which will be called "Noise Meter". Password is "noisemeter".
- Open a web browser and navigate to IP address 4.3.2.1 and fill out your Wifi network SSID and password. This will then bbe saved to the onboard flash, and should persist between restarts.
- The device should reset and begin attempting to connect to wifi. Use Serial monitor to confirm this.
- Once connected, the device will sync itself with a NTP time server and then begin taking readings.
- The device fills a buffer with integer readings from the microphone until it has enough to
- Periodically (at a time interval determined by UPLOAD_INTERVAL_MS) the device will collate its data and upload it to the server, whereupon it will clear its cached data and begin taking readings again.
- To clear your saved information, hold the Reset button (Pin 5 in this example) while you power on the device, or hold the Reset button and reset the device using the built-in reset button.
1. Power on the device. The device should enter Hotspot mode, indicated by a flashing LED.
2. Connect to the device's WiFi hotspot, which will be called "Noise meter". Password is "noisemeter".
3. You should be automatically redirected to a setup form; if not, go to "http://8.8.4.4" in your web browser.
4. Enter your WiFi network's name (SSID) and password.
5. Once submitted, the device will restart and attempt to connect to your WiFi. If the LED turns off, the connection was successful. If the LED blinks, the connection failed and the hotspot is available for reconfiguration.
6. While running, the device will take decibel noise measurements based on short 128ms recordings. Every five minutes, statistics about the decibel measurments (minimum, maximum, and average values) will be sent to the server.
7. To factory reset the device, hold down the Reset button while you power on the device. Release the button once you see the blinking LED; this should only take a few seconds.

For testing, the device's serial output can be viewed with a serial monitor while plugged into a computer. The output includes the device's ID, version number, error messages, and decibel readings.

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
34 changes: 0 additions & 34 deletions noisemeter-device/config.h.example

This file was deleted.

9 changes: 0 additions & 9 deletions noisemeter-device/noisemeter-device.ino
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,7 @@
#include <iterator>
#include <optional>

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

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

/** Maximum number of milliseconds to wait for successful WiFi connection. */
constexpr auto WIFI_CONNECT_TIMEOUT_MS = 20 * 1000;
Expand Down Expand Up @@ -359,11 +354,7 @@ int tryWifiConnection()

String createJSONPayload(const DataPacket& dp)
{
#ifdef BUILD_PLATFORMIO
JsonDocument doc;
#else
DynamicJsonDocument doc (2048);
#endif

doc["parent"] = "/Bases/nm1";
doc["data"]["type"] = "comand";
Expand Down
4 changes: 3 additions & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ build_unflags =
-std=gnu++11
build_flags =
-std=gnu++17
-DBUILD_PLATFORMIO
-DNO_GLOBAL_EEPROM
-DNOISEMETER_VERSION=\"0.0.4\"
-Wall -Wextra
# Optional build flags:
# -DSTORAGE_SHOW_PASSKEY Print passkey over serial.
# -DUPLOAD_DISABLED Disable WiFi and data upload.

[env:esp32-pcb]
board = esp32-c3-devkitm-1
Expand Down

0 comments on commit dc721aa

Please sign in to comment.