-
Notifications
You must be signed in to change notification settings - Fork 25
/
JeeUI2.h
198 lines (156 loc) · 5.56 KB
/
JeeUI2.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#ifndef JeeUI2_h
#define JeeUI2_h
#include "Arduino.h"
#ifdef ESP8266
#include <ESPAsyncTCP.h>
#include <FS.h>
#else
#include <AsyncTCP.h>
#include "SPIFFS.h"
#endif
#include <ESPAsyncWebServer.h>
#include "ArduinoJson.h"
#ifdef ESP8266
#include <ESP8266WiFi.h>
#else
#include <WiFi.h>
#endif
#include <AsyncMqttClient.h>
#define BUTTON 0
class jeeui2
{
StaticJsonDocument<8192> cfg;
StaticJsonDocument<128> pub_transport;
StaticJsonDocument<128> btn_transport;
AsyncMqttClient mqttClient;
typedef void (*buttonCallback) ();
typedef void (*uiCallback) ();
typedef void (*updateCallback) ();
typedef void (*mqttCallback) ();
public:
void var(String key, String value);
String param(String key);
void led(uint8_t pin, bool invert);
String deb();
void ap(unsigned long interval);
void begin();
void begin(bool debug);
void handle();
void btnCallback(String name ,buttonCallback response);
void app(String name);
void menu(String name);
void page();
void text(String id, String label);
void password(String id, String label);
void number(String id, String label);
void time(String id, String label);
void date(String id, String label);
void datetime(String id, String label);
void email(String id, String label);
void range(String id, int min, int max, float step, String label);
void select(String id, String label);
void option(String value, String label);
void checkbox(String id, String label);
void color(String id, String label);
void button(String id, String color, String label);
void button(String id, String color, String label, int column);
void textarea(String id, String label);
void save();
void udp(String message);
void udp();
void pub(String id, String label);
void pub(String id, String label, String unit);
void pub(String id, String label, String unit, String bg_color);
void pub(String id, String label, String unit, String bg_color, String text_color);
void formWifi();
void formMqtt();
uiCallback foo;
void ui(void (*uiFunction) ());
void mqtt(String pref, String host, int port, String user, String pass, void (*mqttFunction) (String topic, String payload), bool remotecontrol);
void mqtt(String pref, String host, int port, String user, String pass, void (*mqttFunction) (String topic, String payload));
void mqtt(String host, int port, String user, String pass, void (*mqttFunction) (String topic, String payload));
void mqtt(String host, int port, String user, String pass, void (*mqttFunction) (String topic, String payload), bool remotecontrol);
void mqtt(String host, int port, String user, String pass, bool remotecontrol);
void mqtt(String pref, String host, int port, String user, String pass, bool remotecontrol);
mqttCallback onConnect;
void mqtt(String pref, String host, int port, String user, String pass, void (*mqttFunction) (String topic, String payload), void (*mqttConnect) (), bool remotecontrol);
void mqtt(String pref, String host, int port, String user, String pass, void (*mqttFunction) (String topic, String payload), void (*mqttConnect) ());
void mqtt(String host, int port, String user, String pass, void (*mqttFunction) (String topic, String payload), void (*mqttConnect) ());
void mqtt(String host, int port, String user, String pass, void (*mqttFunction) (String topic, String payload), void (*mqttConnect) (), bool remotecontrol);
void subscribe(String topic);
void publish(String topic, String payload);
void publish(String topic, String payload, bool retained);
void remControl();
updateCallback upd;
void update(void (*updateFunction) ());
String ip;
String buf;
String mc;
String mac;
bool connected = false;
String id(String tpoic);
String m_pref;
private:
void arr(String key, String value);
void wifi_connect();
void button_handle();
void led_handle();
void nonWifiVar();
void led_on();
void led_off();
void led_inv();
void load();
void autosave();
void as();
void prntmac();
void udpBegin();
void udpLoop();
void btn();
void getAPmac();
void pub_mqtt(String key, String value);
void mqtt_update();
void mqtt_handle();
void mqtt_send();
void mqtt_reconnect();
bool mqtt_ok = false;
bool mqtt_enable = false;
void _connected();
void subscribeAll();
String m_host;
int m_port;
String m_user;
String m_pass;
bool m_params;
int sendConfig = 0;
bool pub_enable;
int btn_num = 0;
String btn_id[32];
String udpRemoteIP;
unsigned int localUdpPort = 4243;
char incomingPacket[64];
unsigned int asave = 1000;
bool sv = false;
unsigned long astimer;
String op = "";
uint8_t wifi_mode;
int LED_PIN = -1;
bool LED_INVERT = false;
uint8_t mn = 0;
unsigned long a_ap = 0;
bool wf = false;
uint8_t pg = 0;
String btnui = "";
String udpMessage;
bool dbg = false;
bool rc;
void connectToMqtt();
void onMqttConnect();
static void onMqttDisconnect(AsyncMqttClientDisconnectReason reason);
static void onMqttSubscribe(uint16_t packetId, uint8_t qos);
static void onMqttUnsubscribe(uint16_t packetId);
static void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties properties, size_t len, size_t index, size_t total);
static void onMqttPublish(uint16_t packetId);
static void _onMqttConnect(bool sessionPresent);
void check_wifi_state();
};
#endif