void initVar()
{
id [0] = "50"; // === 0 === Температура
page [0] = room;
pageId [0] = "52";
sTopic [0] = prefdev + "/DHT22_t";
stat [0] = setStatus(DHT22_tS + " °C");
descr [0] = "Температура";
widget [0] = "anydata";
class1 [0] = "item rounded no-padding";
style1 [0] = "";
class2 [0] = "rounded padding";
style2 [0] = "font-size:20px;float:left;height:50px";
class3 [0] = "rounded padding";
style3 [0] = "font-size:30px;text-align:right;height:50px";
id [1] = "51"; // === 1 === Влажность
page [1] = room;
pageId [1] = "52";
sTopic [1] = prefdev + "/DHT22_h";
stat [1] = setStatus(DHT22_hS + " %");
descr [1] = "Влажность";
widget [1] = "anydata";
class1 [1] = "item rounded no-padding";
style1 [1] = "";
class2 [1] = "rounded padding";
style2 [1] = "font-size:20px;float:left;height:50px";
class3 [1] = "rounded padding";
style3 [1] = "font-size:30px;text-align:right;height:50px";
id [2] = "52"; // === 2 === Нагреватель
page [2] = room;
pageId [2] = "52";
sTopic [2] = prefdev + "/lightblue";
stat [2] = setStatus(OFF);
descr [2] = "Нагреватель";
widget [2] = "toggle";
more [2] = ",\"iconClass\":\"ion-ios-flame-outline\",\"iconClassOff\":\"ion-ios-flame-outline\",\"iconStyle\":\"font-size:30px;color:#ff3d3d;\",\"iconStyleOff\":\"font-size:30px;color:#eee;\",\"descrStyle\":\"font-size:20px;line-height:1.5em;\"";
defaultVal[2] = OFF;
id [3] = "53"; // === 3 === Button_Minus
page [3] = room;
pageId [3] = "52";
sTopic [3] = prefdev + "/B_Minus";
widget [3] = "simple-btn";
class1 [3] = "item no-border col-xs-4"; // Размер колонки
class2 [3] = "balanced";
class3 [3] = "button button-calm button-fab button-outline icon ion-minus";
style3 [3] = "height:80px;width:80px;";
more [3] = ",\"delay\":\"1000\"";
id [4] = "54"; // === 4 === Нагревать до
page [4] = room;
pageId [4] = "52";
sTopic [4] = prefdev + "/setpoint";
stat [4] = setStatus(String(setpoint) + "°");
widget [4] = "anydata";
class1 [4] = "item no-border col-xs-4"; // Размер колонки
class3 [4] = "text-center";
style3 [4] = "font-size:45px;font-weight:bold;line-height:2em;height:70px;";
id [5] = "55"; // === 5 === Button_Plus
page [5] = room;
pageId [5] = "52";
sTopic [5] = prefdev + "/B_Plus";
widget [5] = "simple-btn";
class1 [5] = "item no-border col-xs-4"; // Размер колонки
style1 [5] = "text-align: right;";
class2 [5] = "balanced";
class3 [5] = "button button-assertive button-fab button-outline icon ion-plus";
style3 [5] = "height:80px;width:80px;";
more [5] = ",\"delay\":\"1000\"";
id [6] = "57"; // === 6 === Button_MinusA
page [6] = room;
pageId [6] = "52";
sTopic [6] = prefdev + "/B_MinusA";
widget [6] = "simple-btn";
class1 [6] = "item no-border col-xs-4"; // Размер колонки
class2 [6] = "balanced";
class3 [6] = "button button-calm button-fab button-outline icon ion-minus";
style3 [6] = "height:60px;width:60px;";
hide [6] = false;
id [7] = "58"; // === 7 === Нагревать с 23 до 7
page [7] = room;
pageId [7] = "52";
sTopic [7] = prefdev + "/setpointA";
stat [7] = setStatus(String(setpointA) + "°");
widget [7] = "anydata";
class1 [7] = "item no-border col-xs-4"; // Размер колонки
class3 [7] = "text-center";
style3 [7] = "font-size:35px;font-weight:bold;line-height:2em;height:50px;";
hide [7] = false;
id [8] = "59"; // === 8 === Button_PlusA
page [8] = room;
pageId [8] = "52";
sTopic [8] = prefdev + "/B_PlusA";
widget [8] = "simple-btn";
class1 [8] = "item no-border col-xs-4"; // Размер колонки
style1 [8] = "text-align: right;";
class2 [8] = "balanced";
class3 [8] = "button button-assertive button-fab button-outline icon ion-plus";
style3 [8] = "height:60px;width:60px;";
hide [8] = false;
id [9] = "56"; // === 9 === Время
page [9] = room;
pageId [9] = "52";
sTopic [9] = prefdev + "/DateTime";
stat [9] = setStatus(String(addZero(day(), 2, " ") + "." + addZero(month(), 2, "0") + "." + addZero(year(), 2, "0") + " " + addZero(hour(), 2, "0") + ":" + addZero(minute(), 2, "0") + ":" + addZero(second(), 2, "0")));
widget [9] = "anydata";
descr [9] = "Время";
class1 [9] = "item rounded no-padding";
style1 [9] = "";
class2 [9] = "rounded padding";
style2 [9] = "font-size:15px;float:left;height:50px";
class3 [9] = "rounded padding";
style3 [9] = "font-size:15px;text-align:right;height:50px";
id [10] = "60"; // === 10 === DS18B20
page [10] = room;
pageId [10] = "52";
sTopic [10] = prefdev + "/DS18B20";
stat [10] = setStatus(DS18B20_1S + " °C");
widget [10] = "anydata";
descr [10] = "Улица";
class1 [10] = "item rounded no-padding";
style1 [10] = "";
class2 [10] = "rounded padding";
style2 [10] = "font-size:20px;float:left;height:50px";
class3 [10] = "rounded padding";
style3 [10] = "font-size:30px;text-align:right;height:50px";
needPubConfig = true;
}
// send confirmation - status message
void pubStatus(String t, String payload)
{
client.publish(t + "/status", payload);
delay(PUB_DELAY);
}
void pubConfig()
{
needPubConfig = false;
for (int i = 0; i < nWidgets; i = i + 1)
{
pubConfigX(i);
}
yield();
}
void pubConfigX(int i)
{
if (hide[i] == false)
{
thing_config[i] = "{\"id\":" + id[i] + ",\"page\":\"" + page[i] + "\",\"pageId\":" + pageId[i] + ",\"widget\":\"" + widget[i] + "\",\"descr\":\"" + descr[i] + "\",\"topic\":\"" + sTopic[i] + "\",\"class1\":\"" + class1[i] + "\",\"style1\":\"" + style1[i] + "\",\"class2\":\"" + class2[i] + "\",\"style2\":\"" + style2[i] + "\",\"class3\":\"" + class3[i] + "\",\"style3\":\"" + style3[i] + "\"" + more[i] + "}";
}
else
{
thing_config[i] = "{\"id\":" + id[i] + ",\"page\":\"" + page[i] + "\"}";
}
client.publish(MQTT::Publish(prefdev + "/config", thing_config[i]).set_qos(1));
delay(PUB_DELAY);
pubStatus(sTopic[i], stat[i]);
}
void controlGPIO ()
{
String t = topic;
String p = payload;
needControlGPIO = false;
if (t == sTopic[0] + "/control") // === 0 === Температура
{
}
else if (t == sTopic[1] + "/control") // === 1 === Влажность
{
}
else if (t == sTopic[2] + "/control") // === 2 === Нагреватель
{
if (p == "0")
{
//digitalWrite(Relay_pin, OFF);
stat[2] = stat0;
getDHT22();
for (int i = 3; i < 9; i = i + 1)
{
hide[i] = false;
pubConfigX(i);
}
}
else
{
digitalWrite(Relay_pin, ON);
stat[2] = stat1;
for (int i = 3; i < 9; i = i + 1)
{
hide[i] = true;
pubConfigX(i);
}
}
pubStatus(sTopic[2], stat[2]);
chkdRt();
}
else if (t == sTopic[3] + "/control") // === 3 === Button_Minus
{
setpointMinus();
}
else if (t == sTopic[4] + "/control") // === 4 === setpoint
{
}
else if (t == sTopic[5] + "/control") // === 5 === Button_Plus
{
setpointPlus();
}
else if (t == sTopic[6] + "/control") // === 6 === Button_MinusA
{
setpointMinusA();
}
else if (t == sTopic[7] + "/control") // === 7 === Нагревать с 23 до 7
{
}
else if (t == sTopic[8] + "/control") // === 8 === Button_PlusA
{
setpointPlusA();
}
else if (t == sTopic[9] + "/control") // === 9 === Время
{
}
else if (t == sTopic[10] + "/control") // === 10 === DS18B20
{
}
}
// ========================== publish =========================================================
if( count10 < 10)
{
count10 ++;
}
else
{
pubStatus(sTopic[0], "{\"status\":\"" + DHT22_tS + " °C\"}");
pubStatus(sTopic[1], "{\"status\":\"" + DHT22_hS + " %\"}");
stat[4] = setStatus(String(addZero(setpoint, 2, " ")) + "°"); // === Статус регулятора Нагревателя
pubStatus(sTopic[4], stat[4]);
stat[9] = setStatus(String(addZero(day(), 2, " ") + "." + addZero(month(), 2, "0") + "." + addZero(year(), 2, "0") + " " + addZero(hour(), 2, "0") + ":" + addZero(minute(), 2, "0") + ":" + addZero(second(), 2, "0")));
pubStatus(sTopic[9], stat[9]); // Дата и Время
pubStatus(sTopic[10], "{\"status\":\"" + DS18B20_1S + " °C\"}");
count10 = 0;
}
client.loop();
}
}
else
{
delay(1000);
}
}
String setStatus ( String s )
{
String stat = "{\"status\":\"" + s + "\"}";
return stat;
}
String setStatus ( int s )
{
String stat = "{\"status\":\"" + String(s) + "\"}";
return stat;
}