mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-30 11:59:12 +03:00
pulse() в ButtonOut, +прочие корректировки
This commit is contained in:
@@ -11,7 +11,7 @@ struct IoTValue {
|
|||||||
class IoTItem {
|
class IoTItem {
|
||||||
public:
|
public:
|
||||||
IoTItem(const String& parameters);
|
IoTItem(const String& parameters);
|
||||||
virtual ~IoTItem() {}
|
virtual ~IoTItem() {};
|
||||||
virtual void loop();
|
virtual void loop();
|
||||||
virtual void doByInterval();
|
virtual void doByInterval();
|
||||||
virtual IoTValue execute(String command, std::vector<IoTValue>& param);
|
virtual IoTValue execute(String command, std::vector<IoTValue>& param);
|
||||||
@@ -35,9 +35,12 @@ class IoTItem {
|
|||||||
void setInterval(long interval);
|
void setInterval(long interval);
|
||||||
void setIntFromNet(int interval);
|
void setIntFromNet(int interval);
|
||||||
|
|
||||||
unsigned long currentMillis;
|
// unsigned long currentMillis;
|
||||||
unsigned long prevMillis;
|
// unsigned long prevMillis;
|
||||||
unsigned long difference;
|
// unsigned long difference;
|
||||||
|
unsigned long nextMillis=0; // достаточно 1 переменной, надо экономить память
|
||||||
|
// задержка следующего вызова, не изменяет текущий _interval
|
||||||
|
void suspendNextDoByInt(unsigned long _delay); // 0 - force
|
||||||
|
|
||||||
IoTValue value; // хранение основного значения, которое обновляется из сценария, execute(), loop() или doByInterval()
|
IoTValue value; // хранение основного значения, которое обновляется из сценария, execute(), loop() или doByInterval()
|
||||||
|
|
||||||
|
|||||||
@@ -10,8 +10,8 @@
|
|||||||
IoTScenario iotScen; // объект управления сценарием
|
IoTScenario iotScen; // объект управления сценарием
|
||||||
|
|
||||||
String volStrForSave = "";
|
String volStrForSave = "";
|
||||||
unsigned long currentMillis;
|
// unsigned long currentMillis; // это сдесь лишнее
|
||||||
unsigned long prevMillis;
|
// unsigned long prevMillis;
|
||||||
|
|
||||||
void elementsLoop() {
|
void elementsLoop() {
|
||||||
// передаем управление каждому элементу конфигурации для выполнения своих функций
|
// передаем управление каждому элементу конфигурации для выполнения своих функций
|
||||||
|
|||||||
@@ -7,9 +7,7 @@
|
|||||||
|
|
||||||
IoTItem::IoTItem(const String& parameters) {
|
IoTItem::IoTItem(const String& parameters) {
|
||||||
jsonRead(parameters, F("int"), _interval, false);
|
jsonRead(parameters, F("int"), _interval, false);
|
||||||
if (_interval == 0) enableDoByInt = false; // выключаем использование периодического выполнения в модуле
|
setInterval(_interval);
|
||||||
if (_interval > 0) _interval = _interval * 1000; // если int положителен, то считаем, что получены секунды
|
|
||||||
if (_interval < 0) _interval = _interval * -1; // если int отрицательный, то миллисекунды
|
|
||||||
jsonRead(parameters, F("subtype"), _subtype, false);
|
jsonRead(parameters, F("subtype"), _subtype, false);
|
||||||
jsonRead(parameters, F("id"), _id);
|
jsonRead(parameters, F("id"), _id);
|
||||||
if (!jsonRead(parameters, F("multiply"), _multiply, false)) _multiply = 1;
|
if (!jsonRead(parameters, F("multiply"), _multiply, false)) _multiply = 1;
|
||||||
@@ -38,12 +36,16 @@ IoTItem::IoTItem(const String& parameters) {
|
|||||||
setValue(valAsStr, false);
|
setValue(valAsStr, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void IoTItem::suspendNextDoByInt(unsigned long _delay) { // 0 - force
|
||||||
|
nextMillis = millis() + _delay;
|
||||||
|
}
|
||||||
|
|
||||||
void IoTItem::loop() {
|
void IoTItem::loop() {
|
||||||
if (enableDoByInt) {
|
if (enableDoByInt) {
|
||||||
currentMillis = millis();
|
unsigned long currentMillis = millis(); // _interval должен быть < 2147483647 мс (24 суток)
|
||||||
difference = currentMillis - prevMillis;
|
if (nextMillis - currentMillis > 2147483647UL /*ULONG_MAX/2*/ ) {
|
||||||
if (difference >= _interval) {
|
nextMillis = currentMillis + _interval;
|
||||||
prevMillis = millis();
|
// SerialPrint(F("i"), _id, "this->doByInterval");
|
||||||
this->doByInterval();
|
this->doByInterval();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -201,7 +203,13 @@ bool IoTItem::isStrInID(const String& str) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void IoTItem::setInterval(long interval) {
|
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() {
|
IoTGpio* IoTItem::getGpioDriver() {
|
||||||
|
|||||||
@@ -43,13 +43,16 @@ public:
|
|||||||
#if defined ESP8266
|
#if defined ESP8266
|
||||||
if (!http.begin(_host, 80, _url))
|
if (!http.begin(_host, 80, _url))
|
||||||
{
|
{
|
||||||
#elif defined ESP32
|
|
||||||
if (!http.begin(String("http://") + _host + _url))
|
|
||||||
{
|
|
||||||
#endif
|
|
||||||
// Serial.println("connection failed");
|
// Serial.println("connection failed");
|
||||||
SerialPrint("I", F("NextionUpdate"), "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);
|
SerialPrint("I", F("NextionUpdate"), "Requesting file: " + (String)_url);
|
||||||
int code = http.GET();
|
int code = http.GET();
|
||||||
|
|||||||
@@ -3,24 +3,28 @@
|
|||||||
|
|
||||||
extern IoTGpio IoTgpio;
|
extern IoTGpio IoTgpio;
|
||||||
|
|
||||||
|
|
||||||
class ButtonOut : public IoTItem {
|
class ButtonOut : public IoTItem {
|
||||||
private:
|
private:
|
||||||
int _pin, _inv;
|
int _pin;
|
||||||
|
bool _inv;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ButtonOut(String parameters): IoTItem(parameters) {
|
ButtonOut(String parameters): IoTItem(parameters) {
|
||||||
jsonRead(parameters, "pin", _pin);
|
jsonRead(parameters, "pin", _pin);
|
||||||
jsonRead(parameters, "inv", _inv);
|
jsonRead(parameters, "inv", _inv);
|
||||||
_round = 0;
|
_round = 0;
|
||||||
|
|
||||||
IoTgpio.pinMode(_pin, OUTPUT);
|
IoTgpio.pinMode(_pin, OUTPUT);
|
||||||
IoTgpio.digitalWrite(_pin, _inv?!value.valD:value.valD);
|
IoTgpio.digitalWrite(_pin, _inv?!value.valD:value.valD);
|
||||||
|
enableDoByInt = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void doByInterval() {
|
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"); //обязательный вызов хотяб один
|
//regEvent(value.valD, "ButtonOut"); //обязательный вызов хотяб один
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,20 +38,36 @@ class ButtonOut : public IoTItem {
|
|||||||
IoTgpio.digitalWrite(_pin, value.valD);
|
IoTgpio.digitalWrite(_pin, value.valD);
|
||||||
regEvent(value.valD, "ButtonOut");
|
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 {}; // команда поддерживает возвращаемое значения. Т.е. по итогу выполнения команды или общения с внешней системой, можно вернуть значение в сценарий для дальнейшей обработки
|
return {}; // команда поддерживает возвращаемое значения. Т.е. по итогу выполнения команды или общения с внешней системой, можно вернуть значение в сценарий для дальнейшей обработки
|
||||||
}
|
}
|
||||||
|
|
||||||
void setValue(const IoTValue& Value, bool genEvent = true) {
|
void setValue(const IoTValue& Value, bool genEvent = true) {
|
||||||
value = Value;
|
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);
|
regEvent((String)(int)value.valD, "ButtonOut", false, genEvent);
|
||||||
|
IoTgpio.digitalWrite(_pin, _inv?!value.valD:value.valD);
|
||||||
}
|
}
|
||||||
|
|
||||||
String getValue() {
|
String getValue() {
|
||||||
return (String)(int)value.valD;
|
return (String)(int)value.valD;
|
||||||
}
|
}
|
||||||
//=======================================================================================================
|
|
||||||
|
|
||||||
~ButtonOut() {};
|
~ButtonOut() {};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -39,6 +39,11 @@
|
|||||||
"name": "change",
|
"name": "change",
|
||||||
"descr": "Инвертирует значение переключателя",
|
"descr": "Инвертирует значение переключателя",
|
||||||
"params": []
|
"params": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "pulse",
|
||||||
|
"descr": "Генерирует одиночный импульс",
|
||||||
|
"params": ["Длительность (ms)"]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -79,16 +79,7 @@ public:
|
|||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
// for doByIntervals
|
// for doByIntervals
|
||||||
if (enableDoByInt)
|
IoTItem::loop();
|
||||||
{
|
|
||||||
currentMillis = millis();
|
|
||||||
difference = currentMillis - prevMillis;
|
|
||||||
if (difference >= _interval)
|
|
||||||
{
|
|
||||||
prevMillis = millis();
|
|
||||||
this->doByInterval();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
|
|||||||
@@ -3,6 +3,11 @@
|
|||||||
#include "Arduino.h"
|
#include "Arduino.h"
|
||||||
#include "MySensorsGate.h"
|
#include "MySensorsGate.h"
|
||||||
|
|
||||||
|
// временное решение
|
||||||
|
unsigned long currentMillis;
|
||||||
|
unsigned long prevMillis;
|
||||||
|
unsigned long difference;
|
||||||
|
|
||||||
#ifdef MYSENSORS
|
#ifdef MYSENSORS
|
||||||
// callback библиотеки mysensors
|
// callback библиотеки mysensors
|
||||||
void receive(const MyMessage& message) {
|
void receive(const MyMessage& message) {
|
||||||
|
|||||||
@@ -246,6 +246,11 @@ protected:
|
|||||||
pv_last = pv;
|
pv_last = pv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// временное решение
|
||||||
|
unsigned long currentMillis;
|
||||||
|
unsigned long prevMillis;
|
||||||
|
unsigned long difference;
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
if (enableDoByInt)
|
if (enableDoByInt)
|
||||||
|
|||||||
@@ -64,13 +64,7 @@ class AnalogAdc : public IoTItem {
|
|||||||
_avgSumm = _avgSumm + IoTgpio.analogRead(_pin);
|
_avgSumm = _avgSumm + IoTgpio.analogRead(_pin);
|
||||||
_avgCount++;
|
_avgCount++;
|
||||||
}
|
}
|
||||||
|
IoTItem::loop();
|
||||||
currentMillis = millis();
|
|
||||||
difference = currentMillis - prevMillis;
|
|
||||||
if (difference >= _interval) {
|
|
||||||
prevMillis = millis();
|
|
||||||
this->doByInterval();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
~AnalogAdc(){};
|
~AnalogAdc(){};
|
||||||
|
|||||||
@@ -102,13 +102,7 @@ public:
|
|||||||
adc = IoTgpio.analogRead(_pin);
|
adc = IoTgpio.analogRead(_pin);
|
||||||
|
|
||||||
// Блок вызова doByInterval, так как если определили loop, то сам он не вызовится
|
// Блок вызова doByInterval, так как если определили loop, то сам он не вызовится
|
||||||
currentMillis = millis();
|
IoTItem::loop();
|
||||||
difference = currentMillis - prevMillis;
|
|
||||||
if (difference >= _interval)
|
|
||||||
{
|
|
||||||
prevMillis = millis();
|
|
||||||
this->doByInterval();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
~ExampleModule_A(){};
|
~ExampleModule_A(){};
|
||||||
|
|||||||
@@ -157,16 +157,17 @@ public:
|
|||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
ts_sds.update();
|
ts_sds.update();
|
||||||
if (enableDoByInt)
|
IoTItem::loop();
|
||||||
{
|
// if (enableDoByInt)
|
||||||
currentMillis = millis();
|
// {
|
||||||
difference = currentMillis - prevMillis;
|
// currentMillis = millis();
|
||||||
if (difference >= _interval)
|
// difference = currentMillis - prevMillis;
|
||||||
{
|
// if (difference >= _interval)
|
||||||
prevMillis = millis();
|
// {
|
||||||
this->doByInterval();
|
// prevMillis = millis();
|
||||||
}
|
// this->doByInterval();
|
||||||
}
|
// }
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
//=======================================================================================================
|
//=======================================================================================================
|
||||||
// doByInterval()
|
// doByInterval()
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ private:
|
|||||||
String scid = "";
|
String scid = "";
|
||||||
String shname = "";
|
String shname = "";
|
||||||
// bool init = false;
|
// bool init = false;
|
||||||
int interval = 1;
|
// int interval = 1;
|
||||||
// long interval;
|
// long interval;
|
||||||
String URL = ("http://iotmanager.org/projects/google.php?/macros/s/"); // F("https://script.google.com/macros/s/");
|
String URL = ("http://iotmanager.org/projects/google.php?/macros/s/"); // F("https://script.google.com/macros/s/");
|
||||||
String urlFinal;
|
String urlFinal;
|
||||||
@@ -24,8 +24,11 @@ public:
|
|||||||
jsonRead(parameters, F("logid"), logid);
|
jsonRead(parameters, F("logid"), logid);
|
||||||
jsonRead(parameters, F("scid"), scid);
|
jsonRead(parameters, F("scid"), scid);
|
||||||
jsonRead(parameters, F("shname"), shname);
|
jsonRead(parameters, F("shname"), shname);
|
||||||
jsonRead(parameters, F("int"), interval);
|
// jsonRead(parameters, F("int"), interval);
|
||||||
interval = interval * 1000 * 60; // так как у нас в минутах
|
long interval;
|
||||||
|
jsonRead(parameters, F("int"), interval); // в минутах
|
||||||
|
setInterval(interval * 60);
|
||||||
|
// interval = interval * 1000 * 60; // так как у нас в минутах
|
||||||
urlFinal = URL + scid + F("/exec?") + F("sheet=") + shname;
|
urlFinal = URL + scid + F("/exec?") + F("sheet=") + shname;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,19 +42,19 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop()
|
// void loop()
|
||||||
{
|
// {
|
||||||
if (enableDoByInt)
|
// if (enableDoByInt)
|
||||||
{
|
// {
|
||||||
currentMillis = millis();
|
// currentMillis = millis();
|
||||||
difference = currentMillis - prevMillis;
|
// difference = currentMillis - prevMillis;
|
||||||
if (difference >= interval)
|
// if (difference >= interval)
|
||||||
{
|
// {
|
||||||
prevMillis = millis();
|
// prevMillis = millis();
|
||||||
this->doByInterval();
|
// this->doByInterval();
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
IoTValue execute(String command, std::vector<IoTValue> ¶m)
|
IoTValue execute(String command, std::vector<IoTValue> ¶m)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ class Loging : public IoTItem {
|
|||||||
String prevDate = "";
|
String prevDate = "";
|
||||||
bool firstTimeInit = true;
|
bool firstTimeInit = true;
|
||||||
|
|
||||||
long interval;
|
// long interval;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Loging(String parameters) : IoTItem(parameters) {
|
Loging(String parameters) : IoTItem(parameters) {
|
||||||
@@ -34,8 +34,9 @@ class Loging : public IoTItem {
|
|||||||
points = 300;
|
points = 300;
|
||||||
SerialPrint("E", F("Loging"), "'" + id + "' user set more points than allowed, value reset to 300");
|
SerialPrint("E", F("Loging"), "'" + id + "' user set more points than allowed, value reset to 300");
|
||||||
}
|
}
|
||||||
jsonRead(parameters, F("int"), interval);
|
long interval;
|
||||||
interval = interval * 1000 * 60; // приводим к милисекундам
|
jsonRead(parameters, F("int"), interval); // в минутах
|
||||||
|
setInterval(interval * 60);
|
||||||
//jsonRead(parameters, F("keepdays"), keepdays, false);
|
//jsonRead(parameters, F("keepdays"), keepdays, false);
|
||||||
|
|
||||||
// создадим экземпляр класса даты
|
// создадим экземпляр класса даты
|
||||||
@@ -303,18 +304,18 @@ class Loging : public IoTItem {
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
// void loop() {
|
||||||
if (enableDoByInt) {
|
// if (enableDoByInt) {
|
||||||
currentMillis = millis();
|
// currentMillis = millis();
|
||||||
difference = currentMillis - prevMillis;
|
// difference = currentMillis - prevMillis;
|
||||||
if (difference >= interval) {
|
// if (difference >= interval) {
|
||||||
prevMillis = millis();
|
// prevMillis = millis();
|
||||||
if (interval != 0) {
|
// if (interval != 0) {
|
||||||
this->doByInterval();
|
// this->doByInterval();
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
void regEvent(const String &value, const String &consoleInfo, bool error = false, bool genEvent = true) {
|
void regEvent(const String &value, const String &consoleInfo, bool error = false, bool genEvent = true) {
|
||||||
String userDate = getItemValue(id + "-date");
|
String userDate = getItemValue(id + "-date");
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ class LogingDaily : public IoTItem {
|
|||||||
String prevDate = "";
|
String prevDate = "";
|
||||||
bool firstTimeInit = true;
|
bool firstTimeInit = true;
|
||||||
|
|
||||||
long interval;
|
// long interval;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
LogingDaily(String parameters) : IoTItem(parameters) {
|
LogingDaily(String parameters) : IoTItem(parameters) {
|
||||||
@@ -40,8 +40,9 @@ class LogingDaily : public IoTItem {
|
|||||||
points = 365;
|
points = 365;
|
||||||
SerialPrint("E", F("LogingDaily"), "'" + id + "' user set more points than allowed, value reset to 365");
|
SerialPrint("E", F("LogingDaily"), "'" + id + "' user set more points than allowed, value reset to 365");
|
||||||
}
|
}
|
||||||
jsonRead(parameters, F("int"), interval);
|
long interval;
|
||||||
interval = interval * 1000 * 60; // приводим к милисекундам
|
jsonRead(parameters, F("int"), interval); // в минутах
|
||||||
|
setInterval(interval * 60);
|
||||||
}
|
}
|
||||||
|
|
||||||
void doByInterval() {
|
void doByInterval() {
|
||||||
@@ -225,16 +226,16 @@ class LogingDaily : public IoTItem {
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
// void loop() {
|
||||||
if (enableDoByInt) {
|
// if (enableDoByInt) {
|
||||||
currentMillis = millis();
|
// currentMillis = millis();
|
||||||
difference = currentMillis - prevMillis;
|
// difference = currentMillis - prevMillis;
|
||||||
if (difference >= interval) {
|
// if (difference >= interval) {
|
||||||
prevMillis = millis();
|
// prevMillis = millis();
|
||||||
this->doByInterval();
|
// this->doByInterval();
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
// просто максимальное количество точек
|
// просто максимальное количество точек
|
||||||
int calculateMaxCount() {
|
int calculateMaxCount() {
|
||||||
|
|||||||
@@ -11,15 +11,16 @@ class Weather : public IoTItem
|
|||||||
private:
|
private:
|
||||||
String _location;
|
String _location;
|
||||||
String _param;
|
String _param;
|
||||||
long interval;
|
// long interval;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Weather(String parameters) : IoTItem(parameters)
|
Weather(String parameters) : IoTItem(parameters)
|
||||||
{
|
{
|
||||||
_location = jsonReadStr(parameters, "location");
|
_location = jsonReadStr(parameters, "location");
|
||||||
_param = jsonReadStr(parameters, "param");
|
_param = jsonReadStr(parameters, "param");
|
||||||
jsonRead(parameters, F("int"), interval);
|
long interval;
|
||||||
interval = interval * 1000 * 60 * 60; // интервал проверки погоды в часах
|
jsonRead(parameters, F("int"), interval); // интервал проверки погоды в часах
|
||||||
|
setInterval(interval * 60 * 60);
|
||||||
}
|
}
|
||||||
|
|
||||||
void getWeather()
|
void getWeather()
|
||||||
@@ -113,19 +114,21 @@ public:
|
|||||||
regEvent(value.valS, "Weather");
|
regEvent(value.valS, "Weather");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void loop()
|
|
||||||
{
|
// void loop()
|
||||||
if (enableDoByInt)
|
// {
|
||||||
{
|
// if (enableDoByInt)
|
||||||
currentMillis = millis();
|
// {
|
||||||
difference = currentMillis - prevMillis;
|
// currentMillis = millis();
|
||||||
if (difference >= interval)
|
// difference = currentMillis - prevMillis;
|
||||||
{
|
// if (difference >= interval)
|
||||||
prevMillis = millis();
|
// {
|
||||||
this->doByInterval();
|
// prevMillis = millis();
|
||||||
}
|
// this->doByInterval();
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
IoTValue execute(String command, std::vector<IoTValue> ¶m)
|
IoTValue execute(String command, std::vector<IoTValue> ¶m)
|
||||||
{
|
{
|
||||||
if (command == "get")
|
if (command == "get")
|
||||||
|
|||||||
Reference in New Issue
Block a user