mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-26 22:22:16 +03:00
stability of san
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
//===========Firmware=============================================================================================================================================
|
//===========Firmware=============================================================================================================================================
|
||||||
#define FIRMWARE_VERSION 271
|
#define FIRMWARE_VERSION 271
|
||||||
//#define FLASH_SIZE_1MB
|
//#define FLASH_SIZE_1MB true
|
||||||
#ifdef ESP8266
|
#ifdef ESP8266
|
||||||
#define FIRMWARE_NAME "esp8266-iotm"
|
#define FIRMWARE_NAME "esp8266-iotm"
|
||||||
#endif
|
#endif
|
||||||
@@ -122,3 +122,9 @@ enum ConfigType_t {
|
|||||||
|
|
||||||
//RAM: [===== ] 45.6% (used 37336 bytes from 81920 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 publishControl(String id, String topic, String state);
|
||||||
boolean publishChart_test(const String& topic, const String& data);
|
boolean publishChart_test(const String& topic, const String& data);
|
||||||
boolean publishStatus(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);
|
boolean publishInfo(const String& topic, const String& data);
|
||||||
|
|
||||||
void publishWidgets();
|
void publishWidgets();
|
||||||
|
|||||||
@@ -1,83 +1,85 @@
|
|||||||
//#pragma once
|
#ifdef modbus
|
||||||
//#include <Arduino.h>
|
#pragma once
|
||||||
//#include <ModbusMaster.h>
|
#include <Arduino.h>
|
||||||
//#include <SoftwareSerial.h>
|
#include <ModbusMaster.h>
|
||||||
//
|
#include <SoftwareSerial.h>
|
||||||
//#include "Class/LineParsing.h"
|
|
||||||
//#include "Global.h"
|
#include "Class/LineParsing.h"
|
||||||
//#include "items/SensorConvertingClass.h"
|
#include "Global.h"
|
||||||
//
|
#include "items/SensorConvertingClass.h"
|
||||||
//ModbusMaster modbus1;
|
|
||||||
//SoftwareSerial uart(13, 12); // RX, TX
|
ModbusMaster modbus1;
|
||||||
//
|
SoftwareSerial uart(13, 12); // RX, TX
|
||||||
//class SensorModbusClass : public SensorConvertingClass {
|
|
||||||
// public:
|
class SensorModbusClass : public SensorConvertingClass {
|
||||||
// SensorModbusClass() : SensorConvertingClass(){};
|
public:
|
||||||
//
|
SensorModbusClass() : SensorConvertingClass(){};
|
||||||
// void SensorModbusInit() {
|
|
||||||
// uart.begin(9600);
|
void SensorModbusInit() {
|
||||||
// jsonWriteStr(configOptionJson, _key + "_map", _map);
|
uart.begin(9600);
|
||||||
// jsonWriteStr(configOptionJson, _key + "_с", _c);
|
jsonWriteStr(configOptionJson, _key + "_map", _map);
|
||||||
// sensorReadingMap10sec += _key + " " + _addr + " " + _reg + ",";
|
jsonWriteStr(configOptionJson, _key + "_с", _c);
|
||||||
// Serial.println(sensorReadingMap10sec);
|
sensorReadingMap10sec += _key + " " + _addr + " " + _reg + ",";
|
||||||
// }
|
Serial.println(sensorReadingMap10sec);
|
||||||
//
|
}
|
||||||
// void SensorModbusRead(String key, uint8_t slaveAddress, uint16_t regAddress) {
|
|
||||||
// int value;
|
void SensorModbusRead(String key, uint8_t slaveAddress, uint16_t regAddress) {
|
||||||
//
|
int value;
|
||||||
// modbus1.begin(slaveAddress, uart);
|
|
||||||
// uint16_t reqisterValue = modbus1.readHoldingRegisters(regAddress, 1);
|
modbus1.begin(slaveAddress, uart);
|
||||||
// if (getResultMsg(&modbus1, reqisterValue)) {
|
uint16_t reqisterValue = modbus1.readHoldingRegisters(regAddress, 1);
|
||||||
// reqisterValue = modbus1.getResponseBuffer(0);
|
if (getResultMsg(&modbus1, reqisterValue)) {
|
||||||
// value = reqisterValue;
|
reqisterValue = modbus1.getResponseBuffer(0);
|
||||||
// } else {
|
value = reqisterValue;
|
||||||
// value = NULL;
|
} else {
|
||||||
// }
|
value = NULL;
|
||||||
//
|
}
|
||||||
// int valueFl = this->correction(key, value);
|
|
||||||
// eventGen2(key, String(valueFl));
|
int valueFl = this->correction(key, value);
|
||||||
// jsonWriteStr(configLiveJson, key, String(valueFl));
|
eventGen2(key, String(valueFl));
|
||||||
// publishStatus(key, String(valueFl));
|
jsonWriteStr(configLiveJson, key, String(valueFl));
|
||||||
// SerialPrint("I", "Sensor", "'" + key + "' data: " + String(valueFl) + ", Slave dev addr: " + String(slaveAddress) + ", Register: " + String(regAddress));
|
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;
|
bool getResultMsg(ModbusMaster* modbus1, uint16_t result) {
|
||||||
// switch (result) {
|
String tmpstr;
|
||||||
// case modbus1->ku8MBSuccess:
|
switch (result) {
|
||||||
// return true;
|
case modbus1->ku8MBSuccess:
|
||||||
// tmpstr += "Ok";
|
return true;
|
||||||
// break;
|
tmpstr += "Ok";
|
||||||
// case modbus1->ku8MBIllegalFunction:
|
break;
|
||||||
// tmpstr += "Illegal Function";
|
case modbus1->ku8MBIllegalFunction:
|
||||||
// break;
|
tmpstr += "Illegal Function";
|
||||||
// case modbus1->ku8MBIllegalDataAddress:
|
break;
|
||||||
// tmpstr += "Illegal Data Address";
|
case modbus1->ku8MBIllegalDataAddress:
|
||||||
// break;
|
tmpstr += "Illegal Data Address";
|
||||||
// case modbus1->ku8MBIllegalDataValue:
|
break;
|
||||||
// tmpstr += "Illegal Data Value";
|
case modbus1->ku8MBIllegalDataValue:
|
||||||
// break;
|
tmpstr += "Illegal Data Value";
|
||||||
// case modbus1->ku8MBSlaveDeviceFailure:
|
break;
|
||||||
// tmpstr += "Slave Device Failure";
|
case modbus1->ku8MBSlaveDeviceFailure:
|
||||||
// break;
|
tmpstr += "Slave Device Failure";
|
||||||
// case modbus1->ku8MBInvalidSlaveID:
|
break;
|
||||||
// tmpstr += "Invalid Slave ID";
|
case modbus1->ku8MBInvalidSlaveID:
|
||||||
// break;
|
tmpstr += "Invalid Slave ID";
|
||||||
// case modbus1->ku8MBInvalidFunction:
|
break;
|
||||||
// tmpstr += "Invalid Function";
|
case modbus1->ku8MBInvalidFunction:
|
||||||
// break;
|
tmpstr += "Invalid Function";
|
||||||
// case modbus1->ku8MBResponseTimedOut:
|
break;
|
||||||
// tmpstr += "Response Timed Out";
|
case modbus1->ku8MBResponseTimedOut:
|
||||||
// break;
|
tmpstr += "Response Timed Out";
|
||||||
// case modbus1->ku8MBInvalidCRC:
|
break;
|
||||||
// tmpstr += "Invalid CRC";
|
case modbus1->ku8MBInvalidCRC:
|
||||||
// break;
|
tmpstr += "Invalid CRC";
|
||||||
// default:
|
break;
|
||||||
// tmpstr += "Unknown error: " + String(result);
|
default:
|
||||||
// break;
|
tmpstr += "Unknown error: " + String(result);
|
||||||
// }
|
break;
|
||||||
// SerialPrint("I", "Modbus", tmpstr);
|
}
|
||||||
// return false;
|
SerialPrint("I", "Modbus", tmpstr);
|
||||||
// }
|
return false;
|
||||||
//};
|
}
|
||||||
//extern SensorModbusClass mySensorModbus;
|
};
|
||||||
|
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;
|
typedef std::vector<SensorUltrasonic> MySensorUltrasonicVector;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class SensorUltrasonic : public SensorConvertingClass {
|
class SensorUltrasonic : public SensorConvertingClass {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,6 @@ extra_scripts = ./tools/littlefsbuilder.py
|
|||||||
framework = arduino
|
framework = arduino
|
||||||
;board = esp01_1m
|
;board = esp01_1m
|
||||||
board = nodemcuv2
|
board = nodemcuv2
|
||||||
;board_build.ldscript = eagle.flash.1m512.ld
|
|
||||||
board_build.ldscript = eagle.flash.1m256.ld
|
board_build.ldscript = eagle.flash.1m256.ld
|
||||||
platform = https://github.com/platformio/platform-espressif8266.git
|
platform = https://github.com/platformio/platform-espressif8266.git
|
||||||
lib_deps =
|
lib_deps =
|
||||||
|
|||||||
@@ -10,7 +10,8 @@ void eventGen2(String eventName, String eventValue) {
|
|||||||
String event = eventName + " " + eventValue + ",";
|
String event = eventName + " " + eventValue + ",";
|
||||||
eventBuf += event;
|
eventBuf += event;
|
||||||
|
|
||||||
streamEventUDP(event);
|
if (jsonReadBool(configSetupJson, "snaMqtt")) publishEvent(eventName, eventValue);
|
||||||
|
//streamEventUDP(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void streamEventUDP(String event) {
|
void streamEventUDP(String event) {
|
||||||
|
|||||||
@@ -41,7 +41,6 @@ void addItem(String name) {
|
|||||||
String url = serverIP + F("/projects/iotmanager/config/items/") + name + ".txt";
|
String url = serverIP + F("/projects/iotmanager/config/items/") + name + ".txt";
|
||||||
String item = getURL(url);
|
String item = getURL(url);
|
||||||
Serial.println(url);
|
Serial.println(url);
|
||||||
Serial.println(item);
|
|
||||||
if (item == "error") return;
|
if (item == "error") return;
|
||||||
#endif
|
#endif
|
||||||
#ifndef FLASH_SIZE_1MB
|
#ifndef FLASH_SIZE_1MB
|
||||||
@@ -75,15 +74,16 @@ void addItem(String name) {
|
|||||||
item.replace("\r\n", "");
|
item.replace("\r\n", "");
|
||||||
item.replace("\r", "");
|
item.replace("\r", "");
|
||||||
item.replace("\n", "");
|
item.replace("\n", "");
|
||||||
|
|
||||||
addFile(DEVICE_CONFIG_FILE, "\n" + item);
|
addFile(DEVICE_CONFIG_FILE, "\n" + item);
|
||||||
|
Serial.println(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
void addPreset(String name) {
|
void addPreset(String name) {
|
||||||
#ifdef FLASH_SIZE_1MB
|
#ifdef FLASH_SIZE_1MB
|
||||||
String url2 = serverIP + F("/projects/iotmanager/config/presets/") + name + ".txt";
|
String url = serverIP + F("/projects/iotmanager/config/presets/") + name + ".txt";
|
||||||
String preset = getURL(url2);
|
String preset = getURL(url);
|
||||||
Serial.println(url2);
|
Serial.println(url);
|
||||||
Serial.println(preset);
|
|
||||||
if (preset == "error") return;
|
if (preset == "error") return;
|
||||||
#endif
|
#endif
|
||||||
#ifndef FLASH_SIZE_1MB
|
#ifndef FLASH_SIZE_1MB
|
||||||
@@ -91,14 +91,14 @@ void addPreset(String name) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
addFile(DEVICE_CONFIG_FILE, "\n" + preset);
|
addFile(DEVICE_CONFIG_FILE, "\n" + preset);
|
||||||
|
Serial.println(preset);
|
||||||
|
|
||||||
name.replace(".c", ".s");
|
name.replace(".c", ".s");
|
||||||
|
|
||||||
#ifdef FLASH_SIZE_1MB
|
#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);
|
String scenario = getURL(url);
|
||||||
Serial.println(url);
|
Serial.println(url);
|
||||||
Serial.println(scenario);
|
|
||||||
if (scenario == "error") return;
|
if (scenario == "error") return;
|
||||||
#endif
|
#endif
|
||||||
#ifndef FLASH_SIZE_1MB
|
#ifndef FLASH_SIZE_1MB
|
||||||
@@ -106,8 +106,11 @@ void addPreset(String name) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
removeFile(DEVICE_SCENARIO_FILE);
|
removeFile(DEVICE_SCENARIO_FILE);
|
||||||
|
|
||||||
|
|
||||||
addFile(DEVICE_SCENARIO_FILE, scenario);
|
addFile(DEVICE_SCENARIO_FILE, scenario);
|
||||||
loadScenario();
|
loadScenario();
|
||||||
|
Serial.println(scenario);
|
||||||
}
|
}
|
||||||
|
|
||||||
void delAllItems() {
|
void delAllItems() {
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ void mqttSubscribe() {
|
|||||||
mqtt.subscribe((mqttRootDevice + "/update").c_str());
|
mqtt.subscribe((mqttRootDevice + "/update").c_str());
|
||||||
|
|
||||||
if (jsonReadBool(configSetupJson, "snaMqtt")) {
|
if (jsonReadBool(configSetupJson, "snaMqtt")) {
|
||||||
mqtt.subscribe((mqttPrefix + "/+/+/status").c_str());
|
mqtt.subscribe((mqttPrefix + "/+/+/event").c_str());
|
||||||
mqtt.subscribe((mqttPrefix + "/+/+/info").c_str());
|
mqtt.subscribe((mqttPrefix + "/+/+/info").c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -142,18 +142,16 @@ void mqttCallback(char* topic, uint8_t* payload, size_t length) {
|
|||||||
SerialPrint("I", "=>MQTT", "Msg from iotmanager app: " + key + " " + payloadStr);
|
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")) {
|
if (!jsonReadBool(configSetupJson, "snaMqtt")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (topicStr.indexOf(chipId) == -1) {
|
if (topicStr.indexOf(chipId) == -1) {
|
||||||
String devId = selectFromMarkerToMarker(topicStr, "/", 2);
|
String devId = selectFromMarkerToMarker(topicStr, "/", 2);
|
||||||
String key = selectFromMarkerToMarker(topicStr, "/", 3);
|
String key = selectFromMarkerToMarker(topicStr, "/", 3);
|
||||||
String value = jsonReadStr(payloadStr, "status");
|
SerialPrint("I", "=>MQTT", "Received event from other device: '" + devId + "' " + key + " " + payloadStr);
|
||||||
|
String event = key + " " + payloadStr + ",";
|
||||||
SerialPrint("I", "=>MQTT", "Msg from other device: '" + devId + "' " + key + " " + value);
|
eventBuf += event;
|
||||||
|
|
||||||
eventGen2(key, value);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -215,6 +213,11 @@ boolean publishStatus(const String& topic, const String& data) {
|
|||||||
return mqtt.publish(path.c_str(), json.c_str(), false);
|
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) {
|
boolean publishInfo(const String& topic, const String& data) {
|
||||||
String path = mqttRootDevice + "/" + topic + "/info";
|
String path = mqttRootDevice + "/" + topic + "/info";
|
||||||
return mqtt.publish(path.c_str(), data.c_str(), false);
|
return mqtt.publish(path.c_str(), data.c_str(), false);
|
||||||
|
|||||||
@@ -323,6 +323,10 @@ void web_init() {
|
|||||||
SerialPrint("I", "Update", "firmware version: " + String(lastVersion));
|
SerialPrint("I", "Update", "firmware version: " + String(lastVersion));
|
||||||
|
|
||||||
String msg = "";
|
String msg = "";
|
||||||
|
//if (FLASH_SIZE_1MB) {
|
||||||
|
// msg = F("Обновление невозможно, память устройства 1 мб");
|
||||||
|
//}
|
||||||
|
//else {
|
||||||
if (lastVersion == FIRMWARE_VERSION) {
|
if (lastVersion == FIRMWARE_VERSION) {
|
||||||
msg = F("Актуальная версия прошивки уже установлена.");
|
msg = F("Актуальная версия прошивки уже установлена.");
|
||||||
}
|
}
|
||||||
@@ -338,6 +342,7 @@ void web_init() {
|
|||||||
else if (lastVersion < FIRMWARE_VERSION) {
|
else if (lastVersion < FIRMWARE_VERSION) {
|
||||||
msg = F("Ошибка версии. Попробуйте повторить позже...");
|
msg = F("Ошибка версии. Попробуйте повторить позже...");
|
||||||
}
|
}
|
||||||
|
//}
|
||||||
|
|
||||||
// else if (lastVersion == "") {
|
// else if (lastVersion == "") {
|
||||||
//msg = F("Нажмите на кнопку \"обновить прошивку\" повторно...");
|
//msg = F("Нажмите на кнопку \"обновить прошивку\" повторно...");
|
||||||
|
|||||||
@@ -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