mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-30 11:59:12 +03:00
add button with name (wo number)
This commit is contained in:
@@ -10,6 +10,8 @@ String selectToMarkerLast(String str, String found);
|
|||||||
|
|
||||||
String selectToMarker(String str, String found);
|
String selectToMarker(String str, String found);
|
||||||
|
|
||||||
|
String extractInner(String str);
|
||||||
|
|
||||||
String deleteAfterDelimiter(String str, String found);
|
String deleteAfterDelimiter(String str, String found);
|
||||||
|
|
||||||
String deleteBeforeDelimiter(String str, String found);
|
String deleteBeforeDelimiter(String str, String found);
|
||||||
|
|||||||
@@ -31,7 +31,8 @@ StringCommand::StringCommand()
|
|||||||
commandCount(0),
|
commandCount(0),
|
||||||
defaultHandler(NULL),
|
defaultHandler(NULL),
|
||||||
term('\n'), // default terminator for commands, newline character
|
term('\n'), // default terminator for commands, newline character
|
||||||
last(NULL)
|
last(NULL),
|
||||||
|
main(NULL)
|
||||||
{
|
{
|
||||||
strcpy(delim, " "); // strtok_r needs a null-terminated string
|
strcpy(delim, " "); // strtok_r needs a null-terminated string
|
||||||
clearBuffer();
|
clearBuffer();
|
||||||
@@ -130,3 +131,7 @@ void StringCommand::clearBuffer() {
|
|||||||
char *StringCommand::next() {
|
char *StringCommand::next() {
|
||||||
return strtok_r(NULL, delim, &last);
|
return strtok_r(NULL, delim, &last);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *StringCommand::order() {
|
||||||
|
return strtok_r(buffer, delim, &main);
|
||||||
|
}
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ class StringCommand {
|
|||||||
void readStr(String sBuffer ); // Main entry point.
|
void readStr(String sBuffer ); // Main entry point.
|
||||||
void clearBuffer(); // Clears the input buffer.
|
void clearBuffer(); // Clears the input buffer.
|
||||||
char *next(); // Returns pointer to next token found in command buffer (for getting arguments to commands).
|
char *next(); // Returns pointer to next token found in command buffer (for getting arguments to commands).
|
||||||
|
char *order();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Command/handler dictionary
|
// Command/handler dictionary
|
||||||
@@ -70,6 +71,7 @@ class StringCommand {
|
|||||||
char buffer[SERIALCOMMAND_BUFFER + 1]; // Buffer of stored characters while waiting for terminator character
|
char buffer[SERIALCOMMAND_BUFFER + 1]; // Buffer of stored characters while waiting for terminator character
|
||||||
byte bufPos; // Current position in the buffer
|
byte bufPos; // Current position in the buffer
|
||||||
char *last; // State variable used by strtok_r during processing
|
char *last; // State variable used by strtok_r during processing
|
||||||
|
char *main;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //StringCommand_h
|
#endif //StringCommand_h
|
||||||
|
|||||||
182
src/Cmd.cpp
182
src/Cmd.cpp
@@ -1,5 +1,4 @@
|
|||||||
#include "Global.h"
|
#include "Global.h"
|
||||||
|
|
||||||
#include "Module/Terminal.h"
|
#include "Module/Terminal.h"
|
||||||
#include "Servo/Servos.h"
|
#include "Servo/Servos.h"
|
||||||
|
|
||||||
@@ -20,7 +19,7 @@ void getData();
|
|||||||
|
|
||||||
void cmd_init() {
|
void cmd_init() {
|
||||||
sCmd.addCommand("button", button);
|
sCmd.addCommand("button", button);
|
||||||
sCmd.addCommand("buttonSet", buttonSet);
|
//sCmd.addCommand("buttonSet", buttonSet);
|
||||||
sCmd.addCommand("buttonChange", buttonChange);
|
sCmd.addCommand("buttonChange", buttonChange);
|
||||||
|
|
||||||
sCmd.addCommand("pinSet", pinSet);
|
sCmd.addCommand("pinSet", pinSet);
|
||||||
@@ -108,80 +107,137 @@ void cmd_init() {
|
|||||||
|
|
||||||
//==========================================================================================================
|
//==========================================================================================================
|
||||||
//==========================================Модуль кнопок===================================================
|
//==========================================Модуль кнопок===================================================
|
||||||
|
//button out light toggle Кнопки Свет 1 pin[12] inv[1] st[1]
|
||||||
void button() {
|
void button() {
|
||||||
pm.info("create 'button'");
|
String command = sCmd.order();
|
||||||
String number = sCmd.next();
|
pm.info("create '" + command + "'");
|
||||||
String param = sCmd.next();
|
String type = sCmd.next();
|
||||||
String widget = sCmd.next();
|
String key = sCmd.next();
|
||||||
|
String file = sCmd.next();
|
||||||
String page = sCmd.next();
|
String page = sCmd.next();
|
||||||
String state = sCmd.next();
|
String descr = sCmd.next();
|
||||||
String pageNumber = sCmd.next();
|
String order = sCmd.next();
|
||||||
|
|
||||||
jsonWriteStr(configOptionJson, "button_param" + number, param);
|
String pin;
|
||||||
jsonWriteStr(configLiveJson, "button" + number, state);
|
String inv;
|
||||||
|
String state;
|
||||||
|
|
||||||
if (isDigitStr(param)) {
|
for (int i = 1; i < 6; i++) {
|
||||||
pinMode(param.toInt(), OUTPUT);
|
String arg = sCmd.next();
|
||||||
digitalWrite(param.toInt(), state.toInt());
|
if (arg != "") {
|
||||||
}
|
if (arg.indexOf("pin[") != -1) {
|
||||||
|
pin = extractInner(arg);
|
||||||
if (param == "scen") {
|
}
|
||||||
jsonWriteStr(configSetupJson, "scen", state);
|
if (arg.indexOf("inv[") != -1) {
|
||||||
loadScenario();
|
inv = extractInner(arg);
|
||||||
saveConfig();
|
}
|
||||||
}
|
if (arg.indexOf("st[") != -1) {
|
||||||
|
state = extractInner(arg);
|
||||||
if (param.indexOf("line") != -1) {
|
}
|
||||||
String str = param;
|
|
||||||
while (str.length()) {
|
|
||||||
if (str == "") return;
|
|
||||||
String tmp = selectToMarker(str, ","); //line1,
|
|
||||||
String number = deleteBeforeDelimiter(tmp, "e"); //1,
|
|
||||||
number.replace(",", "");
|
|
||||||
Serial.println(number);
|
|
||||||
int number_int = number.toInt();
|
|
||||||
scenario_line_status[number_int] = state.toInt();
|
|
||||||
str = deleteBeforeDelimiter(str, ",");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
createWidget(widget, page, pageNumber, "toggle", "button" + number);
|
|
||||||
|
Serial.println(pin);
|
||||||
|
Serial.println(inv);
|
||||||
|
Serial.println(state);
|
||||||
|
|
||||||
|
createWidget(descr, page, order, file, key);
|
||||||
|
|
||||||
|
sCmd.addCommand(key.c_str(), buttonSet);
|
||||||
|
|
||||||
|
if (pin != "") {
|
||||||
|
pinMode(pin.toInt(), OUTPUT);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (state != "") {
|
||||||
|
digitalWrite(pin.toInt(), state.toInt());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//void button() {
|
||||||
|
// pm.info("create 'button'");
|
||||||
|
// String number = sCmd.next();
|
||||||
|
// String param = sCmd.next();
|
||||||
|
// String widget = sCmd.next();
|
||||||
|
// String page = sCmd.next();
|
||||||
|
// String state = sCmd.next();
|
||||||
|
// String pageNumber = sCmd.next();
|
||||||
|
//
|
||||||
|
// jsonWriteStr(configOptionJson, "button_param" + number, param);
|
||||||
|
// jsonWriteStr(configLiveJson, "button" + number, state);
|
||||||
|
//
|
||||||
|
// if (isDigitStr(param)) {
|
||||||
|
// pinMode(param.toInt(), OUTPUT);
|
||||||
|
// digitalWrite(param.toInt(), state.toInt());
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// if (param == "scen") {
|
||||||
|
// jsonWriteStr(configSetupJson, "scen", state);
|
||||||
|
// loadScenario();
|
||||||
|
// saveConfig();
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// if (param.indexOf("line") != -1) {
|
||||||
|
// String str = param;
|
||||||
|
// while (str.length()) {
|
||||||
|
// if (str == "") return;
|
||||||
|
// String tmp = selectToMarker(str, ","); //line1,
|
||||||
|
// String number = deleteBeforeDelimiter(tmp, "e"); //1,
|
||||||
|
// number.replace(",", "");
|
||||||
|
// Serial.println(number);
|
||||||
|
// int number_int = number.toInt();
|
||||||
|
// scenario_line_status[number_int] = state.toInt();
|
||||||
|
// str = deleteBeforeDelimiter(str, ",");
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// createWidget(widget, page, pageNumber, "toggle", "button" + number);
|
||||||
|
//}
|
||||||
|
|
||||||
void buttonSet() {
|
void buttonSet() {
|
||||||
String button_number = sCmd.next();
|
String order = sCmd.order();
|
||||||
String button_state = sCmd.next();
|
String state = sCmd.next();
|
||||||
String button_param = jsonReadStr(configOptionJson, "button_param" + button_number);
|
|
||||||
|
|
||||||
if (button_param != "na" || button_param != "scen" || button_param.indexOf("line") != -1) {
|
//Serial.println(order);
|
||||||
digitalWrite(button_param.toInt(), button_state.toInt());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (button_param == "scen") {
|
eventGen(order, "");
|
||||||
jsonWriteStr(configSetupJson, "scen", button_state);
|
jsonWriteStr(configLiveJson, order, state);
|
||||||
loadScenario();
|
MqttClient::publishStatus(order, state);
|
||||||
saveConfig();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (button_param.indexOf("line") != -1) {
|
|
||||||
String str = button_param;
|
|
||||||
while (str.length() != 0) {
|
|
||||||
if (str == "") return;
|
|
||||||
String tmp = selectToMarker(str, ","); //line1,
|
|
||||||
String number = deleteBeforeDelimiter(tmp, "e"); //1,
|
|
||||||
number.replace(",", "");
|
|
||||||
Serial.println(number);
|
|
||||||
int number_int = number.toInt();
|
|
||||||
scenario_line_status[number_int] = button_state.toInt();
|
|
||||||
str = deleteBeforeDelimiter(str, ",");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
eventGen("button", button_number);
|
|
||||||
jsonWriteStr(configLiveJson, "button" + button_number, button_state);
|
|
||||||
MqttClient::publishStatus("button" + button_number, button_state);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//void buttonSet() {
|
||||||
|
// String button_number = sCmd.next();
|
||||||
|
// String button_state = sCmd.next();
|
||||||
|
// String button_param = jsonReadStr(configOptionJson, "button_param" + button_number);
|
||||||
|
//
|
||||||
|
// if (button_param != "na" || button_param != "scen" || button_param.indexOf("line") != -1) {
|
||||||
|
// digitalWrite(button_param.toInt(), button_state.toInt());
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// if (button_param == "scen") {
|
||||||
|
// jsonWriteStr(configSetupJson, "scen", button_state);
|
||||||
|
// loadScenario();
|
||||||
|
// saveConfig();
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// if (button_param.indexOf("line") != -1) {
|
||||||
|
// String str = button_param;
|
||||||
|
// while (str.length() != 0) {
|
||||||
|
// if (str == "") return;
|
||||||
|
// String tmp = selectToMarker(str, ","); //line1,
|
||||||
|
// String number = deleteBeforeDelimiter(tmp, "e"); //1,
|
||||||
|
// number.replace(",", "");
|
||||||
|
// Serial.println(number);
|
||||||
|
// int number_int = number.toInt();
|
||||||
|
// scenario_line_status[number_int] = button_state.toInt();
|
||||||
|
// str = deleteBeforeDelimiter(str, ",");
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// eventGen("button", button_number);
|
||||||
|
// jsonWriteStr(configLiveJson, "button" + button_number, button_state);
|
||||||
|
// MqttClient::publishStatus("button" + button_number, button_state);
|
||||||
|
//}
|
||||||
|
|
||||||
void buttonChange() {
|
void buttonChange() {
|
||||||
String button_number = sCmd.next();
|
String button_number = sCmd.next();
|
||||||
if (!isDigitStr(button_number)) {
|
if (!isDigitStr(button_number)) {
|
||||||
|
|||||||
@@ -114,11 +114,14 @@ void handleSubscribedUpdates(char* topic, uint8_t* payload, size_t length) {
|
|||||||
pm.info(topicStr);
|
pm.info(topicStr);
|
||||||
|
|
||||||
String payloadStr;
|
String payloadStr;
|
||||||
|
|
||||||
payloadStr.reserve(length + 1);
|
payloadStr.reserve(length + 1);
|
||||||
for (size_t i = 0; i < length; i++) {
|
for (size_t i = 0; i < length; i++) {
|
||||||
payloadStr += (char)payload[i];
|
payloadStr += (char)payload[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
pm.info(payloadStr);
|
pm.info(payloadStr);
|
||||||
|
|
||||||
if (payloadStr.startsWith("HELLO")) {
|
if (payloadStr.startsWith("HELLO")) {
|
||||||
pm.info("Full update");
|
pm.info("Full update");
|
||||||
publishWidgets();
|
publishWidgets();
|
||||||
@@ -126,35 +129,40 @@ void handleSubscribedUpdates(char* topic, uint8_t* payload, size_t length) {
|
|||||||
#ifdef LOGGING_ENABLED
|
#ifdef LOGGING_ENABLED
|
||||||
choose_log_date_and_send();
|
choose_log_date_and_send();
|
||||||
#endif
|
#endif
|
||||||
} else if (topicStr.indexOf("control")) {
|
|
||||||
// название топика - команда,
|
|
||||||
// значение - параметр
|
|
||||||
//IoTmanager/800324-1458415/button99/control 1
|
|
||||||
String topic = selectFromMarkerToMarker(topicStr, "/", 3);
|
|
||||||
topic = add_set(topic);
|
|
||||||
String number = selectToMarkerLast(topic, "Set");
|
|
||||||
topic.replace(number, "");
|
|
||||||
|
|
||||||
order_loop += topic;
|
} else if (topicStr.indexOf("control")) {
|
||||||
order_loop += " ";
|
|
||||||
order_loop += number;
|
//iotTeam/12882830-1458415/light 1
|
||||||
|
|
||||||
|
String key = selectFromMarkerToMarker(topicStr, "/", 3);
|
||||||
|
|
||||||
|
order_loop += key;
|
||||||
order_loop += " ";
|
order_loop += " ";
|
||||||
order_loop += payloadStr;
|
order_loop += payloadStr;
|
||||||
order_loop += ",";
|
order_loop += ",";
|
||||||
|
|
||||||
} else if (topicStr.indexOf("order")) {
|
} else if (topicStr.indexOf("order")) {
|
||||||
|
|
||||||
payloadStr.replace("_", " ");
|
payloadStr.replace("_", " ");
|
||||||
order_loop += payloadStr;
|
order_loop += payloadStr;
|
||||||
order_loop += ",";
|
order_loop += ",";
|
||||||
|
|
||||||
} else if (topicStr.indexOf("update")) {
|
} else if (topicStr.indexOf("update")) {
|
||||||
|
|
||||||
if (payloadStr == "1") {
|
if (payloadStr == "1") {
|
||||||
updateFlag = true;
|
updateFlag = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (topicStr.indexOf("devc")) {
|
} else if (topicStr.indexOf("devc")) {
|
||||||
|
|
||||||
writeFile(String(DEVICE_CONFIG_FILE), payloadStr);
|
writeFile(String(DEVICE_CONFIG_FILE), payloadStr);
|
||||||
Device_init();
|
Device_init();
|
||||||
|
|
||||||
} else if (topicStr.indexOf("devs")) {
|
} else if (topicStr.indexOf("devs")) {
|
||||||
|
|
||||||
writeFile(String(DEVICE_SCENARIO_FILE), payloadStr);
|
writeFile(String(DEVICE_SCENARIO_FILE), payloadStr);
|
||||||
loadScenario();
|
loadScenario();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,12 @@ String selectToMarker(String str, String found) {
|
|||||||
return str.substring(0, p);
|
return str.substring(0, p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String extractInner(String str) {
|
||||||
|
int p1 = str.indexOf("[");
|
||||||
|
int p2 = str.indexOf("]");
|
||||||
|
return str.substring(p1 + 1, p2);
|
||||||
|
}
|
||||||
|
|
||||||
String deleteAfterDelimiter(String str, String found) {
|
String deleteAfterDelimiter(String str, String found) {
|
||||||
int p = str.indexOf(found);
|
int p = str.indexOf(found);
|
||||||
return str.substring(0, p);
|
return str.substring(0, p);
|
||||||
|
|||||||
@@ -13,17 +13,17 @@ bool loadWidget(const String& filename, String& buf) {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
void createWidget(String widget, String page, String pageNumber, String filename, String topic) {
|
void createWidget(String descr, String page, String order, String filename, String topic) {
|
||||||
String buf = "{}";
|
String buf = "{}";
|
||||||
if (!loadWidget(filename, buf)) {
|
if (!loadWidget(filename, buf)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
widget.replace("#", " ");
|
descr.replace("#", " ");
|
||||||
page.replace("#", " ");
|
page.replace("#", " ");
|
||||||
|
|
||||||
jsonWriteStr(buf, "page", page);
|
jsonWriteStr(buf, "page", page);
|
||||||
jsonWriteStr(buf, "order", pageNumber);
|
jsonWriteStr(buf, "order", order);
|
||||||
jsonWriteStr(buf, "descr", widget);
|
jsonWriteStr(buf, "descr", descr);
|
||||||
jsonWriteStr(buf, "topic", prex + "/" + topic);
|
jsonWriteStr(buf, "topic", prex + "/" + topic);
|
||||||
|
|
||||||
#ifdef LAYOUT_IN_RAM
|
#ifdef LAYOUT_IN_RAM
|
||||||
|
|||||||
Reference in New Issue
Block a user