-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxnsclient.h
97 lines (76 loc) · 3.26 KB
/
xnsclient.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
// xinit.h
#ifndef _xnsClientCLASS_h
#define _xnsClientCLASS_h
#ifndef WIFI_CONNECTION_TIMEOUT
#define WIFI_CONNECTION_TIMEOUT 30000
#endif // !WIFI_CONNECTION_TIMEOUT
#include <arduino.h>
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <ESP8266httpUpdate.h>
#include <ArduinoJson.h>
#include <PubSubClient.h>
#include "xnsclientwebserver.h"
class xnsClientClass
{
private:
bool secure = false;
Stream* debugger = NULL;
//Name of Hardware Eq. xns.rfid
const char* hwName;
//Revision number Eq. A
const char* hwRevision;
//Revision number Eq. 1.0.0.0
const int* fwRevision;
const char* ssid;
const char* ssidPassword;
const char* mqttName;
int mqttPort;
const char* mqttUser = 0;
const char* mqttPass = 0;
const char* mqttClientName = 0;
const char* mqttClientID = 0;
const char* mqttPublishTopic = 0;
const char* mqttSubscribeTopic = 0;
unsigned long aliveMessageInterval = 0;
unsigned long lastAliveMessage = 0;
int accessPointButtonPin = -1;
WiFiClient *client;
byte mac[6]; // the MAC address of your Wifi shield
PubSubClient mqtt;
void MQTT_connect();
void UpgradeFirmware(String pUrl);
void(*mqttMessageCallback)(JsonObject& json) = NULL;
xnsClientWebServerClass *webConfig = 0;
bool isAPButtonPressed();
protected:
public:
xnsClientClass();
void begin(const char* hwName,const char* hwRevision, const int fwRevision[], int accessPointButtonPin, Stream& debugger);
void begin(const char* hwName,const char* hwRevision, const int fwRevision[], const char* ssid, const char* ssidPassword, const char* mqtt, int mqttPort);
void begin(const char* hwName,const char* hwRevision, const int fwRevision[], const char* ssid, const char* ssidPassword, const char* mqtt, int mqttPort, Stream& debugger);
void begin(const char* hwName,const char* hwRevision, const int fwRevision[], const char* ssid, const char* ssidPassword, const char* mqtt, int mqttPort, const char* mqttUser, const char* mqttPass);
void begin(const char* hwName,const char* hwRevision, const int fwRevision[], const char* ssid, const char* ssidPassword, const char* mqtt, int mqttPort, const char* mqttUser, const char* mqttPass, Stream& debugger);
void beginSecure(const char* hwName,const char* hwRevision, const int fwRevision[], const char* ssid, const char* ssidPassword, const char* mqtt, int mqttPort, const char* mqttClientID, const char* mqttUser, const char* mqttPass, const char* mqttPublishTopic, const char* mqttSubscribeTopic, Stream& debugger);
void loop();
bool connected();
void printFlashInfo();
void printDeviceInfo();
String GetVersionString();
void sendMqttConnectMessage();
void sendMqttMessage(String message);
void sendMqttMessage(JsonObject& message);
void sendMqttData(String message);
void sendMqttData(JsonObject& message);
void setMqttMessageCallback(void(*mqttMessageCallback)(JsonObject& json));
void sendConfigMessage();
void sendConfigMessage(xnsClientConfig& config);
void setConfig(JsonObject& json);
bool hasValue(JsonObject& json, String key);
String getJsonValue(JsonObject& json, String key);
JsonVariant getJsonObject(JsonObject& json, String key);
void mqttMessageReceived(char* topic, unsigned char* payload, unsigned int length);
void setAliveMessageInterval(int interval);
};
extern xnsClientClass xnsClient;
#endif