diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 00f20b5..9507d65 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -11,4 +11,5 @@ examples:
image: python:2.7-stretch
script:
- pio run -t clean
- - pio run -e basic
\ No newline at end of file
+ - pio run -e basic
+ - pio run -e ota
\ No newline at end of file
diff --git a/platformio.ini b/platformio.ini
index a4850bf..3d46ff5 100644
--- a/platformio.ini
+++ b/platformio.ini
@@ -12,7 +12,6 @@ lib_deps =
TaskScheduler
SPIFFS
ArduinoJson
- ArduinoOTA
ESP8266mDNS
https://gitlab.com/wirelos/sprocket-lib.git#feature/13-separation-of-concerns
@@ -23,4 +22,14 @@ board = ${common.board}
upload_speed = ${common.upload_speed}
monitor_baud = ${common.monitor_baud}
framework = ${common.framework}
-lib_deps = ${common.lib_deps}
\ No newline at end of file
+lib_deps = ${common.lib_deps}
+
+[env:ota]
+src_filter = +<*> - +
+platform = ${common.platform}
+board = ${common.board}
+upload_speed = ${common.upload_speed}
+monitor_baud = ${common.monitor_baud}
+framework = ${common.framework}
+lib_deps = ${common.lib_deps}
+ ArduinoOTA
\ No newline at end of file
diff --git a/src/OtaTcpPlugin.cpp b/src/OtaTcpPlugin.cpp
new file mode 100644
index 0000000..54daa9a
--- /dev/null
+++ b/src/OtaTcpPlugin.cpp
@@ -0,0 +1,71 @@
+#ifndef __OTA_CLASSIC_H__
+#define __OTA_CLASSIC_H__
+
+#include "TaskSchedulerDeclarations.h"
+#include "ArduinoOTA.h"
+#include "Plugin.h"
+
+using namespace std;
+using namespace std::placeholders;
+
+struct OtaConfig {
+ int port;
+ const char* password;
+};
+
+class OtaTcpPlugin : public Plugin {
+ private:
+ OtaConfig config;
+ Task otaTask;
+ public:
+ OtaTcpPlugin(OtaConfig cfg){
+ config = cfg;
+
+ }
+ void enable() {
+ Serial.println("OTA enable");
+ ArduinoOTA.begin();
+ otaTask.enable();
+ }
+ void activate(Scheduler* userScheduler){
+ // setup task
+ // TOOD check if we can increase the time OTA needs to be handled
+ // FIXME make this configurable
+ otaTask.set(TASK_MILLISECOND * 1000, TASK_FOREVER, [](){
+ ArduinoOTA.handle();
+ });
+ userScheduler->addTask(otaTask);
+
+ // configure OTA
+ ArduinoOTA.setPort(config.port);
+ //ArduinoOTA.setHostname(HOSTNAME);
+ if(strlen(config.password) > 0){
+ ArduinoOTA.setPassword(config.password);
+ }
+ // setup callbacks
+ ArduinoOTA.onStart([]() {
+ Serial.println("OTA: Start");
+ });
+ ArduinoOTA.onEnd([]() {
+ Serial.println("OTA: End");
+ });
+ ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
+ Serial.printf("OTA: Progress: %u%%\r", (progress / (total / 100)));
+ });
+ ArduinoOTA.onError([](ota_error_t error) {
+ Serial.printf("OTA: Error[%u]: ", error);
+ if (error == OTA_AUTH_ERROR) Serial.println("OTA: Auth Failed");
+ else if (error == OTA_BEGIN_ERROR) Serial.println("OTA: Begin Failed");
+ else if (error == OTA_CONNECT_ERROR) Serial.println("OTA: Connect Failed");
+ else if (error == OTA_RECEIVE_ERROR) Serial.println("OTA: Receive Failed");
+ else if (error == OTA_END_ERROR) Serial.println("OTA: End Failed");
+ });
+
+ enable();
+ }
+ void disable(){
+ otaTask.disable();
+ }
+};
+
+#endif
\ No newline at end of file
diff --git a/src/examples/basic/config.h b/src/examples/basic/config.h
index 1ce975a..051b345 100644
--- a/src/examples/basic/config.h
+++ b/src/examples/basic/config.h
@@ -23,10 +23,4 @@
#define OTA_PORT 8266
#define OTA_PASSWORD ""
-// WebServer
-#define WEB_CONTEXT_PATH "/"
-#define WEB_DOC_ROOT "/www"
-#define WEB_DEFAULT_FILE "index.html"
-#define WEB_SERVER_PORT 80
-
#endif
\ No newline at end of file
diff --git a/src/examples/ota/config.h b/src/examples/ota/config.h
new file mode 100644
index 0000000..051b345
--- /dev/null
+++ b/src/examples/ota/config.h
@@ -0,0 +1,26 @@
+#ifndef __STANDALONE_CONFIG__
+#define __STANDALONE_CONFIG__
+
+// Scheduler config
+#define _TASK_PRIORITY // Support for layered scheduling priority
+#define _TASK_SLEEP_ON_IDLE_RUN
+#define _TASK_STD_FUNCTION
+
+// Chip config
+#define SERIAL_BAUD_RATE 115200
+#define STARTUP_DELAY 3000
+
+// network config
+#define SPROCKET_MODE 0
+#define AP_SSID "MyAP"
+#define AP_PASSWORD "myApPwd"
+#define STATION_SSID "Th1ngs4p"
+#define STATION_PASSWORD "th3r31sn0sp00n"
+#define HOSTNAME "standalone-node"
+#define CONNECT_TIMEOUT 10000
+
+// OTA config
+#define OTA_PORT 8266
+#define OTA_PASSWORD ""
+
+#endif
\ No newline at end of file
diff --git a/src/examples/ota/main.cpp b/src/examples/ota/main.cpp
new file mode 100644
index 0000000..3410309
--- /dev/null
+++ b/src/examples/ota/main.cpp
@@ -0,0 +1,30 @@
+#include "config.h"
+#include "WiFiNet.h"
+#include "Sprocket.h"
+#include "OtaTcpPlugin.h"
+
+WiFiNet wifi(
+ SPROCKET_MODE,
+ STATION_SSID,
+ STATION_PASSWORD,
+ AP_SSID,
+ AP_PASSWORD,
+ HOSTNAME,
+ CONNECT_TIMEOUT);
+
+Sprocket sprocket(
+ {STARTUP_DELAY, SERIAL_BAUD_RATE});
+
+void setup()
+{
+ delay(3000);
+ wifi.connect();
+ sprocket.addPlugin(new OtaTcpPlugin({8266, ""}));
+ sprocket.activate();
+}
+
+void loop()
+{
+ sprocket.loop();
+ yield();
+}
\ No newline at end of file