Skip to content
Open
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
30 changes: 30 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: PlatformIO CI

on:
push:
branches:
- '**'
pull_request:
branches:
- '**'

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'

- name: Install PlatformIO
run: pip install platformio

- name: Build esp32dev
run: pio run -e esp32dev

- name: Compile tests
run: pio test -e test --without-uploading --without-testing
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ OpenConstructESP32
.libdeps

# PlatformIO
.pio-venv/
.travis.yml
platformio.ini

# Arduino
*.hex
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ Arduino/ESP32 library that lets microcontrollers participate as **Plato shells**
```cpp
#include <openconstruct-esp32.h>

OpenConstructESP32 node("kitchen-sensor");
OpenConstructESP32 node;

void setup() {
node.begin("WiFiSSID", "WiFiPass");
node.registerDigitalSensor("door", 4); // GPIO 4
node.registerAnalogSensor("light", 34); // ADC on GPIO 34
node.registerTemperatureSensor("temp", 23); // DHT22 on GPIO 23
node.begin("kitchen-sensor", "WiFiSSID", "WiFiPass");
node.registerSensor(4, "door", "digital"); // GPIO 4
node.registerSensor(34, "light", "analog"); // ADC on GPIO 34
node.registerSensor(23, "temp", "temperature"); // DHT22 on GPIO 23
}

void loop() {
node.loop(); // handles MQTT, mDNS, command parsing, sensor reporting
node.update(); // handles MQTT, mDNS, command parsing, sensor reporting
}
```

Expand Down
2 changes: 1 addition & 1 deletion examples/basic_shell/basic_shell.ino
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <OpenConstructESP32.h>
#include <openconstruct-esp32.h>

// WiFi credentials - replace with your own
const char* WIFI_SSID = "your_wifi_ssid";
Expand Down
23 changes: 23 additions & 0 deletions library.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "OpenConstructESP32",
"version": "0.1.0",
"description": "Ultralight ESP32 edge node library for OpenConstruct networks",
"keywords": "openconstruct, esp32, mqtt, agent, sensor",
"repository": {
"type": "git",
"url": "https://github.com/SuperInstance/openconstruct-esp32.git"
},
"authors": [
{
"name": "SuperInstance",
"email": "dev@superinstance.com"
}
],
"license": "MIT",
"homepage": "https://github.com/SuperInstance/openconstruct-esp32",
"dependencies": {
"knolleary/PubSubClient": "^2.8"
},
"frameworks": "arduino",
"platforms": "espressif32"
}
3 changes: 1 addition & 2 deletions library.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ paragraph=OpenConstructESP32 enables ESP32 devices to participate as Plato shell
category=Communication
url=https://github.com/SuperInstance/openconstruct-esp32
architectures=esp32
depends=
depends_on=PubSubClient
depends=PubSubClient
24 changes: 24 additions & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[platformio]
src_dir = examples/basic_shell
test_dir = test

[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
lib_deps =
knolleary/PubSubClient @ ^2.8
lib_extra_dirs =
.

[env:test]
platform = espressif32
board = esp32dev
framework = arduino
lib_deps =
knolleary/PubSubClient @ ^2.8
lib_extra_dirs =
.
lib_ldf_mode = deep
test_build_src = no
test_framework = unity
6 changes: 4 additions & 2 deletions src/OpenConstructESP32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ void OpenConstructESP32::registerSensor(int pin, const char* name, const char* t
s.lastRead = 0;

// Configure pin based on type
String sensorType = String(type).toLowerCase();
String sensorType = String(type);
sensorType.toLowerCase();
if (sensorType == "digital") {
pinMode(pin, INPUT);
} else if (sensorType == "analog") {
Expand Down Expand Up @@ -150,7 +151,8 @@ void OpenConstructESP32::subscribeToCommands() {

void OpenConstructESP32::readSensors() {
for (auto& sensor : _sensors) {
String sensorType = sensor.type.toLowerCase();
String sensorType = sensor.type;
sensorType.toLowerCase();
float value = 0.0;

if (sensorType == "digital") {
Expand Down
6 changes: 4 additions & 2 deletions src/TextSensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ String describeMotion(float value) {
}

String describeSensor(const Sensor& sensor) {
String sensorType = sensor.type.toLowerCase();
String sensorType = sensor.type;
sensorType.toLowerCase();
String description;

if (sensorType == "digital") {
Expand Down Expand Up @@ -66,7 +67,8 @@ String formatSensorStatus(const std::vector<Sensor>& sensors) {

String result = "";
for (const auto& sensor : sensors) {
String sensorType = sensor.type.toLowerCase();
String sensorType = sensor.type;
sensorType.toLowerCase();
String valueText;

if (sensorType == "digital") {
Expand Down
Loading