mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-26 14:12:16 +03:00
stability of san
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
//===========Firmware=============================================================================================================================================
|
||||
#define FIRMWARE_VERSION 271
|
||||
//#define FLASH_SIZE_1MB
|
||||
//#define FLASH_SIZE_1MB true
|
||||
#ifdef ESP8266
|
||||
#define FIRMWARE_NAME "esp8266-iotm"
|
||||
#endif
|
||||
@@ -121,4 +121,10 @@ enum ConfigType_t {
|
||||
//Flash: [===== ] 54.5% (used 569296 bytes from 1044464 bytes)
|
||||
|
||||
//RAM: [===== ] 45.6% (used 37336 bytes from 81920 bytes)
|
||||
//Flash: [====== ] 55.3% (used 577396 bytes from 1044464 bytes)
|
||||
//Flash: [====== ] 55.3% (used 577396 bytes from 1044464 bytes)
|
||||
|
||||
|
||||
//eventBuf - буфер событий которые проверяются в сценариях,
|
||||
//и если событие удовлетворяет какому нибудь условию то выполняются указанные команды
|
||||
|
||||
//orderBuf - буфер команд которые выполняются сейчас же
|
||||
@@ -17,6 +17,7 @@ boolean publishChart(const String& topic, const String& data);
|
||||
boolean publishControl(String id, String topic, String state);
|
||||
boolean publishChart_test(const String& topic, const String& data);
|
||||
boolean publishStatus(const String& topic, const String& data);
|
||||
boolean publishEvent(const String& topic, const String& data);
|
||||
boolean publishInfo(const String& topic, const String& data);
|
||||
|
||||
void publishWidgets();
|
||||
|
||||
@@ -1,83 +1,85 @@
|
||||
//#pragma once
|
||||
//#include <Arduino.h>
|
||||
//#include <ModbusMaster.h>
|
||||
//#include <SoftwareSerial.h>
|
||||
//
|
||||
//#include "Class/LineParsing.h"
|
||||
//#include "Global.h"
|
||||
//#include "items/SensorConvertingClass.h"
|
||||
//
|
||||
//ModbusMaster modbus1;
|
||||
//SoftwareSerial uart(13, 12); // RX, TX
|
||||
//
|
||||
//class SensorModbusClass : public SensorConvertingClass {
|
||||
// public:
|
||||
// SensorModbusClass() : SensorConvertingClass(){};
|
||||
//
|
||||
// void SensorModbusInit() {
|
||||
// uart.begin(9600);
|
||||
// jsonWriteStr(configOptionJson, _key + "_map", _map);
|
||||
// jsonWriteStr(configOptionJson, _key + "_с", _c);
|
||||
// sensorReadingMap10sec += _key + " " + _addr + " " + _reg + ",";
|
||||
// Serial.println(sensorReadingMap10sec);
|
||||
// }
|
||||
//
|
||||
// void SensorModbusRead(String key, uint8_t slaveAddress, uint16_t regAddress) {
|
||||
// int value;
|
||||
//
|
||||
// modbus1.begin(slaveAddress, uart);
|
||||
// uint16_t reqisterValue = modbus1.readHoldingRegisters(regAddress, 1);
|
||||
// if (getResultMsg(&modbus1, reqisterValue)) {
|
||||
// reqisterValue = modbus1.getResponseBuffer(0);
|
||||
// value = reqisterValue;
|
||||
// } else {
|
||||
// value = NULL;
|
||||
// }
|
||||
//
|
||||
// int valueFl = this->correction(key, value);
|
||||
// eventGen2(key, String(valueFl));
|
||||
// jsonWriteStr(configLiveJson, key, String(valueFl));
|
||||
// publishStatus(key, String(valueFl));
|
||||
// SerialPrint("I", "Sensor", "'" + key + "' data: " + String(valueFl) + ", Slave dev addr: " + String(slaveAddress) + ", Register: " + String(regAddress));
|
||||
// }
|
||||
//
|
||||
// bool getResultMsg(ModbusMaster* modbus1, uint16_t result) {
|
||||
// String tmpstr;
|
||||
// switch (result) {
|
||||
// case modbus1->ku8MBSuccess:
|
||||
// return true;
|
||||
// tmpstr += "Ok";
|
||||
// break;
|
||||
// case modbus1->ku8MBIllegalFunction:
|
||||
// tmpstr += "Illegal Function";
|
||||
// break;
|
||||
// case modbus1->ku8MBIllegalDataAddress:
|
||||
// tmpstr += "Illegal Data Address";
|
||||
// break;
|
||||
// case modbus1->ku8MBIllegalDataValue:
|
||||
// tmpstr += "Illegal Data Value";
|
||||
// break;
|
||||
// case modbus1->ku8MBSlaveDeviceFailure:
|
||||
// tmpstr += "Slave Device Failure";
|
||||
// break;
|
||||
// case modbus1->ku8MBInvalidSlaveID:
|
||||
// tmpstr += "Invalid Slave ID";
|
||||
// break;
|
||||
// case modbus1->ku8MBInvalidFunction:
|
||||
// tmpstr += "Invalid Function";
|
||||
// break;
|
||||
// case modbus1->ku8MBResponseTimedOut:
|
||||
// tmpstr += "Response Timed Out";
|
||||
// break;
|
||||
// case modbus1->ku8MBInvalidCRC:
|
||||
// tmpstr += "Invalid CRC";
|
||||
// break;
|
||||
// default:
|
||||
// tmpstr += "Unknown error: " + String(result);
|
||||
// break;
|
||||
// }
|
||||
// SerialPrint("I", "Modbus", tmpstr);
|
||||
// return false;
|
||||
// }
|
||||
//};
|
||||
//extern SensorModbusClass mySensorModbus;
|
||||
#ifdef modbus
|
||||
#pragma once
|
||||
#include <Arduino.h>
|
||||
#include <ModbusMaster.h>
|
||||
#include <SoftwareSerial.h>
|
||||
|
||||
#include "Class/LineParsing.h"
|
||||
#include "Global.h"
|
||||
#include "items/SensorConvertingClass.h"
|
||||
|
||||
ModbusMaster modbus1;
|
||||
SoftwareSerial uart(13, 12); // RX, TX
|
||||
|
||||
class SensorModbusClass : public SensorConvertingClass {
|
||||
public:
|
||||
SensorModbusClass() : SensorConvertingClass(){};
|
||||
|
||||
void SensorModbusInit() {
|
||||
uart.begin(9600);
|
||||
jsonWriteStr(configOptionJson, _key + "_map", _map);
|
||||
jsonWriteStr(configOptionJson, _key + "_с", _c);
|
||||
sensorReadingMap10sec += _key + " " + _addr + " " + _reg + ",";
|
||||
Serial.println(sensorReadingMap10sec);
|
||||
}
|
||||
|
||||
void SensorModbusRead(String key, uint8_t slaveAddress, uint16_t regAddress) {
|
||||
int value;
|
||||
|
||||
modbus1.begin(slaveAddress, uart);
|
||||
uint16_t reqisterValue = modbus1.readHoldingRegisters(regAddress, 1);
|
||||
if (getResultMsg(&modbus1, reqisterValue)) {
|
||||
reqisterValue = modbus1.getResponseBuffer(0);
|
||||
value = reqisterValue;
|
||||
} else {
|
||||
value = NULL;
|
||||
}
|
||||
|
||||
int valueFl = this->correction(key, value);
|
||||
eventGen2(key, String(valueFl));
|
||||
jsonWriteStr(configLiveJson, key, String(valueFl));
|
||||
publishStatus(key, String(valueFl));
|
||||
SerialPrint("I", "Sensor", "'" + key + "' data: " + String(valueFl) + ", Slave dev addr: " + String(slaveAddress) + ", Register: " + String(regAddress));
|
||||
}
|
||||
|
||||
bool getResultMsg(ModbusMaster* modbus1, uint16_t result) {
|
||||
String tmpstr;
|
||||
switch (result) {
|
||||
case modbus1->ku8MBSuccess:
|
||||
return true;
|
||||
tmpstr += "Ok";
|
||||
break;
|
||||
case modbus1->ku8MBIllegalFunction:
|
||||
tmpstr += "Illegal Function";
|
||||
break;
|
||||
case modbus1->ku8MBIllegalDataAddress:
|
||||
tmpstr += "Illegal Data Address";
|
||||
break;
|
||||
case modbus1->ku8MBIllegalDataValue:
|
||||
tmpstr += "Illegal Data Value";
|
||||
break;
|
||||
case modbus1->ku8MBSlaveDeviceFailure:
|
||||
tmpstr += "Slave Device Failure";
|
||||
break;
|
||||
case modbus1->ku8MBInvalidSlaveID:
|
||||
tmpstr += "Invalid Slave ID";
|
||||
break;
|
||||
case modbus1->ku8MBInvalidFunction:
|
||||
tmpstr += "Invalid Function";
|
||||
break;
|
||||
case modbus1->ku8MBResponseTimedOut:
|
||||
tmpstr += "Response Timed Out";
|
||||
break;
|
||||
case modbus1->ku8MBInvalidCRC:
|
||||
tmpstr += "Invalid CRC";
|
||||
break;
|
||||
default:
|
||||
tmpstr += "Unknown error: " + String(result);
|
||||
break;
|
||||
}
|
||||
SerialPrint("I", "Modbus", tmpstr);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
extern SensorModbusClass mySensorModbus;
|
||||
#endif
|
||||
@@ -1,49 +0,0 @@
|
||||
//#pragma once
|
||||
//#include <Arduino.h>
|
||||
//
|
||||
//#include "Class/LineParsing.h"
|
||||
//#include "Global.h"
|
||||
//#include "items/SensorConvertingClass.h"
|
||||
//#include "GyverFilters.h"
|
||||
//
|
||||
//GMedian<6, int> testFilter;
|
||||
//
|
||||
//class SensorUltrasonic : public SensorConvertingClass {
|
||||
// public:
|
||||
// SensorUltrasonic() : SensorConvertingClass(){};
|
||||
// void init() {
|
||||
// sensorReadingMap10sec += _key + ",";
|
||||
// String trig = selectFromMarkerToMarker(_pin, ",", 0);
|
||||
// String echo = selectFromMarkerToMarker(_pin, ",", 1);
|
||||
// pinMode(trig.toInt(), OUTPUT);
|
||||
// pinMode(echo.toInt(), INPUT);
|
||||
// jsonWriteStr(configOptionJson, _key + "_trig", trig);
|
||||
// jsonWriteStr(configOptionJson, _key + "_echo", echo);
|
||||
// jsonWriteStr(configOptionJson, _key + "_map", _map);
|
||||
// jsonWriteStr(configOptionJson, _key + "_с", _c);
|
||||
// }
|
||||
//
|
||||
// void SensorUltrasonicRead(String key) {
|
||||
// int trig = jsonReadStr(configOptionJson, key + "_trig").toInt();
|
||||
// int echo = jsonReadStr(configOptionJson, key + "_echo").toInt();
|
||||
// int value;
|
||||
//
|
||||
// digitalWrite(trig, LOW);
|
||||
// delayMicroseconds(2);
|
||||
// digitalWrite(trig, HIGH);
|
||||
// delayMicroseconds(10);
|
||||
// digitalWrite(trig, LOW);
|
||||
// long duration_ = pulseIn(echo, HIGH, 30000); // 3000 µs = 50cm // 30000 µs = 5 m
|
||||
// value = duration_ / 29 / 2;
|
||||
//
|
||||
// value = testFilter.filtered(value);
|
||||
//
|
||||
// value = this->mapping(key, value);
|
||||
// float valueFl = this->correction(key, value);
|
||||
// eventGen2(key, String(valueFl));
|
||||
// jsonWriteStr(configLiveJson, key, String(valueFl));
|
||||
// publishStatus(key, String(valueFl));
|
||||
// SerialPrint("I", "Sensor", "'" + key + "' data: " + String(valueFl));
|
||||
// }
|
||||
//};
|
||||
//extern SensorUltrasonic mySensorUltrasonic;
|
||||
@@ -8,8 +8,6 @@ class SensorUltrasonic;
|
||||
|
||||
typedef std::vector<SensorUltrasonic> MySensorUltrasonicVector;
|
||||
|
||||
|
||||
|
||||
class SensorUltrasonic : public SensorConvertingClass {
|
||||
public:
|
||||
|
||||
|
||||
@@ -37,7 +37,6 @@ extra_scripts = ./tools/littlefsbuilder.py
|
||||
framework = arduino
|
||||
;board = esp01_1m
|
||||
board = nodemcuv2
|
||||
;board_build.ldscript = eagle.flash.1m512.ld
|
||||
board_build.ldscript = eagle.flash.1m256.ld
|
||||
platform = https://github.com/platformio/platform-espressif8266.git
|
||||
lib_deps =
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user