Cleanup
parent
6ee1650381
commit
e264d9279e
|
@ -43,14 +43,14 @@ void SpejsNode::loadJSON(std::vector<EndpointInitializer> initializers) {
|
||||||
spiffs_mount_manual(0x100000, SPIFF_SIZE);
|
spiffs_mount_manual(0x100000, SPIFF_SIZE);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
DynamicJsonBuffer jsonBuffer;
|
DynamicJsonBuffer jsonBuffer;
|
||||||
if (fileExist(CONFIG_FILE)) {
|
if (fileExist(CONFIG_FILE)) {
|
||||||
Serial.println("Found config file");
|
Serial.println("Found config file");
|
||||||
int size = fileGetSize(CONFIG_FILE);
|
int size = fileGetSize(CONFIG_FILE);
|
||||||
Serial.printf("%d bytes\n", size);
|
Serial.printf("%d bytes\n", size);
|
||||||
char* jsonString = new char[size + 1];
|
char* jsonString = new char[size + 1];
|
||||||
fileGetContent(CONFIG_FILE, jsonString, size + 1);
|
fileGetContent(CONFIG_FILE, jsonString, size + 1);
|
||||||
JsonObject& root = jsonBuffer.parseObject(jsonString);
|
JsonObject& root = jsonBuffer.parseObject(jsonString);
|
||||||
|
|
||||||
if (root.containsKey("name"))
|
if (root.containsKey("name"))
|
||||||
deviceType = (root["name"]).asString();
|
deviceType = (root["name"]).asString();
|
||||||
|
@ -163,8 +163,6 @@ void SpejsNode::onConnected() {
|
||||||
http.addPath("/", HttpPathDelegate(&SpejsNode::httpIndex, this));
|
http.addPath("/", HttpPathDelegate(&SpejsNode::httpIndex, this));
|
||||||
http.setDefaultHandler(HttpPathDelegate(&SpejsNode::httpFile, this));
|
http.setDefaultHandler(HttpPathDelegate(&SpejsNode::httpFile, this));
|
||||||
|
|
||||||
// mDNS initialization
|
|
||||||
initializeMDNS();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpejsNode::httpFile(HttpRequest &request, HttpResponse &response)
|
void SpejsNode::httpFile(HttpRequest &request, HttpResponse &response)
|
||||||
|
@ -191,30 +189,6 @@ void SpejsNode::httpFile(HttpRequest &request, HttpResponse &response)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SpejsNode::initializeMDNS() {
|
|
||||||
/*
|
|
||||||
static struct mdns_info *info = (struct mdns_info *)os_zalloc(sizeof(struct mdns_info));
|
|
||||||
char tmp_name[32];
|
|
||||||
("iot-" + deviceID).toCharArray(tmp_name, 32);
|
|
||||||
info->host_name = tmp_name; // You can replace test with your own host name
|
|
||||||
info->ipAddr = WifiStation.getIP();
|
|
||||||
info->server_name = (char *) "spejsiot";
|
|
||||||
info->server_port = 80;
|
|
||||||
|
|
||||||
char tmp_version[32] = "version=";
|
|
||||||
int prefix_len = strlen(tmp_version);
|
|
||||||
strncat(tmp_version, BUILD_ID, 32);
|
|
||||||
info->txt_data[0] = tmp_version;
|
|
||||||
|
|
||||||
char tmp_type[32];
|
|
||||||
("type=" + deviceType).toCharArray(tmp_type, 32);
|
|
||||||
info->txt_data[1] = tmp_type;
|
|
||||||
|
|
||||||
espconn_mdns_init(info);
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Publish on device-specific topic
|
* Publish on device-specific topic
|
||||||
*/
|
*/
|
||||||
|
@ -240,16 +214,6 @@ void SpejsNode::registerEndpoint(String key, Endpoint* endpoint) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpejsNode::mqttCallback(String origtopic, String value) {
|
void SpejsNode::mqttCallback(String origtopic, String value) {
|
||||||
/*int propPos = origtopic.indexOf("/", devicePrefix.length());
|
|
||||||
String endpoint = origtopic.substring(devicePrefix.length(), propPos);
|
|
||||||
String property = origtopic.substring(propPos+1, origtopic.indexOf("/", propPos+1));
|
|
||||||
|
|
||||||
if(endpoints.contains(endpoint)) {
|
|
||||||
Serial.printf("%s - %s response: %d\n", endpoint.c_str(), property.c_str(), endpoints[endpoint]->onValue(property, value).status);
|
|
||||||
} else {
|
|
||||||
Serial.println("unknown topic? " + endpoint);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
for(unsigned int i = 0 ; i < endpoints.count() ; i++) {
|
for(unsigned int i = 0 ; i < endpoints.count() ; i++) {
|
||||||
endpoints.valueAt(i)->onMessage(origtopic, value);
|
endpoints.valueAt(i)->onMessage(origtopic, value);
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,7 +69,6 @@ protected:
|
||||||
void otaUpdateCallback(bool result);
|
void otaUpdateCallback(bool result);
|
||||||
void httpFile(HttpRequest &request, HttpResponse &response);
|
void httpFile(HttpRequest &request, HttpResponse &response);
|
||||||
void httpIndex(HttpRequest &request, HttpResponse &response);
|
void httpIndex(HttpRequest &request, HttpResponse &response);
|
||||||
void httpMetadata(HttpRequest &request, HttpResponse &response);
|
|
||||||
public:
|
public:
|
||||||
MqttClient mqtt;
|
MqttClient mqtt;
|
||||||
HttpServer http;
|
HttpServer http;
|
||||||
|
|
Loading…
Reference in New Issue