mirror of
https://github.com/H3ALY/Wireless-PC-Switch.git
synced 2025-12-19 10:18:22 +00:00
Create main.ino
This commit is contained in:
committed by
GitHub
parent
55adf21ea7
commit
3aa4af853a
39
main.ino
Normal file
39
main.ino
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
#include <SimpleTimer.h>
|
||||||
|
#include "wifi_setup.h"
|
||||||
|
#include "mqtt_handler.h"
|
||||||
|
#include "power_control.h"
|
||||||
|
#include "ota_setup.h"
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
WiFiClient espClient;
|
||||||
|
MqttClient mqttClient(espClient);
|
||||||
|
PowerController powerController(14, 16, mqttClient.client);
|
||||||
|
OtaManager otaManager;
|
||||||
|
SimpleTimer timer;
|
||||||
|
|
||||||
|
void mqttCallback(char* topic, byte* payload, unsigned int length) {
|
||||||
|
payload[length] = '\0';
|
||||||
|
String command = String((char*)payload);
|
||||||
|
powerController.handleCommand(command);
|
||||||
|
}
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
Serial.begin(115200);
|
||||||
|
WiFiManager wifiManager;
|
||||||
|
wifiManager.setup_wifi();
|
||||||
|
|
||||||
|
mqttClient.setCallback(mqttCallback);
|
||||||
|
mqttClient.setupMqtt();
|
||||||
|
|
||||||
|
powerController.setup();
|
||||||
|
otaManager.setupOTA();
|
||||||
|
|
||||||
|
timer.setInterval(3000, []() { powerController.sensePower(); });
|
||||||
|
timer.setInterval(120000, []() { mqttClient.publish(check_in_topic, "OK"); });
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
mqttClient.loop();
|
||||||
|
otaManager.handleOTA();
|
||||||
|
timer.run();
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user