2016-09-18 08:30:34 +00:00
|
|
|
#ifndef SPEJSNODE_H
|
|
|
|
#define SPEJSNODE_H
|
|
|
|
|
2016-06-29 15:00:22 +00:00
|
|
|
#include <user_config.h>
|
|
|
|
#include <common_config.h>
|
2020-10-05 19:52:49 +00:00
|
|
|
#include <SmingCore.h>
|
2016-09-18 08:30:34 +00:00
|
|
|
#include <Endpoint.h>
|
2020-10-05 19:52:49 +00:00
|
|
|
#include <JsonObjectStream.h>
|
2016-06-29 15:00:22 +00:00
|
|
|
|
2017-10-01 21:24:41 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2016-12-04 22:45:25 +00:00
|
|
|
#define D0 16
|
|
|
|
#define D1 5
|
|
|
|
#define D2 4
|
|
|
|
#define D3 0
|
|
|
|
#define D4 2
|
|
|
|
#define D5 14
|
|
|
|
#define D6 12
|
|
|
|
#define D7 13
|
|
|
|
#define D8 15
|
|
|
|
|
2017-09-29 17:34:23 +00:00
|
|
|
class LED {
|
|
|
|
int highState = HIGH;
|
|
|
|
int pin = 2;
|
|
|
|
Timer animateTimer;
|
|
|
|
|
|
|
|
void animate() {
|
|
|
|
if (millis() % blinkRate > blinkOn) {
|
|
|
|
digitalWrite(pin, !highState);
|
|
|
|
} else {
|
|
|
|
digitalWrite(pin, highState);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
2020-10-05 19:52:49 +00:00
|
|
|
unsigned blinkRate = 4000;
|
|
|
|
unsigned blinkOn = 100;
|
2017-09-29 17:34:23 +00:00
|
|
|
|
|
|
|
LED() { }
|
|
|
|
|
|
|
|
void config(int pin_, bool highState_ = HIGH) {
|
|
|
|
pin = pin_;
|
|
|
|
highState = highState_;
|
|
|
|
|
|
|
|
pinMode(pin, OUTPUT);
|
2019-05-08 13:55:06 +00:00
|
|
|
animateTimer.initializeMs(50, [=]() { animate(); }).start();
|
2017-09-29 17:34:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void idle() {
|
|
|
|
blinkRate = 4000;
|
|
|
|
}
|
|
|
|
|
|
|
|
void high() {
|
|
|
|
blinkRate = 300;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-06-29 15:00:22 +00:00
|
|
|
class SpejsNode {
|
|
|
|
protected:
|
|
|
|
Timer keepaliveTimer;
|
|
|
|
|
2016-09-18 08:30:34 +00:00
|
|
|
HashMap<String, Endpoint*> endpoints;
|
2016-06-29 15:00:22 +00:00
|
|
|
|
|
|
|
void keepAliveHandler();
|
2016-12-04 23:17:51 +00:00
|
|
|
void initializeMDNS();
|
2016-06-29 15:00:22 +00:00
|
|
|
|
2016-10-04 18:33:34 +00:00
|
|
|
void buildMetadata(JsonObjectStream* stream);
|
2016-09-18 08:30:34 +00:00
|
|
|
|
2017-02-05 17:41:39 +00:00
|
|
|
void mqttCallback(String, String);
|
|
|
|
void otaUpdateCallback(bool result);
|
|
|
|
void httpFile(HttpRequest &request, HttpResponse &response);
|
2019-05-08 12:26:09 +00:00
|
|
|
void httpConfig(HttpRequest &request, HttpResponse &response);
|
2017-02-05 17:41:39 +00:00
|
|
|
void httpIndex(HttpRequest &request, HttpResponse &response);
|
2019-05-08 12:24:33 +00:00
|
|
|
|
|
|
|
void systemReady(void);
|
|
|
|
|
|
|
|
String wifiSSID = WIFI_SSID;
|
|
|
|
String wifiPassword = WIFI_PWD;
|
|
|
|
|
2019-05-08 14:09:44 +00:00
|
|
|
String brokerURL = "mqtt://" MQTT_BROKER;
|
2019-05-08 16:03:29 +00:00
|
|
|
String brokerClient = "";
|
2019-05-08 14:09:44 +00:00
|
|
|
|
2019-05-08 12:24:33 +00:00
|
|
|
bool brokerUseTLS = false;
|
2019-05-08 14:09:44 +00:00
|
|
|
|
|
|
|
#ifdef ENABLE_SSL
|
|
|
|
SslFingerprints fingerprints;
|
|
|
|
#endif
|
2016-06-29 15:00:22 +00:00
|
|
|
public:
|
2017-06-12 15:40:23 +00:00
|
|
|
MqttClient mqtt;
|
|
|
|
HttpServer http;
|
|
|
|
|
2016-12-04 22:45:25 +00:00
|
|
|
String deviceID;
|
|
|
|
String deviceType;
|
|
|
|
|
2017-09-29 17:34:23 +00:00
|
|
|
LED statusLED;
|
|
|
|
|
2020-10-05 19:52:49 +00:00
|
|
|
void (*onConnectedCallback)(void);
|
|
|
|
void (*onDisconnectedCallback)(void);
|
|
|
|
|
2016-12-04 22:45:25 +00:00
|
|
|
uint8_t currentSlot;
|
|
|
|
|
2016-06-29 15:00:22 +00:00
|
|
|
SpejsNode(String _deviceType) :
|
2020-10-05 19:52:49 +00:00
|
|
|
mqtt(),
|
|
|
|
deviceType(_deviceType), onConnectedCallback(NULL) {
|
|
|
|
mqtt.setCallback(MqttStringSubscriptionCallback(&SpejsNode::mqttCallback, this));
|
|
|
|
};
|
2016-06-29 15:00:22 +00:00
|
|
|
|
2017-06-12 15:40:23 +00:00
|
|
|
void onConnected();
|
2020-10-05 19:52:49 +00:00
|
|
|
void gotIP(IpAddress ip, IpAddress netmask, IpAddress gateway);
|
2017-06-12 15:40:23 +00:00
|
|
|
|
2018-06-28 13:35:32 +00:00
|
|
|
void init(bool debug=false);
|
2016-06-29 15:00:22 +00:00
|
|
|
|
|
|
|
bool notify(String key, String value);
|
2017-02-05 17:41:39 +00:00
|
|
|
bool subscribe(String topic);
|
|
|
|
|
2016-09-18 08:30:34 +00:00
|
|
|
void registerEndpoint(String key, Endpoint* cb);
|
2017-02-05 17:41:39 +00:00
|
|
|
|
2017-03-06 16:56:37 +00:00
|
|
|
String DEV_TOPIC(String t);
|
|
|
|
|
2017-10-01 21:24:41 +00:00
|
|
|
void loadJSON(std::vector<EndpointInitializer>);
|
2016-06-29 15:00:22 +00:00
|
|
|
};
|
2016-09-18 08:30:34 +00:00
|
|
|
|
|
|
|
#endif
|