mirror of
https://gitlab.com/wirelos/sprocket-network-wifi.git
synced 2025-12-14 12:46:51 +01:00
ota
This commit is contained in:
@@ -11,4 +11,5 @@ examples:
|
|||||||
image: python:2.7-stretch
|
image: python:2.7-stretch
|
||||||
script:
|
script:
|
||||||
- pio run -t clean
|
- pio run -t clean
|
||||||
- pio run -e basic
|
- pio run -e basic
|
||||||
|
- pio run -e ota
|
||||||
@@ -12,7 +12,6 @@ lib_deps =
|
|||||||
TaskScheduler
|
TaskScheduler
|
||||||
SPIFFS
|
SPIFFS
|
||||||
ArduinoJson
|
ArduinoJson
|
||||||
ArduinoOTA
|
|
||||||
ESP8266mDNS
|
ESP8266mDNS
|
||||||
https://gitlab.com/wirelos/sprocket-lib.git#feature/13-separation-of-concerns
|
https://gitlab.com/wirelos/sprocket-lib.git#feature/13-separation-of-concerns
|
||||||
|
|
||||||
@@ -23,4 +22,14 @@ board = ${common.board}
|
|||||||
upload_speed = ${common.upload_speed}
|
upload_speed = ${common.upload_speed}
|
||||||
monitor_baud = ${common.monitor_baud}
|
monitor_baud = ${common.monitor_baud}
|
||||||
framework = ${common.framework}
|
framework = ${common.framework}
|
||||||
lib_deps = ${common.lib_deps}
|
lib_deps = ${common.lib_deps}
|
||||||
|
|
||||||
|
[env:ota]
|
||||||
|
src_filter = +<*> -<examples/> +<examples/basic/>
|
||||||
|
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
|
||||||
71
src/OtaTcpPlugin.cpp
Normal file
71
src/OtaTcpPlugin.cpp
Normal file
@@ -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
|
||||||
@@ -23,10 +23,4 @@
|
|||||||
#define OTA_PORT 8266
|
#define OTA_PORT 8266
|
||||||
#define OTA_PASSWORD ""
|
#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
|
#endif
|
||||||
26
src/examples/ota/config.h
Normal file
26
src/examples/ota/config.h
Normal file
@@ -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
|
||||||
30
src/examples/ota/main.cpp
Normal file
30
src/examples/ota/main.cpp
Normal file
@@ -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();
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user