diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..3d0ce40 --- /dev/null +++ b/.github/workflows/ci.yml @@ -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 diff --git a/.gitignore b/.gitignore index 2c09404..9951a0a 100644 --- a/.gitignore +++ b/.gitignore @@ -11,8 +11,8 @@ OpenConstructESP32 .libdeps # PlatformIO +.pio-venv/ .travis.yml -platformio.ini # Arduino *.hex diff --git a/README.md b/README.md index 8ae39cc..a682666 100644 --- a/README.md +++ b/README.md @@ -18,17 +18,17 @@ Arduino/ESP32 library that lets microcontrollers participate as **Plato shells** ```cpp #include -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 } ``` diff --git a/examples/basic_shell/basic_shell.ino b/examples/basic_shell/basic_shell.ino index 6fcd569..fbd4469 100644 --- a/examples/basic_shell/basic_shell.ino +++ b/examples/basic_shell/basic_shell.ino @@ -1,4 +1,4 @@ -#include +#include // WiFi credentials - replace with your own const char* WIFI_SSID = "your_wifi_ssid"; diff --git a/library.json b/library.json new file mode 100644 index 0000000..779a81c --- /dev/null +++ b/library.json @@ -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" +} diff --git a/library.properties b/library.properties index 42cbec3..e279ed8 100644 --- a/library.properties +++ b/library.properties @@ -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 \ No newline at end of file +depends=PubSubClient \ No newline at end of file diff --git a/platformio.ini b/platformio.ini new file mode 100644 index 0000000..a20edeb --- /dev/null +++ b/platformio.ini @@ -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 diff --git a/src/OpenConstructESP32.cpp b/src/OpenConstructESP32.cpp index 96f56f3..4a1702c 100644 --- a/src/OpenConstructESP32.cpp +++ b/src/OpenConstructESP32.cpp @@ -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") { @@ -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") { diff --git a/src/TextSensor.cpp b/src/TextSensor.cpp index 91c797a..540e60a 100644 --- a/src/TextSensor.cpp +++ b/src/TextSensor.cpp @@ -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") { @@ -66,7 +67,8 @@ String formatSensorStatus(const std::vector& sensors) { String result = ""; for (const auto& sensor : sensors) { - String sensorType = sensor.type.toLowerCase(); + String sensorType = sensor.type; + sensorType.toLowerCase(); String valueText; if (sensorType == "digital") {