update my libraries and switch to using wifi lib
This commit is contained in:
parent
004bba0175
commit
9141c8d54e
@ -37,8 +37,16 @@ namespace Board {
|
||||
[] {turnLed(BLUE_LED, false);},
|
||||
[] {turnLed(BLUE_LED);}
|
||||
);
|
||||
Wifi::setup();
|
||||
Ota::setup();
|
||||
Wifi::setup(ts, []{
|
||||
Ota::tLoop.enable();
|
||||
Mqtt::tReConnect.enable();
|
||||
});
|
||||
Ota::setup(
|
||||
[] {
|
||||
Mqtt::publishCleanupConfig();
|
||||
delay(2000);
|
||||
Mqtt::disconnect();
|
||||
});
|
||||
|
||||
tReadCommand.enable();
|
||||
}
|
||||
|
||||
@ -1,34 +0,0 @@
|
||||
#include <ArduinoOTA.h>
|
||||
|
||||
namespace Ota {
|
||||
|
||||
void loop() {
|
||||
ArduinoOTA.handle();
|
||||
}
|
||||
|
||||
Task tLoop(TASK_IMMEDIATE, TASK_FOREVER, loop, &ts, true);
|
||||
|
||||
void setup() {
|
||||
ArduinoOTA.onStart([]() {
|
||||
Serial.println("Starting OTA");
|
||||
Mqtt::publishCleanupConfig();
|
||||
delay(2000);
|
||||
Mqtt::disconnect();
|
||||
});
|
||||
ArduinoOTA.onEnd([]() {
|
||||
Serial.println("\nOTA Finished");
|
||||
});
|
||||
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
|
||||
Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
|
||||
});
|
||||
ArduinoOTA.onError([](ota_error_t error) {
|
||||
Serial.printf("Error[%u]: ", error);
|
||||
if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed");
|
||||
else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed");
|
||||
else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
|
||||
else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
|
||||
else if (error == OTA_END_ERROR) Serial.println("End Failed");
|
||||
});
|
||||
ArduinoOTA.begin();
|
||||
}
|
||||
}
|
||||
@ -1,68 +0,0 @@
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <ESP8266WiFiMulti.h>
|
||||
#include <ESP8266mDNS.h>
|
||||
#include "credentials.h"
|
||||
|
||||
namespace Wifi {
|
||||
|
||||
WiFiEventHandler stationConnectedHandler;
|
||||
WiFiEventHandler stationDisconnectedHandler;
|
||||
ESP8266WiFiMulti wifiMulti;
|
||||
|
||||
String currentSSID;
|
||||
String currentPsk;
|
||||
|
||||
void printStatus();
|
||||
|
||||
Task tReconnect(1 * TASK_MINUTE, TASK_FOREVER, [](){
|
||||
if (WiFi.status() != WL_CONNECTED) {
|
||||
WiFi.forceSleepWake();
|
||||
WiFi.begin(currentSSID.c_str(), currentPsk.c_str());
|
||||
Serial.println("Reconnecting to WiFi netowrk...");
|
||||
}
|
||||
}, &ts);
|
||||
|
||||
void setup() {
|
||||
stationConnectedHandler = WiFi.onStationModeGotIP([](const WiFiEventStationModeGotIP& e) {
|
||||
Serial.println("Connected to network.");
|
||||
printStatus();
|
||||
tReconnect.cancel();
|
||||
Ota::tLoop.enable();
|
||||
Mqtt::tReConnect.enable();
|
||||
});
|
||||
|
||||
stationDisconnectedHandler = WiFi.onStationModeDisconnected([](const WiFiEventStationModeDisconnected& e) {
|
||||
Serial.println("Disconnected from network.");
|
||||
});
|
||||
|
||||
|
||||
for (uint32_t i = 0; i < sizeof(credentials) / sizeof(WifiCredentials); i++) {
|
||||
wifiMulti.addAP(credentials[i].ssid, credentials[i].password);
|
||||
}
|
||||
|
||||
WiFi.setHostname("rc-gateway");
|
||||
Serial.println("Connecting to WiFi netowrk.");
|
||||
while (wifiMulti.run() != WL_CONNECTED) {
|
||||
delay(500);
|
||||
}
|
||||
currentSSID = WiFi.SSID();
|
||||
currentPsk = WiFi.psk();
|
||||
}
|
||||
|
||||
void printStatus() {
|
||||
// print the SSID of the network you're attached to:
|
||||
Serial.print("SSID: ");
|
||||
Serial.println(WiFi.SSID());
|
||||
|
||||
// print your WiFi shield's IP address:
|
||||
IPAddress ip = WiFi.localIP();
|
||||
Serial.print("IP Address: ");
|
||||
Serial.println(ip);
|
||||
|
||||
// print the received signal strength:
|
||||
long rssi = WiFi.RSSI();
|
||||
Serial.print("signal strength (RSSI):");
|
||||
Serial.print(rssi);
|
||||
Serial.println(" dBm");
|
||||
}
|
||||
}
|
||||
@ -19,7 +19,7 @@ lib_deps =
|
||||
bblanchon/ArduinoJson@6.21.5
|
||||
adafruit/Adafruit Unified Sensor@^1.1.4
|
||||
adafruit/DHT sensor library@1.3.2
|
||||
https://git.hodos.ro/arduino/lib_serial-reader.git@^1.0.0
|
||||
https://git.hodos.ro/libraries/serial-reader.git@^1.0.0
|
||||
build_flags = -D DHT_SENSOR=0 -D DEBUG_RAW=0
|
||||
check_tool = cppcheck
|
||||
check_flags = --enable=all
|
||||
@ -32,7 +32,8 @@ board = huzzah
|
||||
framework = arduino
|
||||
lib_deps =
|
||||
${env.lib_deps}
|
||||
https://git.hodos.ro/arduino/ha-mqtt.git@^1.0.0
|
||||
https://git.hodos.ro/libraries/ha-mqtt.git@^1.0.0
|
||||
https://git.hodos.ro/libraries/wifi.git@^1.0.1
|
||||
upload_port = 192.168.6.161
|
||||
upload_protocol = espota
|
||||
upload_flags =
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user