Use a robust asynchronous MQTT client
This commit is contained in:
@@ -1,27 +1,24 @@
|
||||
#ifndef CONFIG_H_
|
||||
#define CONFIG_H_
|
||||
|
||||
#include "FS.h"
|
||||
#include "LittleFS.h"
|
||||
#include <ArduinoJson.h>
|
||||
|
||||
typedef struct {
|
||||
const char *ssid;
|
||||
const char *psk;
|
||||
const char *mqtt_host;
|
||||
const char *mqtt_user;
|
||||
const char *mqtt_password;
|
||||
const char *topic;
|
||||
const char *device_id;
|
||||
int mqtt_port;
|
||||
long sleep_time;
|
||||
int connection_attempts;
|
||||
const char *ssid;
|
||||
const char *psk;
|
||||
const char *mqtt_host;
|
||||
const char *mqtt_user;
|
||||
const char *mqtt_password;
|
||||
const char *topic;
|
||||
const char *device_id;
|
||||
int mqtt_port;
|
||||
unsigned long sleep_time;
|
||||
} Config;
|
||||
|
||||
void initialize_config(Config *config, StaticJsonDocument<512> json);
|
||||
void initialize_config(Config *config, JsonDocument json);
|
||||
|
||||
bool load_config_file(const char *file_path, Config *config);
|
||||
|
||||
long minutes_to_microseconds(int minutes);
|
||||
long minutes_to_milliseconds(int minutes);
|
||||
|
||||
#endif // CONFIG_H_
|
||||
|
||||
10
include/sensor.h
Normal file
10
include/sensor.h
Normal file
@@ -0,0 +1,10 @@
|
||||
#ifndef SENSOR_H_
|
||||
#define SENSOR_H_
|
||||
|
||||
#include <DHT.h>
|
||||
|
||||
void initialize_sensor(DHT &sensor);
|
||||
|
||||
void read_values(DHT &sensor, float *data);
|
||||
|
||||
#endif // SENSOR_H_
|
||||
@@ -2,15 +2,28 @@
|
||||
#define WLAN_H
|
||||
|
||||
#include "config.h"
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <PubSubClient.h>
|
||||
#include <AsyncMqttClient.h>
|
||||
#include <Ticker.h>
|
||||
#include <WiFi.h>
|
||||
|
||||
static AsyncMqttClient mqtt_client;
|
||||
static Ticker mqtt_connection_timer, wlan_connection_timer;
|
||||
extern Config *config;
|
||||
|
||||
void initialize_wlan();
|
||||
|
||||
void initialize_mqtt();
|
||||
|
||||
void connect_wlan();
|
||||
|
||||
void connect_mqtt();
|
||||
|
||||
void wlan_connection_handler(WiFiEvent_t event);
|
||||
|
||||
void on_mqtt_disconnection(AsyncMqttClientDisconnectReason reason);
|
||||
|
||||
void initial_connection(const char *ssid, const char *psk);
|
||||
void connect_wlan(Config *config);
|
||||
void connect_mqtt(PubSubClient &client, Config *config);
|
||||
void disconnect_mqtt(PubSubClient &client, const char *topic);
|
||||
size_t construct_json(float *data, char *buffer, int buffer_size);
|
||||
void mqtt_transfer(PubSubClient &client, Config *config, float *data);
|
||||
void enter_deep_sleep(bool wifi_timeout, int sleep_time);
|
||||
|
||||
void mqtt_transfer(float *data);
|
||||
|
||||
#endif /* WLAN_H */
|
||||
|
||||
Reference in New Issue
Block a user