mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-27 06:32:19 +03:00
добавил MQTT, не рабочая версия
This commit is contained in:
@@ -14,6 +14,9 @@
|
||||
|
||||
//#define REST_FILE_OPERATIONS
|
||||
|
||||
#define MQTT_RECONNECT_INTERVAL 20000
|
||||
#define CHANGE_BROKER_AFTER 5
|
||||
|
||||
#ifdef esp8266_4mb
|
||||
#define USE_LITTLEFS true
|
||||
#endif
|
||||
@@ -30,4 +33,11 @@ enum TimerTask_t { WIFI_SCAN,
|
||||
UPTIME,
|
||||
SYGNAL,
|
||||
TIMES,
|
||||
MYTEST };
|
||||
MYTEST };
|
||||
|
||||
//задачи которые надо протащить через loop
|
||||
enum NotAsyncActions {
|
||||
do_ZERO,
|
||||
do_MQTTPARAMSCHANGED,
|
||||
do_LAST,
|
||||
};
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <Arduino.h>
|
||||
#include <ArduinoJson.h>
|
||||
#include <TickerScheduler.h>
|
||||
#include <PubSubClient.h>
|
||||
|
||||
#ifdef ESP32
|
||||
#include "WiFi.h"
|
||||
@@ -52,6 +53,7 @@
|
||||
|
||||
extern TickerScheduler ts;
|
||||
extern WiFiClient espClient;
|
||||
extern PubSubClient mqtt;
|
||||
#ifdef ASYNC_WEB_SERVER
|
||||
extern AsyncWebServer server;
|
||||
#endif
|
||||
@@ -77,6 +79,23 @@ extern String settingsFlashJson;
|
||||
extern String paramsFlashJson;
|
||||
extern String paramsHeapJson;
|
||||
|
||||
// Mqtt
|
||||
extern String mqttServer;
|
||||
extern int mqttPort;
|
||||
extern String mqttPrefix;
|
||||
extern String mqttUser;
|
||||
extern String mqttPass;
|
||||
|
||||
extern String mqttRootDevice;
|
||||
extern String chipId;
|
||||
extern String prex;
|
||||
extern String all_widgets;
|
||||
extern String scenario;
|
||||
|
||||
extern int mqttConnectAttempts;
|
||||
extern bool changeBroker;
|
||||
extern int currentBroker;
|
||||
|
||||
// extern DynamicJsonDocument settingsFlashJsonDoc;
|
||||
// extern DynamicJsonDocument paramsFlashJsonDoc;
|
||||
// extern DynamicJsonDocument paramsHeapJsonDoc;
|
||||
31
include/MqttClient.h
Normal file
31
include/MqttClient.h
Normal file
@@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
#include "Const.h"
|
||||
#include "classes/NotAsync.h"
|
||||
#include "Global.h"
|
||||
#include "Utils/WiFiUtils.h"
|
||||
|
||||
void mqttInit();
|
||||
void selectBroker();
|
||||
void getMqttData1();
|
||||
void getMqttData2();
|
||||
bool isSecondBrokerSet();
|
||||
boolean mqttConnect();
|
||||
void mqttReconnect();
|
||||
void mqttLoop();
|
||||
void mqttSubscribe();
|
||||
|
||||
boolean publish(const String& topic, const String& data);
|
||||
boolean publishData(const String& topic, const String& data);
|
||||
boolean publishChart(const String& topic, const String& data);
|
||||
boolean publishControl(String id, String topic, String state);
|
||||
boolean publishChart_test(const String& topic, const String& data);
|
||||
boolean publishStatus(const String& topic, const String& data);
|
||||
boolean publishEvent(const String& topic, const String& data);
|
||||
boolean publishInfo(const String& topic, const String& data);
|
||||
boolean publishAnyJsonKey(const String& topic, const String& key, const String& data);
|
||||
|
||||
void publishWidgets();
|
||||
void publishState();
|
||||
|
||||
void mqttCallback(char* topic, uint8_t* payload, size_t length);
|
||||
const String getStateStr();
|
||||
32
include/classes/NotAsync.h
Normal file
32
include/classes/NotAsync.h
Normal file
@@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
#include <Arduino.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <functional>
|
||||
|
||||
typedef std::function<void(void*)> NotAsyncCb;
|
||||
|
||||
struct NotAsyncItem {
|
||||
bool test;
|
||||
NotAsyncCb cb;
|
||||
void* cb_arg;
|
||||
volatile bool is_used = false;
|
||||
};
|
||||
|
||||
class NotAsync {
|
||||
private:
|
||||
uint8_t size;
|
||||
uint8_t task = 0;
|
||||
NotAsyncItem* items = NULL;
|
||||
void handle(NotAsyncCb f, void* arg);
|
||||
|
||||
public:
|
||||
NotAsync(uint8_t size);
|
||||
~NotAsync();
|
||||
|
||||
void add(uint8_t i, NotAsyncCb, void* arg);
|
||||
void make(uint8_t task);
|
||||
void loop();
|
||||
};
|
||||
|
||||
extern NotAsync* myNotAsyncActions;
|
||||
@@ -6,3 +6,4 @@
|
||||
#include "AsyncWebServer.h"
|
||||
#include "StandWebServer.h"
|
||||
#include "classes/sendJson.h"
|
||||
#include "classes/NotAsync.h"
|
||||
|
||||
Reference in New Issue
Block a user