Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Update sensors to build using arduino-cli #523

Merged
merged 6 commits into from
Jun 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 10 additions & 17 deletions sensors/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ TARGET_DIR=$(CURDIR)/bin
LIB_DIR=$(CURDIR)/lib

# variables for tools
ARDUINO_PATH=@ARDUINO_PATH@
SERIAL_PORT?=/dev/ttyUSB0

# versions of libraries
Expand Down Expand Up @@ -66,33 +65,27 @@ $(LIB_DIR)/cert.pem:
wget -O $@ https://letsencrypt.org/certs/lets-encrypt-r3.pem

# Generate certificate header
src/cert.h: $(LIB_DIR)/cert.pem
cp src/cert.h.in $@
powerpi-sensor/cert.h: $(LIB_DIR)/cert.pem
cp powerpi-sensor/cert.h.in $@
sed -i -e '/@CERT@/{r $<' -e 'd}' $@

# compile the sketch
$(TARGET_DIR)/$(SKETCH).bin: src/$(SKETCH) common_libraries dht22_libaries src/cert.h
$(TARGET_DIR)/$(SKETCH).bin: powerpi-sensor/$(SKETCH) common_libraries dht22_libaries powerpi-sensor/cert.h
mkdir -p $(TARGET_DIR)
$(ARDUINO_PATH)/arduino-builder \
-compile \
-hardware "$(ARDUINO_PATH)/hardware" \
-tools "$(ARDUINO_PATH)/tools-builder" \
-tools "$(ARDUINO_PATH)/hardware/tools/avr" \
-built-in-libraries "$(ARDUINO_PATH)/libraries" \
-fqbn=esp8266com:esp8266:generic \
-libraries "$(LIB_DIR)" \
-build-path "$(TARGET_DIR)" \
arduino-cli compile \
--fqbn esp8266:esp8266:generic \
--libraries "$(LIB_DIR)" \
--build-path "$(TARGET_DIR)" \
$<

compile: $(TARGET_DIR)/$(SKETCH).bin

# deploy the binary to the device
flash: $(TARGET_DIR)/$(SKETCH).bin
$(ARDUINO_PATH)/hardware/esp8266com/esp8266/tools/upload.py \
arduino-cli upload \
--port $(SERIAL_PORT) \
write_flash \
0x00000 \
$<
--fqbn esp8266:esp8266:generic \
--input-dir $(TARGET_DIR)

monitor:
screen $(SERIAL_PORT) @serial_baud@
Expand Down
9 changes: 5 additions & 4 deletions sensors/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,20 @@ The following pins on the board are used for each different type of sensor
- **temperature/humidity** - _D2_ - _GPIO4_ - for the data pin of the DHT22.

As follows is the circuit diagram for a sensor including both a PIR (motion) and DHT22 (temperature/humidity). Either can be omitted, which can be configured when building the firmware. This circuit diagram was created using [Circuit Diagram](https://www.circuit-diagram.org/editor/).

![PowerPi sensor circuit diagram](./circuit/circuit.svg)

**Note:** When flashing firmware you need to disconnect _D0_ from _RST_ on the microcontroller, otherwise the microcontroller will get stuck in a reset loop. If this connection is not made, when the firmware attempts to use deep-sleep it will not awaken after the timer period has elapsed. The deep-sleep functionality is only possible when the PIR and button sensors are disabled in the firmware, and the `--disable-deep-sleep` option is not passed when configuring.
**Note:** When flashing firmware you need to disconnect _D0_ from _RST_ on the microcontroller, otherwise the microcontroller will get stuck in a reset loop. If this connection is not made, when the firmware attempts to use deep-sleep it will not awaken after the timer period has elapsed. The deep-sleep functionality is only possible when the PIR and button sensors are disabled in the firmware, or the `--disable-deep-sleep` option is not passed when configuring.

## Building

Building the code requires having the Arduino IDE download to your environment and added to your path.
Building the code requires having the [arduino-cli](https://arduino.github.io/arduino-cli) tool installed on your machine and added to your path.

First we must generate the configure script.

```bash
# Add Arduino IDE to your path
PATH=$PATH:/path/to/arduino-ide
# Add arduino-cli to your path
PATH=$PATH:/path/to/arduino-cli

# Generate the configure script
autoconf
Expand Down
22 changes: 6 additions & 16 deletions sensors/configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -87,26 +87,16 @@ AC_ARG_ENABLE(
)
AC_SUBST([enable_button])

dnl Find the Arduino IDE
AC_CHECK_PROG([ARDUINO], [arduino], $(whereis arduino -b | cut -d':' -f 2), [no])
if test "$ARDUINO" == "no"
dnl Check for the Arduino CLI tool
AC_CHECK_PROG([ARDUINO_CLI], [arduino-cli], [yes], [no])
if test "$ARDUINO_CLI" == "no"
then
AC_MSG_ERROR([Required program "arduino" not found.])
AC_MSG_ERROR([Required program "arduino-cli" not found.])
else
ARDUINO_PATH=$(dirname "${ARDUINO}")
AC_SUBST([ARDUINO_PATH])
fi

dnl Check for the Arduino builder tool
AC_CHECK_PROG([ARDUINO_BUILDER], [arduino-builder], [yes], [no])
if test "$ARDUINO_BUILDER" == "no"
then
AC_MSG_ERROR([Required program "arduino-builder" not found.])
else
arduino-builder -version
arduino-cli version
fi

dnl Generate the Makefile and config.h
AC_CONFIG_FILES([Makefile src/config.h])
AC_CONFIG_FILES([Makefile powerpi-sensor/config.h])

AC_OUTPUT
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void setupPowerPiConfig() {
}

void useDefaultConfig() {
// we have to intiailise with the default values
// we have to initialise with the default values
Serial.println();
configureGeneral(POLL_DELAY);

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.