diff --git a/examples/Locker/locker-sketch.ino b/examples/Locker/locker-sketch.ino deleted file mode 100644 index 73a59bd9..00000000 --- a/examples/Locker/locker-sketch.ino +++ /dev/null @@ -1,59 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace uniot; - -#define RELAY_PIN D3 -#define OLED_RESET 0 -Adafruit_SSD1306 display(OLED_RESET); - -auto taskPrintHeap = TaskScheduler::make([](short t) { - Serial.println(ESP.getFreeHeap()); -}); - -auto taskCheckRelay = TaskScheduler::make([](short t) { - if (digitalRead(RELAY_PIN)) { - display.clearDisplay(); - display.setTextSize(2); - display.setTextColor(WHITE); - display.setCursor(9, 16); - display.println("OPEN"); - display.display(); - } else { - display.clearDisplay(); - display.setTextSize(2); - display.setTextColor(WHITE); - display.setCursor(3, 16); - display.println("CLOSE"); - display.display(); - } -}); - -void inject() { - display.begin(SSD1306_SWITCHCAPVCC, 0x3C); - display.clearDisplay(); - - auto &MainAppKit = AppKit::getInstance(PIN_BUTTON, BTN_PIN_LEVEL, D4); - UniotPinMap.setDigitalOutput(2, RELAY_PIN, D4); - digitalWrite(RELAY_PIN, LOW); - MainEventBus.registerKit(&MainAppKit); - - MainScheduler.push(&MainAppKit) - ->push(taskCheckRelay) - ->push(taskPrintHeap); - - taskPrintHeap->attach(500); - taskCheckRelay->attach(50); - - MainAppKit.begin(); - - UNIOT_LOG_INFO("%s: %s", "CHIP_ID", String(ESP.getChipId(), HEX).c_str()); - UNIOT_LOG_INFO("%s: %s", "DEVICE_ID", MainAppKit.getCredentials().getDeviceId().c_str()); - UNIOT_LOG_INFO("%s: %s", "OWNER_ID", MainAppKit.getCredentials().getOwnerId().c_str()); -} diff --git a/examples/My9231Lamp/My9231Lamp.ino b/examples/My9231Lamp/My9231Lamp.ino deleted file mode 100644 index 36dc4a57..00000000 --- a/examples/My9231Lamp/My9231Lamp.ino +++ /dev/null @@ -1,95 +0,0 @@ -/* - * This is a part of the Uniot project. - * Copyright (C) 2016-2023 Uniot - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include -#include -#include -#include -#include - -#include "My9231Lamp.h" - -using namespace uniot; - -My9231Lamp Lamp; - -CoreCallbackEventListener NetworkLedListener([](int topic, int msg) { - if (topic == NetworkDevice::Topic::NETWORK_LED) { - Lamp.off(); - Lamp.setRed(msg ? 10 : 0); - Lamp.update(); - } -}); - -Object lamp_update(Root root, VarObject env, VarObject list) { - auto expeditor = PrimitiveExpeditor::describe(getPrimitiveName(), Lisp::Bool, 5, Lisp::Int, Lisp::Int, Lisp::Int, Lisp::BoolInt, Lisp::BoolInt) - .init(root, env, list); - expeditor.assertDescribedArgs(); - auto red = expeditor.getArgInt(0); - auto green = expeditor.getArgInt(1); - auto blue = expeditor.getArgInt(2); - auto warm = expeditor.getArgInt(3); - auto cool = expeditor.getArgInt(4); - - red = std::min(255, std::max(0, red)); - green = std::min(255, std::max(0, green)); - blue = std::min(255, std::max(0, blue)); - - warm = std::min(255, std::max(0, warm)); - cool = std::min(255, std::max(0, cool)); - // warm = warm > 0 ? 255 : 0; // Sonoff B1R2 - // cool = cool > 0 ? 255 : 0; // Sonoff B1R2 - - Lamp.off(); - Lamp.set(red, green, blue, warm, cool); - Lamp.update(); - - return expeditor.makeBool(false); -} - -auto taskPrintHeap = TaskScheduler::make([](short t) { - Serial.println(ESP.getFreeHeap()); -}); - -auto taskPrintTime = TaskScheduler::make([](short t) { - Serial.println(Date::getFormattedTime()); -}); - -void inject() { - Lamp.off(); - auto &MainAppKit = AppKit::getInstance(0, LOW, 2); - - MainAppKit.getLisp().pushPrimitive(lamp_update); - - MainEventBus.registerKit(MainAppKit); - MainEventBus.registerEntity(NetworkLedListener.listenToEvent(NetworkDevice::Topic::NETWORK_LED)); - - MainScheduler - .push(MainAppKit) - .push("print_time", taskPrintTime) - .push("print_heap", taskPrintHeap); - - taskPrintHeap->attach(500); - taskPrintTime->attach(500); - - MainAppKit.attach(); - - UNIOT_LOG_INFO("%s: %s", "CHIP_ID", String(ESP.getChipId(), HEX).c_str()); - UNIOT_LOG_INFO("%s: %s", "DEVICE_ID", MainAppKit.getCredentials().getDeviceId().c_str()); - UNIOT_LOG_INFO("%s: %s", "OWNER_ID", MainAppKit.getCredentials().getOwnerId().c_str()); -} diff --git a/examples/My9231Lamp/My9231Lamp.h b/examples/My9231Lamp/lib/My9231Lamp/My9231Lamp.h similarity index 98% rename from examples/My9231Lamp/My9231Lamp.h rename to examples/My9231Lamp/lib/My9231Lamp/My9231Lamp.h index 79525b29..1313ef57 100644 --- a/examples/My9231Lamp/My9231Lamp.h +++ b/examples/My9231Lamp/lib/My9231Lamp/My9231Lamp.h @@ -1,6 +1,6 @@ /* * This is a part of the Uniot project. - * Copyright (C) 2016-2023 Uniot + * Copyright (C) 2016-2025 Uniot * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/examples/My9231Lamp/platformio.ini b/examples/My9231Lamp/platformio.ini index 9b8ba1a2..88002097 100755 --- a/examples/My9231Lamp/platformio.ini +++ b/examples/My9231Lamp/platformio.ini @@ -9,19 +9,24 @@ ; https://docs.platformio.org/page/projectconf.html [env:esp12e] -platform = espressif8266@4.2.1 +platform = espressif8266 framework = arduino board = sonoff_basic board_build.filesystem = littlefs monitor_speed = 115200 monitor_filters = default, esp8266_exception_decoder -extra_scripts = ./scripts/download_fs.py + lib_deps = - ./../uniot-cbor - ./../uniot-lisp - ./../uniot-pubsubclient - ./../uniot-crypto + uniot-io/uniot-core@^0.8.1 + +build_unflags = + -std=gnu++11 + build_flags = + -std=gnu++17 -D UNIOT_CREATOR_ID=\"UNIOT\" -D UNIOT_LOG_ENABLED=1 -D UNIOT_USE_LITTLEFS=1 + -D UNIOT_LOG_LEVEL=UNIOT_LOG_LEVEL_DEBUG + -D UNIOT_LISP_HEAP=10000 + -D MQTT_MAX_PACKET_SIZE=2048 diff --git a/examples/My9231Lamp/src/main.cpp b/examples/My9231Lamp/src/main.cpp new file mode 100644 index 00000000..5634c5df --- /dev/null +++ b/examples/My9231Lamp/src/main.cpp @@ -0,0 +1,87 @@ +/* + * This is a part of the Uniot project. + * Copyright (C) 2016-2025 Uniot + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include + +using namespace uniot; + +My9231Lamp Lamp; + +// Custom Lisp primitive to control the lamp +Object lamp_update(Root root, VarObject env, VarObject list) { + auto expeditor = PrimitiveExpeditor::describe("lamp_update", Lisp::Bool, 5, Lisp::Int, Lisp::Int, Lisp::Int, Lisp::Int, Lisp::Int) + .init(root, env, list); + expeditor.assertDescribedArgs(); + + // Get RGB, warm white, and cool white values + auto red = expeditor.getArgInt(0); + auto green = expeditor.getArgInt(1); + auto blue = expeditor.getArgInt(2); + auto warm = expeditor.getArgInt(3); + auto cool = expeditor.getArgInt(4); + + // Clamp values to valid range + red = std::min(255, std::max(0, red)); + green = std::min(255, std::max(0, green)); + blue = std::min(255, std::max(0, blue)); + warm = std::min(255, std::max(0, warm)); + cool = std::min(255, std::max(0, cool)); + + // Note: For Sonoff B1R2, you may need to adjust: + // warm = warm > 0 ? 255 : 0; + // cool = cool > 0 ? 255 : 0; + + // Update the lamp + Lamp.off(); + Lamp.set(red, green, blue, warm, cool); + Lamp.update(); + + return expeditor.makeBool(true); +} + +void setup() { + // Initialize the lamp + Lamp.off(); + + // Custom WiFi status LED handler that uses the lamp + Uniot.addWifiStatusLedListener([](bool state) { + Lamp.off(); + Lamp.setRed(state ? 10 : 0); + Lamp.update(); + }); + + // Add custom Lisp primitive for lamp control + Uniot.addLispPrimitive(lamp_update); + + // Create periodic tasks for monitoring + Uniot.setInterval([]() { + UNIOT_LOG_DEBUG("Free heap: %u", ESP.getFreeHeap()); + }, 5000); + + Uniot.setInterval([]() { + UNIOT_LOG_DEBUG("Time: %s", Date::getFormattedTime().c_str()); + }, 5000); + + // Initialize and start Uniot + Uniot.begin(); +} + +void loop() { + Uniot.loop(); +} diff --git a/examples/S20Socket/S20Socket.ino b/examples/S20Socket/S20Socket.ino deleted file mode 100644 index 6c4d64b3..00000000 --- a/examples/S20Socket/S20Socket.ino +++ /dev/null @@ -1,41 +0,0 @@ -#include -#include -#include -#include -#include - -#define PIN_STATUS_LED 13 -#define PIN_RELAY 12 -#define PIN_BUTTON 0 -#define BTN_PIN_LEVEL LOW - -using namespace uniot; - -auto taskPrintHeap = TaskScheduler::make([](short t) { - Serial.println(ESP.getFreeHeap()); -}); - -auto taskPrintTime = TaskScheduler::make([](short t) { - Serial.println(Date::getFormattedTime()); -}); - -void inject() { - auto& MainAppKit = AppKit::getInstance(PIN_BUTTON, BTN_PIN_LEVEL, PIN_STATUS_LED); - UniotPinMap.setDigitalOutput(2, PIN_RELAY, PIN_STATUS_LED); - - MainEventBus.registerKit(MainAppKit); - - MainScheduler - .push(MainAppKit) - .push("print_time", taskPrintTime) - .push("print_heap", taskPrintHeap); - - taskPrintHeap->attach(500); - taskPrintTime->attach(500); - - MainAppKit.attach(); - - UNIOT_LOG_INFO("%s: %s", "CHIP_ID", String(ESP.getChipId(), HEX).c_str()); - UNIOT_LOG_INFO("%s: %s", "DEVICE_ID", MainAppKit.getCredentials().getDeviceId().c_str()); - UNIOT_LOG_INFO("%s: %s", "OWNER_ID", MainAppKit.getCredentials().getOwnerId().c_str()); -} diff --git a/examples/S20Socket/platformio.ini b/examples/S20Socket/platformio.ini index 9b8ba1a2..88002097 100755 --- a/examples/S20Socket/platformio.ini +++ b/examples/S20Socket/platformio.ini @@ -9,19 +9,24 @@ ; https://docs.platformio.org/page/projectconf.html [env:esp12e] -platform = espressif8266@4.2.1 +platform = espressif8266 framework = arduino board = sonoff_basic board_build.filesystem = littlefs monitor_speed = 115200 monitor_filters = default, esp8266_exception_decoder -extra_scripts = ./scripts/download_fs.py + lib_deps = - ./../uniot-cbor - ./../uniot-lisp - ./../uniot-pubsubclient - ./../uniot-crypto + uniot-io/uniot-core@^0.8.1 + +build_unflags = + -std=gnu++11 + build_flags = + -std=gnu++17 -D UNIOT_CREATOR_ID=\"UNIOT\" -D UNIOT_LOG_ENABLED=1 -D UNIOT_USE_LITTLEFS=1 + -D UNIOT_LOG_LEVEL=UNIOT_LOG_LEVEL_DEBUG + -D UNIOT_LISP_HEAP=10000 + -D MQTT_MAX_PACKET_SIZE=2048 diff --git a/examples/S20Socket/src/main.cpp b/examples/S20Socket/src/main.cpp new file mode 100644 index 00000000..0b9421b4 --- /dev/null +++ b/examples/S20Socket/src/main.cpp @@ -0,0 +1,52 @@ +/* + * This is a part of the Uniot project. + * Copyright (C) 2016-2025 Uniot + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include + +using namespace uniot; + +#define PIN_STATUS_LED 13 +#define PIN_RELAY 12 +#define PIN_BUTTON 0 +#define BTN_PIN_LEVEL LOW + +void setup() { + // Configure WiFi with status LED and reset button + Uniot.configWiFiStatusLed(PIN_STATUS_LED); + Uniot.configWiFiResetButton(PIN_BUTTON, BTN_PIN_LEVEL); + Uniot.configWiFiResetOnReboot(5, 10000); + + // Register GPIO pins for Lisp access + Uniot.registerLispDigitalOutput(PIN_RELAY, PIN_STATUS_LED); + + // Create periodic tasks for monitoring + Uniot.setInterval([]() { + UNIOT_LOG_DEBUG("Free heap: %u", ESP.getFreeHeap()); + }, 5000); + + Uniot.setInterval([]() { + UNIOT_LOG_DEBUG("Time: %s", Date::getFormattedTime().c_str()); + }, 5000); + + // Initialize and start Uniot + Uniot.begin(); +} + +void loop() { + Uniot.loop(); +} diff --git a/examples/WittyCloud/WittyCloud.ino b/examples/WittyCloud/WittyCloud.ino deleted file mode 100644 index 50237a9d..00000000 --- a/examples/WittyCloud/WittyCloud.ino +++ /dev/null @@ -1,57 +0,0 @@ -/* - * This is a part of the Uniot project. - * Copyright (C) 2016-2023 Uniot - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include -#include -#include -#include -#include -#include - -using namespace uniot; - -auto taskPrintHeap = TaskScheduler::make([](short t) { - Serial.println(ESP.getFreeHeap()); -}); - -auto taskPrintTime = TaskScheduler::make([](short t) { - Serial.println(Date::getFormattedTime()); -}); - -void inject() { - auto &MainAppKit = AppKit::getInstance(PIN_BUTTON, BTN_PIN_LEVEL, RED); - UniotPinMap.setDigitalOutput(3, RED, GREEN, BLUE); - UniotPinMap.setDigitalInput(3, RED, GREEN, BLUE); - UniotPinMap.setAnalogOutput(3, RED, GREEN, BLUE); - UniotPinMap.setAnalogInput(1, LDR); - - MainEventBus.registerKit(&MainAppKit); - - MainScheduler.push(&MainAppKit) - ->push(taskPrintTime) - ->push(taskPrintHeap); - - taskPrintHeap->attach(500); - taskPrintTime->attach(500); - - MainAppKit.begin(); - - UNIOT_LOG_INFO("%s: %s", "CHIP_ID", String(ESP.getChipId(), HEX).c_str()); - UNIOT_LOG_INFO("%s: %s", "DEVICE_ID", MainAppKit.getCredentials().getDeviceId().c_str()); - UNIOT_LOG_INFO("%s: %s", "OWNER_ID", MainAppKit.getCredentials().getOwnerId().c_str()); -} diff --git a/examples/Locker/platformio.ini b/examples/WittyCloud/platformio.ini old mode 100755 new mode 100644 similarity index 68% rename from examples/Locker/platformio.ini rename to examples/WittyCloud/platformio.ini index c9adb933..41065563 --- a/examples/Locker/platformio.ini +++ b/examples/WittyCloud/platformio.ini @@ -8,22 +8,26 @@ ; Please visit documentation for the other options and examples ; https://docs.platformio.org/page/projectconf.html -[env:d1] -platform = espressif8266@4.2.1 +[env:esp12e] +platform = espressif8266 framework = arduino -board = d1_mini +board = esp12e board_build.filesystem = littlefs monitor_speed = 115200 monitor_filters = default, esp8266_exception_decoder -extra_scripts = ./scripts/download_fs.py + lib_deps = - ./../uniot-cbor - ./../uniot-lisp - ./../uniot-pubsubclient - ./../uniot-crypto - adafruit/Adafruit GFX Library@^1.11.9 - https://github.com/stblassitude/Adafruit_SSD1306_Wemos_OLED + uniot-io/uniot-core@^0.8.1 + +build_unflags = + -std=gnu++11 + build_flags = + -std=gnu++17 -D UNIOT_CREATOR_ID=\"UNIOT\" -D UNIOT_LOG_ENABLED=1 -D UNIOT_USE_LITTLEFS=1 + -D UNIOT_LOG_LEVEL=UNIOT_LOG_LEVEL_DEBUG + -D UNIOT_LISP_HEAP=10000 + -D MQTT_MAX_PACKET_SIZE=2048 + diff --git a/examples/WittyCloud/src/main.cpp b/examples/WittyCloud/src/main.cpp new file mode 100644 index 00000000..c50a97ef --- /dev/null +++ b/examples/WittyCloud/src/main.cpp @@ -0,0 +1,63 @@ +/* + * This is a part of the Uniot project. + * Copyright (C) 2016-2025 Uniot + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include + +using namespace uniot; + +// WittyCloud board pin definitions +#define PIN_BUTTON 4 +#define PIN_RED 15 +#define PIN_GREEN 12 +#define PIN_BLUE 13 +#define PIN_LDR A0 + +#define BTN_PIN_LEVEL LOW +#define LED_PIN_LEVEL HIGH + +void setup() { + // Configure WiFi with status LED and reset button + Uniot.configWiFiStatusLed(PIN_RED, LED_PIN_LEVEL); + Uniot.configWiFiResetButton(PIN_BUTTON, BTN_PIN_LEVEL); + Uniot.configWiFiResetOnReboot(5, 10000); + + // Register GPIO pins for Lisp access + Uniot.registerLispDigitalOutput(PIN_RED, PIN_GREEN, PIN_BLUE); + Uniot.registerLispDigitalInput(PIN_BUTTON); + Uniot.registerLispAnalogOutput(PIN_RED, PIN_GREEN, PIN_BLUE); + Uniot.registerLispAnalogInput(PIN_LDR); + + // Create periodic tasks for monitoring + Uniot.setInterval([]() { + UNIOT_LOG_DEBUG("Free heap: %u", ESP.getFreeHeap()); + }, 5000); + + Uniot.setInterval([]() { + UNIOT_LOG_DEBUG("Time: %s", Date::getFormattedTime().c_str()); + }, 5000); + + // Log device information + UNIOT_LOG_INFO("CHIP_ID: %s", String(ESP.getChipId(), HEX).c_str()); + + // Initialize and start Uniot + Uniot.begin(); +} + +void loop() { + Uniot.loop(); +}