Initialisation depot
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
#include <functional>
|
||||
#include <PubSubClient.h>
|
||||
#include <WiFiClient.h>
|
||||
|
||||
class MqttManager {
|
||||
public:
|
||||
using MessageCallback = std::function<void(char*, uint8_t*, unsigned int)>;
|
||||
MqttManager();
|
||||
void begin(const char* server, uint16_t port, MessageCallback cb);
|
||||
void loop();
|
||||
bool publish(const char* topic, const char* payload);
|
||||
bool subscribe(const char* topic);
|
||||
bool connected();
|
||||
private:
|
||||
WiFiClient espClient;
|
||||
PubSubClient client{espClient};
|
||||
MessageCallback messageCb;
|
||||
const char* serverAddr = nullptr;
|
||||
uint16_t serverPort = 0;
|
||||
static MqttManager* instance;
|
||||
static void staticCallback(char* topic, byte* payload, unsigned int length);
|
||||
void connect();
|
||||
};
|
||||
@@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
#include <Arduino.h>
|
||||
#include <WiFi.h>
|
||||
#include <WebServer.h>
|
||||
|
||||
class WifiManager {
|
||||
public:
|
||||
WifiManager();
|
||||
void begin();
|
||||
bool isConnected();
|
||||
void loop();
|
||||
String getSSID();
|
||||
String getPassword();
|
||||
private:
|
||||
WebServer server{80};
|
||||
String ssid;
|
||||
String pass;
|
||||
bool apMode;
|
||||
void startAP();
|
||||
void handleRoot();
|
||||
void handleSave();
|
||||
void loadCredentials();
|
||||
void saveCredentials(const String &s, const String &p);
|
||||
};
|
||||
@@ -0,0 +1,17 @@
|
||||
#ifndef CONFIG_H
|
||||
#define CONFIG_H
|
||||
|
||||
// MQTT broker settings (leave MQTT server values as needed)
|
||||
#define MQTT_SERVER "192.168.1.10"
|
||||
#define MQTT_PORT 1883
|
||||
#define MQTT_TOPIC_CMD "dcc/command"
|
||||
#define MQTT_TOPIC_STATUS "dcc/status"
|
||||
#define MQTT_TOPIC_RESPONSE "dcc/response"
|
||||
|
||||
// Pin used for simulated DCC output (adjust as needed)
|
||||
#define DCC_OUTPUT_PIN 27
|
||||
|
||||
// Access point SSID shown when no WiFi credentials are configured
|
||||
#define DEFAULT_AP_SSID "DCC_Config"
|
||||
|
||||
#endif // CONFIG_H
|
||||
Reference in New Issue
Block a user