mirror of
https://gitlab.com/wirelos/sprocket-network-wifi.git
synced 2025-12-15 13:08:22 +01:00
Read wifi config from config folder, remove old OTA plugin
This commit is contained in:
@@ -1,6 +1,3 @@
|
|||||||
[platformio]
|
|
||||||
env_default = basic_esp01
|
|
||||||
|
|
||||||
[common]
|
[common]
|
||||||
framework = arduino
|
framework = arduino
|
||||||
platform = espressif8266
|
platform = espressif8266
|
||||||
@@ -43,14 +40,3 @@ monitor_baud = ${common.monitor_baud}
|
|||||||
framework = ${common.framework}
|
framework = ${common.framework}
|
||||||
lib_deps = ${common.lib_deps}
|
lib_deps = ${common.lib_deps}
|
||||||
ESPmDNS
|
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
|
|
||||||
@@ -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
|
|
||||||
@@ -18,7 +18,7 @@ WiFiNet::WiFiNet(
|
|||||||
}
|
}
|
||||||
|
|
||||||
int WiFiNet::connect(){
|
int WiFiNet::connect(){
|
||||||
config.fromFile("/config.json");
|
config.fromFile("/config/wifi.json");
|
||||||
#ifdef ESP32
|
#ifdef ESP32
|
||||||
WiFi.setHostname(config.hostname.c_str());
|
WiFi.setHostname(config.hostname.c_str());
|
||||||
#elif defined(ESP8266)
|
#elif defined(ESP8266)
|
||||||
|
|||||||
@@ -19,8 +19,4 @@
|
|||||||
#define HOSTNAME "standalone-node"
|
#define HOSTNAME "standalone-node"
|
||||||
#define CONNECT_TIMEOUT 10000
|
#define CONNECT_TIMEOUT 10000
|
||||||
|
|
||||||
// OTA config
|
|
||||||
#define OTA_PORT 8266
|
|
||||||
#define OTA_PASSWORD ""
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -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
|
|
||||||
@@ -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();
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user