stability of san

This commit is contained in:
Dmitry Borisenko
2020-12-11 03:21:50 +03:00
parent 71c8fec27b
commit 71468599fe
11 changed files with 125 additions and 176 deletions

View File

@@ -10,7 +10,8 @@ void eventGen2(String eventName, String eventValue) {
String event = eventName + " " + eventValue + ",";
eventBuf += event;
streamEventUDP(event);
if (jsonReadBool(configSetupJson, "snaMqtt")) publishEvent(eventName, eventValue);
//streamEventUDP(event);
}
void streamEventUDP(String event) {

View File

@@ -41,7 +41,6 @@ void addItem(String name) {
String url = serverIP + F("/projects/iotmanager/config/items/") + name + ".txt";
String item = getURL(url);
Serial.println(url);
Serial.println(item);
if (item == "error") return;
#endif
#ifndef FLASH_SIZE_1MB
@@ -75,30 +74,31 @@ void addItem(String name) {
item.replace("\r\n", "");
item.replace("\r", "");
item.replace("\n", "");
addFile(DEVICE_CONFIG_FILE, "\n" + item);
Serial.println(item);
}
void addPreset(String name) {
#ifdef FLASH_SIZE_1MB
String url2 = serverIP + F("/projects/iotmanager/config/presets/") + name + ".txt";
String preset = getURL(url2);
Serial.println(url2);
Serial.println(preset);
String url = serverIP + F("/projects/iotmanager/config/presets/") + name + ".txt";
String preset = getURL(url);
Serial.println(url);
if (preset == "error") return;
#endif
#ifndef FLASH_SIZE_1MB
String preset = readFile("presets/" + name + ".txt", 4048);
#endif
addFile(DEVICE_CONFIG_FILE, "\n" + preset);
Serial.println(preset);
name.replace(".c", ".s");
#ifdef FLASH_SIZE_1MB
String url = serverIP + F("/projects/iotmanager/config/presets/") + name + ".txt";
url = serverIP + F("/projects/iotmanager/config/presets/") + name + ".txt";
String scenario = getURL(url);
Serial.println(url);
Serial.println(scenario);
if (scenario == "error") return;
#endif
#ifndef FLASH_SIZE_1MB
@@ -106,8 +106,11 @@ void addPreset(String name) {
#endif
removeFile(DEVICE_SCENARIO_FILE);
addFile(DEVICE_SCENARIO_FILE, scenario);
loadScenario();
Serial.println(scenario);
}
void delAllItems() {

View File

@@ -72,7 +72,7 @@ void mqttSubscribe() {
mqtt.subscribe((mqttRootDevice + "/update").c_str());
if (jsonReadBool(configSetupJson, "snaMqtt")) {
mqtt.subscribe((mqttPrefix + "/+/+/status").c_str());
mqtt.subscribe((mqttPrefix + "/+/+/event").c_str());
mqtt.subscribe((mqttPrefix + "/+/+/info").c_str());
}
}
@@ -142,26 +142,24 @@ void mqttCallback(char* topic, uint8_t* payload, size_t length) {
SerialPrint("I", "=>MQTT", "Msg from iotmanager app: " + key + " " + payloadStr);
}
else if (topicStr.indexOf("status") != -1) {
else if (topicStr.indexOf("event") != -1) {
if (!jsonReadBool(configSetupJson, "snaMqtt")) {
return;
}
if (topicStr.indexOf(chipId) == -1) {
String devId = selectFromMarkerToMarker(topicStr, "/", 2);
String key = selectFromMarkerToMarker(topicStr, "/", 3);
String value = jsonReadStr(payloadStr, "status");
SerialPrint("I", "=>MQTT", "Msg from other device: '" + devId + "' " + key + " " + value);
eventGen2(key, value);
SerialPrint("I", "=>MQTT", "Received event from other device: '" + devId + "' " + key + " " + payloadStr);
String event = key + " " + payloadStr + ",";
eventBuf += event;
}
}
else if (topicStr.indexOf("info") != -1) {
if (topicStr.indexOf("scen") != -1) {
writeFile(String(DEVICE_SCENARIO_FILE), payloadStr);
loadScenario();
SerialPrint("I", "=>MQTT", "Scenario received");
loadScenario();
SerialPrint("I", "=>MQTT", "Scenario received");
}
}
@@ -215,6 +213,11 @@ boolean publishStatus(const String& topic, const String& data) {
return mqtt.publish(path.c_str(), json.c_str(), false);
}
boolean publishEvent(const String& topic, const String& data) {
String path = mqttRootDevice + "/" + topic + "/event";
return mqtt.publish(path.c_str(), data.c_str(), false);
}
boolean publishInfo(const String& topic, const String& data) {
String path = mqttRootDevice + "/" + topic + "/info";
return mqtt.publish(path.c_str(), data.c_str(), false);

View File

@@ -323,6 +323,10 @@ void web_init() {
SerialPrint("I", "Update", "firmware version: " + String(lastVersion));
String msg = "";
//if (FLASH_SIZE_1MB) {
// msg = F("Обновление невозможно, память устройства 1 мб");
//}
//else {
if (lastVersion == FIRMWARE_VERSION) {
msg = F("Актуальная версия прошивки уже установлена.");
}
@@ -338,6 +342,7 @@ void web_init() {
else if (lastVersion < FIRMWARE_VERSION) {
msg = F("Ошибка версии. Попробуйте повторить позже...");
}
//}
// else if (lastVersion == "") {
//msg = F("Нажмите на кнопку \"обновить прошивку\" повторно...");
@@ -361,7 +366,7 @@ void web_init() {
request->send(200, "text/html");
});
SerialPrint("I", F("Web"), F("WebAdmin Init"));
SerialPrint("I", F("Web"), F("WebAdmin Init"));
}
void setConfigParam(const char* param, const String& value) {

View File

@@ -1,20 +0,0 @@
//#include "BufferExecute.h"
//#include "items/SensorUltrasonicClass.h"
////#ifdef SensorUltrasonicEnabled
////=========================================Модуль ультрозвукового дальномера==================================================================
////ultrasonic-cm;id;anydata;Сенсоры;Расстояние;order;pin[12,13];map[1,100,1,100];c[1]
////=========================================================================================================================================
//SensorUltrasonic mySensorUltrasonic;
//void ultrasonicCm() {
// mySensorUltrasonic.update();
// String key = mySensorUltrasonic.gkey();
// sCmd.addCommand(key.c_str(), ultrasonicReading);
// mySensorUltrasonic.init();
// mySensorUltrasonic.clear();
//}
//
//void ultrasonicReading() {
// String key = sCmd.order();
// mySensorUltrasonic.SensorUltrasonicRead(key);
//}
////#endif