Skip to content

Commit 486bd51

Browse files
author
Miles Burton
committed
feat: Add basic dev container to aid for quicker debugging of the Arduino-Temperature-Control-Library
1 parent c4e76a5 commit 486bd51

File tree

5 files changed

+218
-0
lines changed

5 files changed

+218
-0
lines changed

.devcontainer/Dockerfile

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
FROM mcr.microsoft.com/vscode/devcontainers/cpp:debian
2+
3+
# Install required packages
4+
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
5+
&& apt-get -y install --no-install-recommends \
6+
python3 \
7+
python3-pip \
8+
git \
9+
curl \
10+
&& apt-get clean \
11+
&& rm -rf /var/lib/apt/lists/*
12+
13+
# Install arduino-cli
14+
RUN curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | sh
15+
16+
# Set up arduino-cli config
17+
RUN arduino-cli config init
18+
19+
# Add arduino-cli to PATH
20+
ENV PATH="/usr/local/bin:${PATH}"
21+
22+
# Create workspace directory
23+
WORKDIR /workspace
24+
25+
# Copy arduino-cli configuration
26+
COPY arduino-cli.yaml /root/.arduino15/arduino-cli.yaml
27+
28+
# Install build essentials
29+
RUN apt-get update && apt-get install -y build-essential
30+
31+
# Install common Arduino libraries
32+
RUN arduino-cli lib install \
33+
"OneWire" \
34+
"DallasTemperature" \
35+
"Adafruit BusIO" \
36+
"Adafruit Unified Sensor" \
37+
"DHT sensor library" \
38+
"WiFiManager" \
39+
"ArduinoJson" \
40+
"PubSubClient" \
41+
"ESP8266WiFi" \
42+
"ESP32" \
43+
"Wire" \
44+
"SPI" \
45+
"FastLED" \
46+
"NTPClient" \
47+
"AsyncTCP" \
48+
"ESPAsyncTCP" \
49+
"ESPAsyncWebServer"
50+
51+
# Verify library installation
52+
RUN arduino-cli lib list
53+
54+
# Copy update script
55+
COPY update-libraries.sh /usr/local/bin/
56+
RUN chmod +x /usr/local/bin/update-libraries.sh
57+
58+
# Add a weekly cron job to update libraries
59+
RUN (crontab -l 2>/dev/null; echo "0 0 * * 0 /usr/local/bin/update-libraries.sh > /var/log/library-updates.log 2>&1") | crontab -
60+
61+
# Add aliases for build operations
62+
RUN echo 'alias arduino-build="./build.sh build"' >> /home/vscode/.bashrc && \
63+
echo 'alias arduino-test="./build.sh test"' >> /home/vscode/.bashrc && \
64+
echo 'alias arduino-build-test="./build.sh all"' >> /home/vscode/.bashrc

.devcontainer/arduino-cli.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
board_manager:
2+
additional_urls:
3+
- https://arduino.esp8266.com/stable/package_esp8266com_index.json
4+
- https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
5+
daemon:
6+
port: "50051"
7+
directories:
8+
data: /root/.arduino15
9+
downloads: /root/.arduino15/staging
10+
user: /root/Arduino
11+
library:
12+
enable_unsafe_install: true
13+
logging:
14+
file: ""
15+
format: text
16+
level: info
17+
metrics:
18+
addr: :9090
19+
enabled: true
20+
sketch:
21+
always_export_binaries: false

.devcontainer/devcontainer.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "Arduino Library Development",
3+
"dockerFile": "Dockerfile",
4+
"customizations": {
5+
"vscode": {
6+
"extensions": [
7+
"vsciot-vscode.vscode-arduino",
8+
"ms-vscode.cpptools"
9+
]
10+
}
11+
},
12+
"postCreateCommand": "arduino-cli core install arduino:avr && arduino-cli lib install ArduinoUnit && /usr/local/bin/update-libraries.sh",
13+
"updateContentCommand": "/usr/local/bin/update-libraries.sh",
14+
"remoteUser": "vscode"
15+
}

.devcontainer/update-libraries.sh

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/bin/bash
2+
3+
echo "Updating arduino-cli core and index..."
4+
arduino-cli core update-index
5+
arduino-cli update
6+
7+
echo "Updating installed libraries..."
8+
arduino-cli lib update-index
9+
arduino-cli lib upgrade
10+
11+
# List of libraries to ensure are installed/updated
12+
LIBRARIES=(
13+
"OneWire"
14+
"DallasTemperature"
15+
"Adafruit BusIO"
16+
"Adafruit Unified Sensor"
17+
"DHT sensor library"
18+
"WiFiManager"
19+
"ArduinoJson"
20+
"PubSubClient"
21+
"ESP8266WiFi"
22+
"ESP32"
23+
"Wire"
24+
"SPI"
25+
"FastLED"
26+
"NTPClient"
27+
"AsyncTCP"
28+
"ESPAsyncTCP"
29+
"ESPAsyncWebServer"
30+
)
31+
32+
echo "Checking and installing libraries..."
33+
for lib in "${LIBRARIES[@]}"; do
34+
echo "Processing library: $lib"
35+
if ! arduino-cli lib list | grep -q "$lib"; then
36+
echo "Installing $lib..."
37+
arduino-cli lib install "$lib"
38+
else
39+
echo "$lib is already installed"
40+
fi
41+
done
42+
43+
echo "Verifying all libraries are up to date..."
44+
arduino-cli lib list
45+
46+
echo "Library update complete!"

build.sh

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#!/bin/bash
2+
3+
# Note this is intended for use within the devcontainer
4+
5+
# Set error handling
6+
set -e
7+
8+
# Function to display usage
9+
show_usage() {
10+
echo "Usage: ./build.sh [option]"
11+
echo "Options:"
12+
echo " build - Only compile library and examples"
13+
echo " test - Only compile and run tests"
14+
echo " all - Build everything and run tests (default)"
15+
}
16+
17+
# Function to compile for a specific board
18+
compile_for_board() {
19+
local fqbn=$1
20+
local sketch=$2
21+
echo "📦 Compiling $sketch for $fqbn..."
22+
arduino-cli compile --fqbn $fqbn "$sketch"
23+
}
24+
25+
# Function to build library and examples
26+
build() {
27+
echo "🔨 Building library and examples..."
28+
29+
# Compile library
30+
echo "📚 Installing library..."
31+
arduino-cli lib install .
32+
33+
# Compile all examples
34+
echo "🔍 Compiling examples..."
35+
for example in examples/*/*.ino; do
36+
if [ -f "$example" ]; then
37+
echo "Building example: $example"
38+
compile_for_board "arduino:avr:uno" "$example"
39+
fi
40+
done
41+
}
42+
43+
# Function to run tests
44+
run_tests() {
45+
echo "🧪 Running tests..."
46+
for test in test/*/*.ino; do
47+
if [ -f "$test" ]; then
48+
echo "Running test: $test"
49+
compile_for_board "arduino:avr:uno" "$test"
50+
fi
51+
done
52+
}
53+
54+
# Main execution
55+
case "${1:-all}" in
56+
"build")
57+
build
58+
;;
59+
"test")
60+
run_tests
61+
;;
62+
"all")
63+
build
64+
run_tests
65+
;;
66+
*)
67+
show_usage
68+
exit 1
69+
;;
70+
esac
71+
72+
echo "✅ Process completed!"

0 commit comments

Comments
 (0)