get OTA enabling working

This commit is contained in:
2018-08-22 11:09:42 +02:00
parent 77f1b278f4
commit 426d495fd9
10 changed files with 49 additions and 35 deletions

View File

@@ -18,29 +18,33 @@ class OtaTcpPlugin : public Plugin {
private:
OtaConfig config;
Task otaTask;
MeshNet* network;
MeshNet* net;
public:
OtaTcpPlugin(OtaConfig cfg){
config = cfg;
}
void connectUpdateNetwork(Network* network) {
// if(!network->isConnected()){
// static_cast<MeshNet*>(network)->config.stationMode = 1;
// }
network->connectStation();
void connectUpdateNetwork() {
Serial.println("OTA connect to update-network");
net->connectStation(1);
}
void enable() {
Serial.println("OTA enable");
ArduinoOTA.begin();
otaTask.enable();
}
void onMessage(MeshMessage msg) {
//enable();
Serial.println("OTA msg received");
if(msg.type == MeshMessage::OTA){
Serial.println("OTA msg received");
connectUpdateNetwork();
enable();
//net->mesh.sendBroadcast("my ip:" + WiFi.localIP().toString(), true);
}
}
void setup(Scheduler* userScheduler, Network* network){
// connect done in network class
// connect done in network class?
//connectUpdateNetwork(network);
net = static_cast<MeshNet*>(network);
// setup task
scheduler = userScheduler;
otaTask.set(TASK_MILLISECOND * 100, TASK_FOREVER, [](){
@@ -72,7 +76,6 @@ class OtaTcpPlugin : public Plugin {
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();