mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-26 22:22:16 +03:00
263 Impuls added
This commit is contained in:
@@ -3,19 +3,19 @@
|
||||
#include "Global.h"
|
||||
#include "Module/Terminal.h"
|
||||
|
||||
void loopCmdAdd(const String &cmdStr) {
|
||||
void loopCmdAdd(const String& cmdStr) {
|
||||
orderBuf += cmdStr;
|
||||
if (!cmdStr.endsWith(",")) {
|
||||
orderBuf += ",";
|
||||
}
|
||||
}
|
||||
|
||||
void fileCmdExecute(const String &filename) {
|
||||
void fileCmdExecute(const String& filename) {
|
||||
String cmdStr = readFile(filename, 4096);
|
||||
csvCmdExecute(cmdStr);
|
||||
}
|
||||
|
||||
void csvCmdExecute(String &cmdStr) {
|
||||
void csvCmdExecute(String& cmdStr) {
|
||||
cmdStr.replace(";", " ");
|
||||
cmdStr += "\r\n";
|
||||
cmdStr.replace("\r\n", "\n");
|
||||
@@ -30,7 +30,7 @@ void csvCmdExecute(String &cmdStr) {
|
||||
}
|
||||
}
|
||||
|
||||
void spaceCmdExecute(String &cmdStr) {
|
||||
void spaceCmdExecute(String& cmdStr) {
|
||||
cmdStr += "\r\n";
|
||||
cmdStr.replace("\r\n", "\n");
|
||||
cmdStr.replace("\r", "\n");
|
||||
@@ -52,7 +52,7 @@ void loopCmdExecute() {
|
||||
|
||||
void sensorsInit() {
|
||||
ts.add(
|
||||
SENSORS10SEC, 10000, [&](void *) {
|
||||
SENSORS10SEC, 10000, [&](void*) {
|
||||
String buf = sensorReadingMap10sec;
|
||||
while (buf.length()) {
|
||||
String tmp = selectToMarker(buf, ",");
|
||||
@@ -63,7 +63,7 @@ void sensorsInit() {
|
||||
nullptr, true);
|
||||
|
||||
ts.add(
|
||||
SENSORS30SEC, 30000, [&](void *) {
|
||||
SENSORS30SEC, 30000, [&](void*) {
|
||||
String buf = sensorReadingMap30sec;
|
||||
while (buf.length()) {
|
||||
String tmp = selectToMarker(buf, ",");
|
||||
@@ -74,3 +74,21 @@ void sensorsInit() {
|
||||
nullptr, true);
|
||||
}
|
||||
|
||||
void addKey(String& key, int number) {
|
||||
impulsKeyList += key + " " + String(number) + ",";
|
||||
}
|
||||
|
||||
int getKeyNum(String& key) {
|
||||
String keyNumberTableBuf = impulsKeyList;
|
||||
//SerialPrint("","",impulsKeyList);
|
||||
int number = -1;
|
||||
while (keyNumberTableBuf.length()) {
|
||||
String tmp = selectToMarker(keyNumberTableBuf, ",");
|
||||
String keyIncomming = selectToMarker(tmp, " ");
|
||||
if (keyIncomming == key) {
|
||||
number = selectToMarkerLast(tmp, " ").toInt();
|
||||
}
|
||||
keyNumberTableBuf = deleteBeforeDelimiter(keyNumberTableBuf, ",");
|
||||
}
|
||||
return number;
|
||||
}
|
||||
|
||||
@@ -33,17 +33,21 @@ String scenario = "";
|
||||
//orders and events
|
||||
String orderBuf = "";
|
||||
String eventBuf = "";
|
||||
|
||||
String itemsFile = "";
|
||||
String itemsLine = "";
|
||||
|
||||
//key lists and numbers
|
||||
String impulsKeyList = "";
|
||||
int impulsEnterCounter = -1;
|
||||
|
||||
|
||||
// Sensors
|
||||
int8_t dallasEnterCounter = -1;
|
||||
String sensorReadingMap10sec;
|
||||
String sensorReadingMap30sec;
|
||||
|
||||
// Logging
|
||||
String logging_value_names_list;
|
||||
String loggingKeyList;
|
||||
int enter_to_logging_counter;
|
||||
|
||||
// Upgrade
|
||||
|
||||
33
src/Init.cpp
33
src/Init.cpp
@@ -1,5 +1,5 @@
|
||||
#include "Init.h"
|
||||
|
||||
#include "BufferExecute.h"
|
||||
#include "Cmd.h"
|
||||
#include "Global.h"
|
||||
#include "items/LoggingClass.h"
|
||||
@@ -31,32 +31,13 @@ void Device_init() {
|
||||
if (myLogging != nullptr) {
|
||||
myLogging->clear();
|
||||
}
|
||||
logging_value_names_list = "";
|
||||
|
||||
loggingKeyList = "";
|
||||
|
||||
impulsKeyList = "";
|
||||
impulsEnterCounter = -1;
|
||||
|
||||
|
||||
|
||||
//enter_to_logging_counter = LOG1 - 1;
|
||||
//analog_value_names_list = "";
|
||||
//enter_to_analog_counter = 0;
|
||||
//dallas_value_name = "";
|
||||
//enter_to_dallas_counter = 0;
|
||||
//levelPr_value_name = "";
|
||||
//ultrasonicCm_value_name = "";
|
||||
//dhtT_value_name = "";
|
||||
//dhtH_value_name = "";
|
||||
//bmp280T_value_name = "";
|
||||
//bmp280P_value_name = "";
|
||||
//bme280T_value_name = "";
|
||||
//bme280P_value_name = "";
|
||||
//bme280H_value_name = "";
|
||||
//bme280A_value_name = "";
|
||||
//int array_sz = sizeof(sensors_reading_map) / sizeof(sensors_reading_map[0]);
|
||||
//for (int i = 0; i < array_sz; i++) {
|
||||
// sensors_reading_map[i] = 0;
|
||||
//}
|
||||
//for (int i = LOG1; i <= LOG5; i++) {
|
||||
// ts.remove(i);
|
||||
//}
|
||||
|
||||
#ifdef LAYOUT_IN_RAM
|
||||
all_widgets = "";
|
||||
#else
|
||||
|
||||
@@ -49,6 +49,8 @@ void cmd_init() {
|
||||
|
||||
sCmd.addCommand("logging", logging);
|
||||
|
||||
sCmd.addCommand("impuls-out", impuls);
|
||||
|
||||
handle_time_init();
|
||||
}
|
||||
|
||||
|
||||
@@ -26,11 +26,13 @@ void mqttInit() {
|
||||
if (mqtt.connected()) {
|
||||
SerialPrint("I", "MQTT", "OK");
|
||||
setLedStatus(LED_OFF);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
SerialPrint("E", "MQTT", "lost connection");
|
||||
mqttConnect();
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
SerialPrint("E", "WIFI", "Lost WiFi connection");
|
||||
ts.remove(WIFI_MQTT_CONNECTION_CHECK);
|
||||
startAPMode();
|
||||
@@ -89,7 +91,8 @@ boolean mqttConnect() {
|
||||
setLedStatus(LED_OFF);
|
||||
mqttSubscribe();
|
||||
res = true;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
SerialPrint("E", "MQTT", "could't connect, retry in " + String(MQTT_RECONNECT_INTERVAL / 1000) + "s");
|
||||
setLedStatus(LED_FAST);
|
||||
}
|
||||
@@ -116,8 +119,9 @@ void mqttCallback(char* topic, uint8_t* payload, size_t length) {
|
||||
choose_log_date_and_send();
|
||||
#endif
|
||||
|
||||
} else if (topicStr.indexOf("control")) {
|
||||
|
||||
}
|
||||
else if (topicStr.indexOf("control")) {
|
||||
|
||||
String key = selectFromMarkerToMarker(topicStr, "/", 3);
|
||||
|
||||
orderBuf += key;
|
||||
@@ -125,12 +129,14 @@ void mqttCallback(char* topic, uint8_t* payload, size_t length) {
|
||||
orderBuf += payloadStr;
|
||||
orderBuf += ",";
|
||||
|
||||
} else if (topicStr.indexOf("order")) {
|
||||
}
|
||||
else if (topicStr.indexOf("order")) {
|
||||
payloadStr.replace("_", " ");
|
||||
orderBuf += payloadStr;
|
||||
orderBuf += ",";
|
||||
|
||||
} else if (topicStr.indexOf("update")) {
|
||||
}
|
||||
else if (topicStr.indexOf("update")) {
|
||||
if (payloadStr == "1") {
|
||||
myNotAsyncActions->make(do_UPGRADE);
|
||||
}
|
||||
@@ -245,38 +251,38 @@ void publishState() {
|
||||
|
||||
const String getStateStr() {
|
||||
switch (mqtt.state()) {
|
||||
case -4:
|
||||
return F("no respond");
|
||||
break;
|
||||
case -3:
|
||||
return F("connection was broken");
|
||||
break;
|
||||
case -2:
|
||||
return F("connection failed");
|
||||
break;
|
||||
case -1:
|
||||
return F("client disconnected");
|
||||
break;
|
||||
case 0:
|
||||
return F("client connected");
|
||||
break;
|
||||
case 1:
|
||||
return F("doesn't support the requested version");
|
||||
break;
|
||||
case 2:
|
||||
return F("rejected the client identifier");
|
||||
break;
|
||||
case 3:
|
||||
return F("unable to accept the connection");
|
||||
break;
|
||||
case 4:
|
||||
return F("wrong username/password");
|
||||
break;
|
||||
case 5:
|
||||
return F("not authorized to connect");
|
||||
break;
|
||||
default:
|
||||
return F("unspecified");
|
||||
break;
|
||||
case -4:
|
||||
return F("no respond");
|
||||
break;
|
||||
case -3:
|
||||
return F("connection was broken");
|
||||
break;
|
||||
case -2:
|
||||
return F("connection failed");
|
||||
break;
|
||||
case -1:
|
||||
return F("client disconnected");
|
||||
break;
|
||||
case 0:
|
||||
return F("client connected");
|
||||
break;
|
||||
case 1:
|
||||
return F("doesn't support the requested version");
|
||||
break;
|
||||
case 2:
|
||||
return F("rejected the client identifier");
|
||||
break;
|
||||
case 3:
|
||||
return F("unable to accept the connection");
|
||||
break;
|
||||
case 4:
|
||||
return F("wrong username/password");
|
||||
break;
|
||||
case 5:
|
||||
return F("not authorized to connect");
|
||||
break;
|
||||
default:
|
||||
return F("unspecified");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ uint16_t hexStringToUint16(String hex) {
|
||||
}
|
||||
}
|
||||
|
||||
size_t itemsCount(String str, const String &separator) {
|
||||
size_t itemsCount(String str, const String& separator) {
|
||||
// если строки поиск нет сразу выход
|
||||
if (str.indexOf(separator) == -1) {
|
||||
return 0;
|
||||
@@ -91,7 +91,7 @@ size_t itemsCount(String str, const String &separator) {
|
||||
return cnt;
|
||||
}
|
||||
|
||||
boolean isDigitStr(const String &str) {
|
||||
boolean isDigitStr(const String& str) {
|
||||
for (size_t i = 0; i < str.length(); i++) {
|
||||
if (!isDigit(str.charAt(i))) {
|
||||
return false;
|
||||
@@ -111,3 +111,5 @@ String prettyBytes(size_t size) {
|
||||
return String(size / 1024.0 / 1024.0 / 1024.0) + "GB";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
#include "items/ImpulsOutClass.h"
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
#include "BufferExecute.h"
|
||||
#include "Class/LineParsing.h"
|
||||
#include "Global.h"
|
||||
#include "ItemsCmd.h"
|
||||
|
||||
ImpulsOutClass::ImpulsOutClass(unsigned long impulsPeriod, unsigned int impulsCount, unsigned int impulsPin) {
|
||||
_impulsPeriod = impulsPeriod;
|
||||
_impulsCount = impulsCount * 2;
|
||||
ImpulsOutClass::ImpulsOutClass(unsigned int impulsPin) {
|
||||
_impulsPin = impulsPin;
|
||||
pinMode(impulsPin, OUTPUT);
|
||||
}
|
||||
|
||||
ImpulsOutClass::~ImpulsOutClass() {}
|
||||
|
||||
void ImpulsOutClass::activate() {
|
||||
void ImpulsOutClass::execute(unsigned long impulsPeriod, unsigned int impulsCount) {
|
||||
_impulsPeriod = impulsPeriod;
|
||||
_impulsCount = impulsCount * 2;
|
||||
_impulsCountBuf = _impulsCount;
|
||||
}
|
||||
|
||||
@@ -38,18 +38,34 @@ void ImpulsOutClass::loop() {
|
||||
|
||||
MyImpulsOutVector* myImpulsOut = nullptr;
|
||||
|
||||
//void impuls() {
|
||||
// myLineParsing.update();
|
||||
// String loggingValueKey = myLineParsing.gvalue();
|
||||
// String key = myLineParsing.gkey();
|
||||
// String interv = myLineParsing.gint();
|
||||
// String maxcnt = myLineParsing.gmaxcnt();
|
||||
// myLineParsing.clear();
|
||||
//
|
||||
// logging_value_names_list += key + ",";
|
||||
//
|
||||
// static bool firstTime = true;
|
||||
// if (firstTime) myImpulsOut = new MyImpulsOutVector();
|
||||
// firstTime = false;
|
||||
// myImpulsOut->push_back(ImpulsOutClass(interv.toInt(), maxcnt.toInt(), loggingValueKey, key));
|
||||
//}
|
||||
void impuls() {
|
||||
myLineParsing.update();
|
||||
String key = myLineParsing.gkey();
|
||||
String pin = myLineParsing.gpin();
|
||||
myLineParsing.clear();
|
||||
|
||||
impulsEnterCounter++;
|
||||
addKey(key, impulsEnterCounter);
|
||||
|
||||
static bool firstTime = true;
|
||||
if (firstTime) myImpulsOut = new MyImpulsOutVector();
|
||||
firstTime = false;
|
||||
myImpulsOut->push_back(ImpulsOutClass(pin.toInt()));
|
||||
|
||||
sCmd.addCommand(key.c_str(), impulsExecute);
|
||||
}
|
||||
|
||||
void impulsExecute() {
|
||||
String key = sCmd.order();
|
||||
String impulsPeriod = sCmd.next();
|
||||
String impulsCount = sCmd.next();
|
||||
|
||||
int number = getKeyNum(key);
|
||||
SerialPrint("I", "Impuls", key + " " + String(number));
|
||||
|
||||
if (myImpulsOut != nullptr) {
|
||||
if (number != -1) {
|
||||
myImpulsOut->at(number).execute(impulsPeriod.toInt(), impulsCount.toInt());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,13 +54,13 @@ MyLoggingVector* myLogging = nullptr;
|
||||
|
||||
void logging() {
|
||||
myLineParsing.update();
|
||||
String loggingValueKey = myLineParsing.gvalue();
|
||||
String loggingValueKey = myLineParsing.gval();
|
||||
String key = myLineParsing.gkey();
|
||||
String interv = myLineParsing.gint();
|
||||
String maxcnt = myLineParsing.gmaxcnt();
|
||||
String maxcnt = myLineParsing.gcnt();
|
||||
myLineParsing.clear();
|
||||
|
||||
logging_value_names_list += key + ",";
|
||||
loggingKeyList += key + ",";
|
||||
|
||||
static bool firstTime = true;
|
||||
if (firstTime) myLogging = new MyLoggingVector();
|
||||
@@ -69,7 +69,7 @@ void logging() {
|
||||
}
|
||||
|
||||
void choose_log_date_and_send() {
|
||||
String all_line = logging_value_names_list;
|
||||
String all_line = loggingKeyList;
|
||||
while (all_line.length() != 0) {
|
||||
String tmp = selectToMarker(all_line, ",");
|
||||
sendLogData("logs/" + tmp + ".txt", tmp);
|
||||
|
||||
10
src/main.cpp
10
src/main.cpp
@@ -101,11 +101,11 @@ void setup() {
|
||||
just_load = false;
|
||||
initialized = true; //this second POST makes the data to be processed (you don't need to connect as "keep-alive" for that to work)
|
||||
|
||||
static bool firstTime = true;
|
||||
if (firstTime) myImpulsOut = new MyImpulsOutVector();
|
||||
firstTime = false;
|
||||
myImpulsOut->push_back(ImpulsOutClass(500, 10, 13));
|
||||
myImpulsOut->at(0).activate();
|
||||
//static bool firstTime = true;
|
||||
//if (firstTime) myImpulsOut = new MyImpulsOutVector();
|
||||
//firstTime = false;
|
||||
//myImpulsOut->push_back(ImpulsOutClass(500, 10, 13));
|
||||
//myImpulsOut->at(0).execute();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
Reference in New Issue
Block a user