Read wifi config from config folder, remove old OTA plugin

This commit is contained in:
Patrick Balsiger
2019-05-20 19:10:16 +02:00
parent 2bf40bcb6e
commit 28d885b087
6 changed files with 2 additions and 147 deletions

View File

@@ -1,6 +1,3 @@
[platformio]
env_default = basic_esp01
[common]
framework = arduino
platform = espressif8266
@@ -42,15 +39,4 @@ upload_speed = ${common.upload_speed}
monitor_baud = ${common.monitor_baud}
framework = ${common.framework}
lib_deps = ${common.lib_deps}
ESPmDNS
[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}
ESP8266mDNS
ArduinoOTA
ESPmDNS

View File

@@ -1,71 +0,0 @@
#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

View File

@@ -18,7 +18,7 @@ WiFiNet::WiFiNet(
}
int WiFiNet::connect(){
config.fromFile("/config.json");
config.fromFile("/config/wifi.json");
#ifdef ESP32
WiFi.setHostname(config.hostname.c_str());
#elif defined(ESP8266)

View File

@@ -19,8 +19,4 @@
#define HOSTNAME "standalone-node"
#define CONNECT_TIMEOUT 10000
// OTA config
#define OTA_PORT 8266
#define OTA_PASSWORD ""
#endif

View File

@@ -1,26 +0,0 @@
#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

View File

@@ -1,30 +0,0 @@
#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();
}