spejsiot/spejsiot/SpejsNode.h

56 lines
1.2 KiB
C
Raw Normal View History

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>
#include <SmingCore/SmingCore.h>
2016-09-18 08:30:34 +00:00
#include <Endpoint.h>
2016-06-29 15:00:22 +00:00
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
2016-06-29 15:00:22 +00:00
class SpejsNode {
protected:
2016-08-30 19:24:34 +00:00
MqttClient mqtt;
HttpServer http;
2016-08-30 19:24:34 +00:00
2016-06-29 15:00:22 +00:00
Timer keepaliveTimer;
2016-09-18 08:30:34 +00:00
HashMap<String, Endpoint*> endpoints;
2016-06-29 15:00:22 +00:00
void onConnected();
void keepAliveHandler();
void initializeMDNS();
2016-06-29 15:00:22 +00:00
void buildMetadata(JsonObjectStream* stream);
2016-09-18 08:30:34 +00:00
2016-06-29 15:00:22 +00:00
public:
2016-12-04 22:45:25 +00:00
String deviceID;
String deviceType;
uint8_t currentSlot;
2016-06-29 15:00:22 +00:00
SpejsNode(String _deviceType) :
mqtt(MQTT_BROKER, MQTT_PORT, MqttStringSubscriptionCallback(&SpejsNode::mqttCallback, this)),
2016-10-04 19:06:45 +00:00
deviceType(_deviceType) {};
2016-06-29 15:00:22 +00:00
void init();
bool notify(String key, String value);
2016-09-18 08:30:34 +00:00
void registerEndpoint(String key, Endpoint* cb);
2016-06-29 15:00:22 +00:00
void mqttCallback(String, String);
void otaUpdateCallback(bool result);
void httpFile(HttpRequest &request, HttpResponse &response);
void httpIndex(HttpRequest &request, HttpResponse &response);
void httpMetadata(HttpRequest &request, HttpResponse &response);
2016-06-29 15:00:22 +00:00
};
2016-09-18 08:30:34 +00:00
#endif