mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-06-10 11:59:19 +03:00
Merge pull request #325 from IoTManagerProject/ver4dev
последние изменения
This commit is contained in:
@@ -20,4 +20,5 @@ void periodicWsSend();
|
||||
void sendFileToWsByFrames(const String& filename, const String& header, const String& json, int client_id, size_t frameSize);
|
||||
void sendStringToWs(const String& header, String& payload, int client_id);
|
||||
|
||||
void sendDeviceList(uint8_t num);
|
||||
void sendDeviceList(uint8_t num);
|
||||
int getNumWSClients();
|
||||
@@ -11,7 +11,7 @@ struct IoTValue {
|
||||
class IoTItem {
|
||||
public:
|
||||
IoTItem(const String& parameters);
|
||||
virtual ~IoTItem() {}
|
||||
virtual ~IoTItem() {};
|
||||
virtual void loop();
|
||||
virtual void doByInterval();
|
||||
virtual IoTValue execute(String command, std::vector<IoTValue>& param);
|
||||
@@ -35,9 +35,12 @@ class IoTItem {
|
||||
void setInterval(long interval);
|
||||
void setIntFromNet(int interval);
|
||||
|
||||
unsigned long currentMillis;
|
||||
unsigned long prevMillis;
|
||||
unsigned long difference;
|
||||
// unsigned long currentMillis;
|
||||
// unsigned long prevMillis;
|
||||
// unsigned long difference;
|
||||
unsigned long nextMillis=0; // достаточно 1 переменной, надо экономить память
|
||||
// задержка следующего вызова, не изменяет текущий _interval
|
||||
void suspendNextDoByInt(unsigned long _delay); // 0 - force
|
||||
|
||||
IoTValue value; // хранение основного значения, которое обновляется из сценария, execute(), loop() или doByInterval()
|
||||
|
||||
@@ -60,6 +63,7 @@ class IoTItem {
|
||||
virtual void onMqttRecive(String& topic, String& msg);
|
||||
virtual void onMqttWsAppConnectEvent();
|
||||
virtual void onModuleOrder(String& key, String& value);
|
||||
virtual void onTrackingValue(IoTItem* item); // момент, когда ядро заметило изменение отслеживаемого значения
|
||||
|
||||
// делаем доступным модулям отправку сообщений в телеграм
|
||||
virtual void sendTelegramMsg(bool often, String msg);
|
||||
@@ -71,6 +75,8 @@ class IoTItem {
|
||||
virtual void clearHistory();
|
||||
virtual void setTodayDate();
|
||||
|
||||
bool isTracking(IoTItem* item); // проверка на отслеживание
|
||||
|
||||
protected:
|
||||
bool _needSave = false; // признак необходимости сохранять и загружать значение элемента на flash
|
||||
String _subtype = "";
|
||||
@@ -90,6 +96,8 @@ class IoTItem {
|
||||
int _numDigits = 1; // количество целых значений, не значимые позиции заменяются нулем в строковом формате
|
||||
|
||||
bool _global = false; // характеристика айтема, что ему нужно слать и принимать события из внешнего мира
|
||||
|
||||
IoTValue* _trackingValue = nullptr; // указатель на значение родительского элемента изменение которого отслеживается
|
||||
};
|
||||
|
||||
IoTItem* findIoTItem(const String& name); // поиск экземпляра элемента модуля по имени
|
||||
|
||||
@@ -2,9 +2,8 @@
|
||||
|
||||
#include "Global.h"
|
||||
#include "MqttClient.h"
|
||||
#include <vector>
|
||||
// boolean isNetworkActive();
|
||||
inline boolean isNetworkActive() {return WiFi.status() == WL_CONNECTED;};
|
||||
boolean isNetworkActive();
|
||||
uint8_t getNumAPClients();
|
||||
void routerConnect();
|
||||
bool startAPMode();
|
||||
boolean RouterFind(std::vector<String> jArray);
|
||||
|
||||
@@ -51,16 +51,21 @@ void handleEvent() {
|
||||
if (eventBuf.length()) {
|
||||
String event = selectToMarker(eventBuf, ",");
|
||||
SerialPrint("i", F("EVENT"), event);
|
||||
String enentIdName = selectToMarker(event, " ");
|
||||
String eventIdName = selectToMarker(event, " ");
|
||||
IoTItem* eventIoTItem = findIoTItem(eventIdName);
|
||||
|
||||
if (eventIoTItem)
|
||||
// распространяем событие через хуки
|
||||
for (std::list<IoTItem*>::iterator it = IoTItems.begin(); it != IoTItems.end(); ++it) {
|
||||
(*it)->onRegEvent(eventIoTItem); // прямой хук
|
||||
|
||||
// распространяем событие через хуки
|
||||
for (std::list<IoTItem*>::iterator it = IoTItems.begin(); it != IoTItems.end(); ++it) {
|
||||
(*it)->onRegEvent(findIoTItem(enentIdName));
|
||||
}
|
||||
// вызов хука при условии отслеживания изменения
|
||||
if ((*it)->isTracking(eventIoTItem)) (*it)->onTrackingValue(eventIoTItem);
|
||||
}
|
||||
|
||||
//здесь нужно пропускать данное событие через условия сценариев
|
||||
//и если оно есть в условии сценария и совподает
|
||||
iotScen.exec(enentIdName);
|
||||
//и если оно есть в условии сценария и совпадает
|
||||
iotScen.exec(eventIdName);
|
||||
|
||||
eventBuf = deleteBeforeDelimiter(eventBuf, ",");
|
||||
}
|
||||
|
||||
@@ -10,8 +10,8 @@
|
||||
IoTScenario iotScen; // объект управления сценарием
|
||||
|
||||
String volStrForSave = "";
|
||||
unsigned long currentMillis;
|
||||
unsigned long prevMillis;
|
||||
// unsigned long currentMillis; // это сдесь лишнее
|
||||
// unsigned long prevMillis;
|
||||
|
||||
void elementsLoop() {
|
||||
// передаем управление каждому элементу конфигурации для выполнения своих функций
|
||||
|
||||
@@ -5,7 +5,7 @@ void mqttInit() {
|
||||
ts.add(
|
||||
WIFI_MQTT_CONNECTION_CHECK, MQTT_RECONNECT_INTERVAL,
|
||||
[&](void*) {
|
||||
if (WiFi.status() == WL_CONNECTED) {
|
||||
if (isNetworkActive()) {
|
||||
SerialPrint("i", F("WIFI"), "http://" + jsonReadStr(settingsFlashJson, F("ip")));
|
||||
wifiUptimeCalc();
|
||||
if (mqtt.connected()) {
|
||||
@@ -121,13 +121,16 @@ void mqttSubscribe() {
|
||||
}
|
||||
|
||||
void mqttSubscribeExternal(String topic, bool usePrefix) {
|
||||
SerialPrint("i", F("MQTT"), ("subscribed external" + topic).c_str());
|
||||
|
||||
// SerialPrint("i", F("MQTT"), mqttRootDevice);
|
||||
String _sb_topic = topic;
|
||||
if (usePrefix)
|
||||
{
|
||||
mqtt.subscribe((mqttPrefix + topic).c_str());
|
||||
_sb_topic = mqttPrefix + "/" + topic;
|
||||
}
|
||||
mqtt.subscribe(topic.c_str());
|
||||
mqtt.subscribe(_sb_topic.c_str());
|
||||
|
||||
SerialPrint("i", F("MQTT"), ("subscribed external " + _sb_topic).c_str());
|
||||
}
|
||||
|
||||
void mqttCallback(char* topic, uint8_t* payload, size_t length) {
|
||||
|
||||
@@ -450,25 +450,27 @@ void sendFileToWsByFrames(const String& filename, const String& header,
|
||||
}
|
||||
|
||||
void sendStringToWs(const String& header, String& payload, int client_id) {
|
||||
if (!(WiFi.softAPgetStationNum() || isNetworkActive())) {
|
||||
return;
|
||||
}
|
||||
if ((!getNumAPClients() && !isNetworkActive()) || !getNumWSClients()) {
|
||||
// standWebSocket.disconnect(); // это и ниже надо сделать при -
|
||||
// standWebSocket.close(); // - отключении AP И WiFi(STA), надо менять ядро WiFi. Сейчас не закрывается сессия клиента при пропаже AP И WiFi(STA)
|
||||
return;
|
||||
}
|
||||
|
||||
if (header.length() != 6) {
|
||||
SerialPrint("E", "FS", F("wrong header size"));
|
||||
return;
|
||||
}
|
||||
if (header.length() != 6) {
|
||||
SerialPrint("E", "FS", F("wrong header size"));
|
||||
return;
|
||||
}
|
||||
|
||||
String msg = header + "|0012|" + payload;
|
||||
size_t totalSize = msg.length();
|
||||
String msg = header + "|0012|" + payload;
|
||||
size_t totalSize = msg.length();
|
||||
|
||||
char dataArray[totalSize];
|
||||
msg.toCharArray(dataArray, totalSize + 1);
|
||||
if (client_id == -1) {
|
||||
standWebSocket.broadcastBIN((uint8_t*)dataArray, totalSize);
|
||||
} else {
|
||||
standWebSocket.sendBIN(client_id, (uint8_t*)dataArray, totalSize);
|
||||
}
|
||||
char dataArray[totalSize];
|
||||
msg.toCharArray(dataArray, totalSize + 1);
|
||||
if (client_id == -1) {
|
||||
standWebSocket.broadcastBIN((uint8_t*)dataArray, totalSize);
|
||||
} else {
|
||||
standWebSocket.sendBIN(client_id, (uint8_t*)dataArray, totalSize);
|
||||
}
|
||||
}
|
||||
|
||||
void sendDeviceList(uint8_t num) {
|
||||
@@ -483,3 +485,7 @@ void sendDeviceList(uint8_t num) {
|
||||
SerialPrint("i", "FS", "flash list");
|
||||
}
|
||||
}
|
||||
|
||||
int getNumWSClients() {
|
||||
return standWebSocket.connectedClients(false);
|
||||
}
|
||||
@@ -7,9 +7,7 @@
|
||||
|
||||
IoTItem::IoTItem(const String& parameters) {
|
||||
jsonRead(parameters, F("int"), _interval, false);
|
||||
if (_interval == 0) enableDoByInt = false; // выключаем использование периодического выполнения в модуле
|
||||
if (_interval > 0) _interval = _interval * 1000; // если int положителен, то считаем, что получены секунды
|
||||
if (_interval < 0) _interval = _interval * -1; // если int отрицательный, то миллисекунды
|
||||
setInterval(_interval);
|
||||
jsonRead(parameters, F("subtype"), _subtype, false);
|
||||
jsonRead(parameters, F("id"), _id);
|
||||
if (!jsonRead(parameters, F("multiply"), _multiply, false)) _multiply = 1;
|
||||
@@ -36,14 +34,25 @@ IoTItem::IoTItem(const String& parameters) {
|
||||
jsonRead(parameters, F("needSave"), _needSave, false);
|
||||
if (_needSave && jsonRead(valuesFlashJson, _id, valAsStr, false)) // пробуем достать из сохранения значение элемента, если указано, что нужно сохранять
|
||||
setValue(valAsStr, false);
|
||||
|
||||
// проверяем нужно ли отслеживать значение другого элемента
|
||||
String trackingID = "";
|
||||
IoTItem* item = nullptr;
|
||||
if (jsonRead(parameters, F("trackingID"), trackingID, false) && (item = findIoTItem(trackingID)) != nullptr) {
|
||||
_trackingValue = &(item->value);
|
||||
}
|
||||
}
|
||||
|
||||
void IoTItem::suspendNextDoByInt(unsigned long _delay) { // 0 - force
|
||||
nextMillis = millis() + _delay;
|
||||
}
|
||||
|
||||
void IoTItem::loop() {
|
||||
if (enableDoByInt) {
|
||||
currentMillis = millis();
|
||||
difference = currentMillis - prevMillis;
|
||||
if (difference >= _interval) {
|
||||
prevMillis = millis();
|
||||
unsigned long currentMillis = millis(); // _interval должен быть < 2147483647 мс (24 суток)
|
||||
if (nextMillis - currentMillis > 2147483647UL /*ULONG_MAX/2*/ ) {
|
||||
nextMillis = currentMillis + _interval;
|
||||
// SerialPrint(F("i"), _id, "this->doByInterval");
|
||||
this->doByInterval();
|
||||
}
|
||||
}
|
||||
@@ -181,6 +190,13 @@ void IoTItem::onRegEvent(IoTItem* item) {}
|
||||
void IoTItem::onMqttRecive(String& topic, String& msg) {}
|
||||
void IoTItem::onMqttWsAppConnectEvent() {}
|
||||
void IoTItem::onModuleOrder(String& key, String& value) {}
|
||||
void IoTItem::onTrackingValue(IoTItem* item) {
|
||||
setValue(item->getValue(), false);
|
||||
}
|
||||
|
||||
bool IoTItem::isTracking(IoTItem* item) {
|
||||
return &(item->value) == _trackingValue;
|
||||
}
|
||||
|
||||
// делаем доступным модулям отправку сообщений в телеграм
|
||||
void IoTItem::sendTelegramMsg(bool often, String msg) {}
|
||||
@@ -201,7 +217,13 @@ bool IoTItem::isStrInID(const String& str) {
|
||||
}
|
||||
|
||||
void IoTItem::setInterval(long interval) {
|
||||
_interval = interval;
|
||||
if (interval == 0) enableDoByInt = false; // выключаем использование периодического выполнения в модуле
|
||||
else {
|
||||
enableDoByInt = true;
|
||||
if (interval > 0) _interval = interval * 1000; // если int положителен, то считаем, что получены секунды
|
||||
else if (interval < 0) _interval = interval * -1; // если int отрицательный, то миллисекунды
|
||||
}
|
||||
// SerialPrint(F("i"), F("IoTItem"), "setInterval: " + _interval.toString);
|
||||
}
|
||||
|
||||
IoTGpio* IoTItem::getGpioDriver() {
|
||||
|
||||
@@ -43,13 +43,16 @@ public:
|
||||
#if defined ESP8266
|
||||
if (!http.begin(_host, 80, _url))
|
||||
{
|
||||
#elif defined ESP32
|
||||
if (!http.begin(String("http://") + _host + _url))
|
||||
{
|
||||
#endif
|
||||
// Serial.println("connection failed");
|
||||
SerialPrint("I", F("NextionUpdate"), "connection failed ");
|
||||
}
|
||||
#elif defined ESP32
|
||||
if (!http.begin(String("http://") + _host + _url))
|
||||
{
|
||||
// Serial.println("connection failed");
|
||||
SerialPrint("I", F("NextionUpdate"), "connection failed ");
|
||||
}
|
||||
#endif
|
||||
|
||||
SerialPrint("I", F("NextionUpdate"), "Requesting file: " + (String)_url);
|
||||
int code = http.GET();
|
||||
|
||||
@@ -3,24 +3,28 @@
|
||||
|
||||
extern IoTGpio IoTgpio;
|
||||
|
||||
|
||||
class ButtonOut : public IoTItem {
|
||||
private:
|
||||
int _pin, _inv;
|
||||
int _pin;
|
||||
bool _inv;
|
||||
|
||||
public:
|
||||
ButtonOut(String parameters): IoTItem(parameters) {
|
||||
jsonRead(parameters, "pin", _pin);
|
||||
jsonRead(parameters, "inv", _inv);
|
||||
_round = 0;
|
||||
|
||||
IoTgpio.pinMode(_pin, OUTPUT);
|
||||
IoTgpio.digitalWrite(_pin, _inv?!value.valD:value.valD);
|
||||
enableDoByInt = false;
|
||||
}
|
||||
|
||||
void doByInterval() {
|
||||
//value.valD = IoTgpio.analogRead(_pin);
|
||||
|
||||
int val = _inv?1:0;
|
||||
IoTgpio.digitalWrite(_pin, val);
|
||||
// SerialPrint("I", "ButtonOut","single pulse end");
|
||||
value.valD = 0;
|
||||
regEvent(0, "ButtonOut");
|
||||
enableDoByInt = false;
|
||||
//regEvent(value.valD, "ButtonOut"); //обязательный вызов хотяб один
|
||||
}
|
||||
|
||||
@@ -30,24 +34,40 @@ class ButtonOut : public IoTItem {
|
||||
// param - вектор ("массив") значений параметров переданных вместе с командой: ID.Команда("пар1", 22, 33) -> param[0].ValS = "пар1", param[1].ValD = 22
|
||||
|
||||
if (command == "change") {
|
||||
value.valD = 1 - IoTgpio.digitalRead(_pin);
|
||||
IoTgpio.digitalWrite(_pin, value.valD);
|
||||
value.valD = 1 - (int)value.valD;
|
||||
IoTgpio.digitalWrite(_pin, _inv?!value.valD:value.valD);
|
||||
regEvent(value.valD, "ButtonOut");
|
||||
}
|
||||
|
||||
else if (command == "pulse") {
|
||||
if (param[0].isDecimal && (param[0].valD != 0)) {
|
||||
value.valD = !_inv?1:0;
|
||||
enableDoByInt = true;
|
||||
// SerialPrint("I", "ButtonOut","single pulse start");
|
||||
regEvent((String)(int)!_inv?1:0, "ButtonOut");
|
||||
suspendNextDoByInt(param[0].valD);
|
||||
IoTgpio.digitalWrite(_pin, !_inv?1:0);
|
||||
}
|
||||
}
|
||||
return {}; // команда поддерживает возвращаемое значения. Т.е. по итогу выполнения команды или общения с внешней системой, можно вернуть значение в сценарий для дальнейшей обработки
|
||||
}
|
||||
|
||||
void setValue(const IoTValue& Value, bool genEvent = true) {
|
||||
value = Value;
|
||||
IoTgpio.digitalWrite(_pin, _inv?!value.valD:value.valD);
|
||||
if ((value.valD == !_inv?1:0) && (_interval != 0)) {
|
||||
value.valD = !_inv?1:0;
|
||||
enableDoByInt = true;
|
||||
// SerialPrint("I", "ButtonOut","single pulse start");
|
||||
suspendNextDoByInt(_interval);
|
||||
} else {
|
||||
enableDoByInt = false;
|
||||
}
|
||||
regEvent((String)(int)value.valD, "ButtonOut", false, genEvent);
|
||||
IoTgpio.digitalWrite(_pin, _inv?!value.valD:value.valD);
|
||||
}
|
||||
|
||||
String getValue() {
|
||||
return (String)(int)value.valD;
|
||||
}
|
||||
//=======================================================================================================
|
||||
|
||||
~ButtonOut() {};
|
||||
};
|
||||
|
||||
@@ -39,6 +39,11 @@
|
||||
"name": "change",
|
||||
"descr": "Инвертирует значение переключателя",
|
||||
"params": []
|
||||
},
|
||||
{
|
||||
"name": "pulse",
|
||||
"descr": "Генерирует одиночный импульс",
|
||||
"params": ["Длительность (ms)"]
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
@@ -79,16 +79,7 @@ public:
|
||||
|
||||
case 1:
|
||||
// for doByIntervals
|
||||
if (enableDoByInt)
|
||||
{
|
||||
currentMillis = millis();
|
||||
difference = currentMillis - prevMillis;
|
||||
if (difference >= _interval)
|
||||
{
|
||||
prevMillis = millis();
|
||||
this->doByInterval();
|
||||
}
|
||||
}
|
||||
IoTItem::loop();
|
||||
break;
|
||||
|
||||
case 2:
|
||||
|
||||
@@ -10,7 +10,7 @@ public:
|
||||
|
||||
void sendHttpPOST(String url, String msg)
|
||||
{
|
||||
if (WiFi.status() == WL_CONNECTED)
|
||||
if (isNetworkActive())
|
||||
{
|
||||
|
||||
WiFiClient client;
|
||||
|
||||
@@ -3,6 +3,11 @@
|
||||
#include "Arduino.h"
|
||||
#include "MySensorsGate.h"
|
||||
|
||||
// временное решение
|
||||
unsigned long currentMillis;
|
||||
unsigned long prevMillis;
|
||||
unsigned long difference;
|
||||
|
||||
#ifdef MYSENSORS
|
||||
// callback библиотеки mysensors
|
||||
void receive(const MyMessage& message) {
|
||||
|
||||
@@ -13,7 +13,7 @@ class TelegramLT : public IoTItem {
|
||||
}
|
||||
|
||||
void sendTelegramMsg(bool often, String msg) {
|
||||
if (WiFi.status() == WL_CONNECTED && (often || !often && _prevMsg != msg)) {
|
||||
if (isNetworkActive() && (often || !often && _prevMsg != msg)) {
|
||||
WiFiClient client;
|
||||
HTTPClient http;
|
||||
http.begin(client, "http://live-control.com/iotm/telegram.php");
|
||||
|
||||
@@ -246,6 +246,11 @@ protected:
|
||||
pv_last = pv;
|
||||
}
|
||||
|
||||
// временное решение
|
||||
unsigned long currentMillis;
|
||||
unsigned long prevMillis;
|
||||
unsigned long difference;
|
||||
|
||||
void loop()
|
||||
{
|
||||
if (enableDoByInt)
|
||||
|
||||
@@ -64,13 +64,7 @@ class AnalogAdc : public IoTItem {
|
||||
_avgSumm = _avgSumm + IoTgpio.analogRead(_pin);
|
||||
_avgCount++;
|
||||
}
|
||||
|
||||
currentMillis = millis();
|
||||
difference = currentMillis - prevMillis;
|
||||
if (difference >= _interval) {
|
||||
prevMillis = millis();
|
||||
this->doByInterval();
|
||||
}
|
||||
IoTItem::loop();
|
||||
}
|
||||
|
||||
~AnalogAdc(){};
|
||||
|
||||
@@ -107,13 +107,7 @@ public:
|
||||
adc = IoTgpio.analogRead(_pin);
|
||||
|
||||
// Блок вызова doByInterval, так как если определили loop, то сам он не вызовится
|
||||
currentMillis = millis();
|
||||
difference = currentMillis - prevMillis;
|
||||
if (difference >= _interval)
|
||||
{
|
||||
prevMillis = millis();
|
||||
this->doByInterval();
|
||||
}
|
||||
IoTItem::loop();
|
||||
}
|
||||
|
||||
~ExampleModule_A()
|
||||
|
||||
@@ -17,6 +17,7 @@ private:
|
||||
bool _isJson;
|
||||
bool _addPrefix;
|
||||
bool _debug;
|
||||
bool sendOk = false;
|
||||
|
||||
public:
|
||||
ExternalMQTT(String parameters) : IoTItem(parameters)
|
||||
@@ -26,10 +27,12 @@ public:
|
||||
jsonRead(parameters, F("red"), red);
|
||||
jsonRead(parameters, F("offline"), offline);
|
||||
_topic = jsonReadStr(parameters, "topic");
|
||||
_isJson = jsonReadBool(parameters, "isJson");
|
||||
_addPrefix = jsonReadBool(parameters, "addPrefix");
|
||||
_debug = jsonReadBool(parameters, "debug");
|
||||
jsonRead(parameters, "isJson", _isJson);
|
||||
jsonRead(parameters, "addPrefix", _addPrefix);
|
||||
jsonRead(parameters, "debug", _debug);
|
||||
dataFromNode = false;
|
||||
if (mqttIsConnect())
|
||||
sendOk = true;
|
||||
mqttSubscribeExternal(_topic, _addPrefix);
|
||||
}
|
||||
char *TimeToString(unsigned long t)
|
||||
@@ -58,6 +61,7 @@ public:
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (_isJson)
|
||||
{
|
||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||
@@ -106,6 +110,11 @@ public:
|
||||
{
|
||||
_minutesPassed++;
|
||||
setNewWidgetAttributes();
|
||||
if (mqttIsConnect() && !sendOk)
|
||||
{
|
||||
sendOk = true;
|
||||
mqttSubscribeExternal(_topic, _addPrefix);
|
||||
}
|
||||
}
|
||||
void onMqttWsAppConnectEvent()
|
||||
{
|
||||
|
||||
@@ -157,16 +157,17 @@ public:
|
||||
void loop()
|
||||
{
|
||||
ts_sds.update();
|
||||
if (enableDoByInt)
|
||||
{
|
||||
currentMillis = millis();
|
||||
difference = currentMillis - prevMillis;
|
||||
if (difference >= _interval)
|
||||
{
|
||||
prevMillis = millis();
|
||||
this->doByInterval();
|
||||
}
|
||||
}
|
||||
IoTItem::loop();
|
||||
// if (enableDoByInt)
|
||||
// {
|
||||
// currentMillis = millis();
|
||||
// difference = currentMillis - prevMillis;
|
||||
// if (difference >= _interval)
|
||||
// {
|
||||
// prevMillis = millis();
|
||||
// this->doByInterval();
|
||||
// }
|
||||
// }
|
||||
}
|
||||
//=======================================================================================================
|
||||
// doByInterval()
|
||||
|
||||
@@ -10,7 +10,7 @@ private:
|
||||
String scid = "";
|
||||
String shname = "";
|
||||
// bool init = false;
|
||||
int interval = 1;
|
||||
// int interval = 1;
|
||||
// long interval;
|
||||
String URL = ("http://iotmanager.org/projects/google.php?/macros/s/"); // F("https://script.google.com/macros/s/");
|
||||
String urlFinal;
|
||||
@@ -24,14 +24,17 @@ public:
|
||||
jsonRead(parameters, F("logid"), logid);
|
||||
jsonRead(parameters, F("scid"), scid);
|
||||
jsonRead(parameters, F("shname"), shname);
|
||||
jsonRead(parameters, F("int"), interval);
|
||||
interval = interval * 1000 * 60; // так как у нас в минутах
|
||||
// jsonRead(parameters, F("int"), interval);
|
||||
long interval;
|
||||
jsonRead(parameters, F("int"), interval); // в минутах
|
||||
setInterval(interval * 60);
|
||||
// interval = interval * 1000 * 60; // так как у нас в минутах
|
||||
urlFinal = URL + scid + F("/exec?") + F("sheet=") + shname;
|
||||
}
|
||||
|
||||
void doByInterval()
|
||||
{
|
||||
if (WiFi.status() == WL_CONNECTED)
|
||||
if (isNetworkActive())
|
||||
{
|
||||
String value = getItemValue(logid);
|
||||
if (value != "")
|
||||
@@ -39,23 +42,23 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
if (enableDoByInt)
|
||||
{
|
||||
currentMillis = millis();
|
||||
difference = currentMillis - prevMillis;
|
||||
if (difference >= interval)
|
||||
{
|
||||
prevMillis = millis();
|
||||
this->doByInterval();
|
||||
}
|
||||
}
|
||||
}
|
||||
// void loop()
|
||||
// {
|
||||
// if (enableDoByInt)
|
||||
// {
|
||||
// currentMillis = millis();
|
||||
// difference = currentMillis - prevMillis;
|
||||
// if (difference >= interval)
|
||||
// {
|
||||
// prevMillis = millis();
|
||||
// this->doByInterval();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
IoTValue execute(String command, std::vector<IoTValue> ¶m)
|
||||
{
|
||||
if (WiFi.status() == WL_CONNECTED)
|
||||
if (isNetworkActive())
|
||||
{
|
||||
if (command == F("logGoogle"))
|
||||
{ // Логирование определенного элемента по его идентификатору в GoogleSheet
|
||||
|
||||
@@ -23,7 +23,7 @@ class Loging : public IoTItem {
|
||||
String prevDate = "";
|
||||
bool firstTimeInit = true;
|
||||
|
||||
long interval;
|
||||
// long interval;
|
||||
|
||||
public:
|
||||
Loging(String parameters) : IoTItem(parameters) {
|
||||
@@ -34,8 +34,9 @@ class Loging : public IoTItem {
|
||||
points = 300;
|
||||
SerialPrint("E", F("Loging"), "'" + id + "' user set more points than allowed, value reset to 300");
|
||||
}
|
||||
jsonRead(parameters, F("int"), interval);
|
||||
interval = interval * 1000 * 60; // приводим к милисекундам
|
||||
long interval;
|
||||
jsonRead(parameters, F("int"), interval); // в минутах
|
||||
setInterval(interval * 60);
|
||||
//jsonRead(parameters, F("keepdays"), keepdays, false);
|
||||
|
||||
// создадим экземпляр класса даты
|
||||
@@ -303,18 +304,18 @@ class Loging : public IoTItem {
|
||||
return "";
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if (enableDoByInt) {
|
||||
currentMillis = millis();
|
||||
difference = currentMillis - prevMillis;
|
||||
if (difference >= interval) {
|
||||
prevMillis = millis();
|
||||
if (interval != 0) {
|
||||
this->doByInterval();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// void loop() {
|
||||
// if (enableDoByInt) {
|
||||
// currentMillis = millis();
|
||||
// difference = currentMillis - prevMillis;
|
||||
// if (difference >= interval) {
|
||||
// prevMillis = millis();
|
||||
// if (interval != 0) {
|
||||
// this->doByInterval();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
void regEvent(const String &value, const String &consoleInfo, bool error = false, bool genEvent = true) {
|
||||
String userDate = getItemValue(id + "-date");
|
||||
|
||||
@@ -25,7 +25,7 @@ class LogingDaily : public IoTItem {
|
||||
String prevDate = "";
|
||||
bool firstTimeInit = true;
|
||||
|
||||
long interval;
|
||||
// long interval;
|
||||
|
||||
public:
|
||||
LogingDaily(String parameters) : IoTItem(parameters) {
|
||||
@@ -40,8 +40,9 @@ class LogingDaily : public IoTItem {
|
||||
points = 365;
|
||||
SerialPrint("E", F("LogingDaily"), "'" + id + "' user set more points than allowed, value reset to 365");
|
||||
}
|
||||
jsonRead(parameters, F("int"), interval);
|
||||
interval = interval * 1000 * 60; // приводим к милисекундам
|
||||
long interval;
|
||||
jsonRead(parameters, F("int"), interval); // в минутах
|
||||
setInterval(interval * 60);
|
||||
}
|
||||
|
||||
void doByInterval() {
|
||||
@@ -225,16 +226,16 @@ class LogingDaily : public IoTItem {
|
||||
return "";
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if (enableDoByInt) {
|
||||
currentMillis = millis();
|
||||
difference = currentMillis - prevMillis;
|
||||
if (difference >= interval) {
|
||||
prevMillis = millis();
|
||||
this->doByInterval();
|
||||
}
|
||||
}
|
||||
}
|
||||
// void loop() {
|
||||
// if (enableDoByInt) {
|
||||
// currentMillis = millis();
|
||||
// difference = currentMillis - prevMillis;
|
||||
// if (difference >= interval) {
|
||||
// prevMillis = millis();
|
||||
// this->doByInterval();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// просто максимальное количество точек
|
||||
int calculateMaxCount() {
|
||||
|
||||
@@ -11,22 +11,23 @@ class Weather : public IoTItem
|
||||
private:
|
||||
String _location;
|
||||
String _param;
|
||||
long interval;
|
||||
// long interval;
|
||||
|
||||
public:
|
||||
Weather(String parameters) : IoTItem(parameters)
|
||||
{
|
||||
_location = jsonReadStr(parameters, "location");
|
||||
_param = jsonReadStr(parameters, "param");
|
||||
jsonRead(parameters, F("int"), interval);
|
||||
interval = interval * 1000 * 60 * 60; // интервал проверки погоды в часах
|
||||
long interval;
|
||||
jsonRead(parameters, F("int"), interval); // интервал проверки погоды в часах
|
||||
setInterval(interval * 60 * 60);
|
||||
}
|
||||
|
||||
void getWeather()
|
||||
{
|
||||
String ret;
|
||||
|
||||
if (WiFi.status() == WL_CONNECTED)
|
||||
if (isNetworkActive())
|
||||
{
|
||||
// char c;
|
||||
String payload;
|
||||
@@ -113,19 +114,21 @@ public:
|
||||
regEvent(value.valS, "Weather");
|
||||
}
|
||||
}
|
||||
void loop()
|
||||
{
|
||||
if (enableDoByInt)
|
||||
{
|
||||
currentMillis = millis();
|
||||
difference = currentMillis - prevMillis;
|
||||
if (difference >= interval)
|
||||
{
|
||||
prevMillis = millis();
|
||||
this->doByInterval();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// void loop()
|
||||
// {
|
||||
// if (enableDoByInt)
|
||||
// {
|
||||
// currentMillis = millis();
|
||||
// difference = currentMillis - prevMillis;
|
||||
// if (difference >= interval)
|
||||
// {
|
||||
// prevMillis = millis();
|
||||
// this->doByInterval();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
IoTValue execute(String command, std::vector<IoTValue> ¶m)
|
||||
{
|
||||
if (command == "get")
|
||||
|
||||
@@ -11,11 +11,11 @@ void SerialPrint(const String& errorLevel, const String& module, const String& m
|
||||
tosend += msg;
|
||||
Serial.println(tosend);
|
||||
|
||||
if (isNetworkActive()) {
|
||||
if (jsonReadInt(settingsFlashJson, F("log")) != 0) {
|
||||
sendStringToWs(F("corelg"), tosend, -1);
|
||||
}
|
||||
// if (isNetworkActive()) { // все проверки происходят в sendStringToWs()
|
||||
if (jsonReadInt(settingsFlashJson, F("log")) != 0) {
|
||||
sendStringToWs(F("corelg"), tosend, -1);
|
||||
}
|
||||
// }
|
||||
|
||||
if (errorLevel == "E") {
|
||||
cleanString(tosend);
|
||||
|
||||
@@ -20,7 +20,7 @@ void updateDeviceStatus() {
|
||||
// jsonRead(settingsFlashJson, F("serverip"), serverIP);
|
||||
String url = serverIP + F("/projects/esprebootstat.php");
|
||||
// SerialPrint("i", "Stat", "url " + url);
|
||||
if ((WiFi.status() == WL_CONNECTED)) {
|
||||
if ((isNetworkActive())) {
|
||||
WiFiClient client;
|
||||
HTTPClient http;
|
||||
http.begin(client, url);
|
||||
|
||||
@@ -171,40 +171,31 @@ boolean RouterFind(std::vector<String> jArray)
|
||||
return res;
|
||||
}
|
||||
|
||||
// boolean isNetworkActive() {
|
||||
// return WiFi.status() == WL_CONNECTED;
|
||||
// }
|
||||
|
||||
uint8_t RSSIquality()
|
||||
{
|
||||
uint8_t res = 0;
|
||||
if (WiFi.status() == WL_CONNECTED)
|
||||
{
|
||||
int rssi = WiFi.RSSI();
|
||||
if (rssi >= -50)
|
||||
{
|
||||
res = 6; //"Excellent";
|
||||
}
|
||||
else if (rssi < -50 && rssi >= -60)
|
||||
{
|
||||
res = 5; //"Very good";
|
||||
}
|
||||
else if (rssi < -60 && rssi >= -70)
|
||||
{
|
||||
res = 4; //"Good";
|
||||
}
|
||||
else if (rssi < -70 && rssi >= -80)
|
||||
{
|
||||
res = 3; //"Low";
|
||||
}
|
||||
else if (rssi < -80 && rssi > -100)
|
||||
{
|
||||
res = 2; //"Very low";
|
||||
}
|
||||
else if (rssi <= -100)
|
||||
{
|
||||
res = 1; //"No signal";
|
||||
}
|
||||
}
|
||||
return res;
|
||||
boolean isNetworkActive() {
|
||||
return WiFi.status() == WL_CONNECTED;
|
||||
}
|
||||
|
||||
uint8_t getNumAPClients() {
|
||||
return WiFi.softAPgetStationNum();
|
||||
}
|
||||
|
||||
uint8_t RSSIquality() {
|
||||
uint8_t res = 0;
|
||||
if (isNetworkActive()) {
|
||||
int rssi = WiFi.RSSI();
|
||||
if (rssi >= -50) {
|
||||
res = 6; //"Excellent";
|
||||
} else if (rssi < -50 && rssi >= -60) {
|
||||
res = 5; //"Very good";
|
||||
} else if (rssi < -60 && rssi >= -70) {
|
||||
res = 4; //"Good";
|
||||
} else if (rssi < -70 && rssi >= -80) {
|
||||
res = 3; //"Low";
|
||||
} else if (rssi < -80 && rssi > -100) {
|
||||
res = 2; //"Very low";
|
||||
} else if (rssi <= -100) {
|
||||
res = 1; //"No signal";
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user