New iobroker
This commit is contained in:
@@ -24,7 +24,8 @@ leds lBlue(LED_BLUE, 200);
|
|||||||
|
|
||||||
const char* ssid = "wf-home";
|
const char* ssid = "wf-home";
|
||||||
const char* password = "0ndthnrf";
|
const char* password = "0ndthnrf";
|
||||||
const char* mqtt_server = "192.168.1.250";
|
const char* mqtt_server = "192.168.1.111";
|
||||||
|
#define TOPIC "home/"
|
||||||
|
|
||||||
float temp, rel_hum;
|
float temp, rel_hum;
|
||||||
bool izm = false;
|
bool izm = false;
|
||||||
@@ -110,13 +111,13 @@ void loop() {
|
|||||||
mv = digitalRead(MOVE_SENS);
|
mv = digitalRead(MOVE_SENS);
|
||||||
if(mv != oldmv){
|
if(mv != oldmv){
|
||||||
oldmv = mv;
|
oldmv = mv;
|
||||||
client.publish("/home/smallroom/move", mv == 0 ? "0" : "1");
|
client.publish(TOPIC"smallroom/move", mv == 0 ? "0" : "1");
|
||||||
};
|
};
|
||||||
//if(abs(adc - oldadc) > delta){
|
//if(abs(adc - oldadc) > delta){
|
||||||
if(((adc < delta) && !lsSent) || ((adc >= (delta + 5)) && !lbSent)){
|
if(((adc < delta) && !lsSent) || ((adc >= (delta + 5)) && !lbSent)){
|
||||||
char strFVal[6];
|
char strFVal[6];
|
||||||
itoa(adc, strFVal, 10);
|
itoa(adc, strFVal, 10);
|
||||||
client.publish("/home/smallroom/light", strFVal);
|
client.publish(TOPIC"smallroom/light", strFVal);
|
||||||
oldadc = adc;
|
oldadc = adc;
|
||||||
if(adc < delta) {lsSent = true; lbSent = false;}
|
if(adc < delta) {lsSent = true; lbSent = false;}
|
||||||
else {lbSent = true; lsSent = false;}
|
else {lbSent = true; lsSent = false;}
|
||||||
@@ -151,8 +152,8 @@ void reconnect() {
|
|||||||
// можно подписаться не только на один, а на несколько топиков
|
// можно подписаться не только на один, а на несколько топиков
|
||||||
char v[6];
|
char v[6];
|
||||||
itoa(delta, v, 10);
|
itoa(delta, v, 10);
|
||||||
client.publish("/home/smallroom/ldelta", v);
|
client.publish(TOPIC"smallroom/ldelta", v);
|
||||||
client.subscribe("/home/smallroom/ldelta");
|
client.subscribe(TOPIC"smallroom/ldelta");
|
||||||
} else {
|
} else {
|
||||||
//Serial.print("failed, rc="); // "подключение не удалось"
|
//Serial.print("failed, rc="); // "подключение не удалось"
|
||||||
//Serial.print(client.state());
|
//Serial.print(client.state());
|
||||||
@@ -170,18 +171,18 @@ void publishMin()
|
|||||||
//digitalWrite(LED_BLUE, HIGH);
|
//digitalWrite(LED_BLUE, HIGH);
|
||||||
if(!isnan(temp)){
|
if(!isnan(temp)){
|
||||||
dtostrf(temp, 6, 1, strFVal);
|
dtostrf(temp, 6, 1, strFVal);
|
||||||
client.publish("/home/smallroom/temp", strFVal);
|
client.publish(TOPIC"smallroom/temp", strFVal);
|
||||||
}
|
}
|
||||||
if(!isnan(rel_hum)){
|
if(!isnan(rel_hum)){
|
||||||
dtostrf(rel_hum, 6, 1, strFVal);
|
dtostrf(rel_hum, 6, 1, strFVal);
|
||||||
client.publish("/home/smallroom/rel_hum", strFVal);
|
client.publish(TOPIC"smallroom/rel_hum", strFVal);
|
||||||
}
|
}
|
||||||
ultoa(adc, strFVal, 10);
|
ultoa(adc, strFVal, 10);
|
||||||
client.publish("/home/smallroom/light", strFVal);
|
client.publish(TOPIC"smallroom/light", strFVal);
|
||||||
ultoa(cRun, strFVal, 10);
|
ultoa(cRun, strFVal, 10);
|
||||||
client.publish("/home/smallroom/millis", strFVal);
|
client.publish(TOPIC"smallroom/millis", strFVal);
|
||||||
itoa(delta, strFVal, 10);
|
itoa(delta, strFVal, 10);
|
||||||
client.publish("/home/smallroom/ldelta", strFVal);
|
client.publish(TOPIC"smallroom/ldelta", strFVal);
|
||||||
//digitalWrite(LED_BLUE, LOW);
|
//digitalWrite(LED_BLUE, LOW);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -213,7 +214,7 @@ void publishSec()
|
|||||||
}
|
}
|
||||||
|
|
||||||
void callback(char* topic, byte* payload, unsigned int length) {
|
void callback(char* topic, byte* payload, unsigned int length) {
|
||||||
if(strcmp(topic,"/home/smallroom/ldelta") == 0){
|
if(strcmp(topic,TOPIC"smallroom/ldelta") == 0){
|
||||||
payload[length] = '\0';
|
payload[length] = '\0';
|
||||||
String pl = String((char*)payload);
|
String pl = String((char*)payload);
|
||||||
delta = pl.toInt();// atoi((char*)payload);
|
delta = pl.toInt();// atoi((char*)payload);
|
||||||
|
|||||||
@@ -10,12 +10,12 @@
|
|||||||
|
|
||||||
[env:esp07]
|
[env:esp07]
|
||||||
platform = espressif8266
|
platform = espressif8266
|
||||||
board = nodemcuv2
|
;board = nodemcuv2
|
||||||
;board = esp07
|
board = esp07
|
||||||
framework = arduino
|
framework = arduino
|
||||||
;board_build.ldscript = eagle.flash.1m.ld
|
;board_build.ldscript = eagle.flash.1m.ld
|
||||||
;upload_protocol = espota
|
upload_protocol = espota
|
||||||
;upload_port = 192.168.1.136
|
upload_port = 192.168.1.136
|
||||||
;upload_port = 192.168.1.95
|
;upload_port = 192.168.1.95
|
||||||
monitor_speed = 115200
|
monitor_speed = 115200
|
||||||
lib_deps =
|
lib_deps =
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ void setup(){
|
|||||||
wifiConnectHandler = WiFi.onStationModeGotIP(onWifiConnect);
|
wifiConnectHandler = WiFi.onStationModeGotIP(onWifiConnect);
|
||||||
wifiDisconnectHandler = WiFi.onStationModeDisconnected(onWifiDisconnect);
|
wifiDisconnectHandler = WiFi.onStationModeDisconnected(onWifiDisconnect);
|
||||||
|
|
||||||
mClient.setServer("192.168.1.250", 1883);
|
mClient.setServer(mqtt_server, 1883);
|
||||||
|
|
||||||
pinMode(LED_WF, OUTPUT);
|
pinMode(LED_WF, OUTPUT);
|
||||||
pinMode(LED_MQ, OUTPUT);
|
pinMode(LED_MQ, OUTPUT);
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
#define P_SENS (14) //D5
|
#define P_SENS (14) //D5
|
||||||
#define WF_LED 2
|
#define WF_LED 2
|
||||||
#define HOST_NAME "MidRoom"
|
#define HOST_NAME "MidRoom"
|
||||||
#define TOPIC "/home/midroom"
|
#define TOPIC "home/midroom"
|
||||||
|
|
||||||
Adafruit_BME280 bme;
|
Adafruit_BME280 bme;
|
||||||
MHZ19 mhz19;
|
MHZ19 mhz19;
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ framework = arduino
|
|||||||
;board_build.ldscript = eagle.flash.1m.ld
|
;board_build.ldscript = eagle.flash.1m.ld
|
||||||
;board_build.flash_mode = dout
|
;board_build.flash_mode = dout
|
||||||
upload_protocol = espota
|
upload_protocol = espota
|
||||||
upload_port = 192.168.1.114
|
upload_port = 192.168.1.132
|
||||||
lib_deps =
|
lib_deps =
|
||||||
jwrw/ESP_EEPROM @ ^2.0.0
|
jwrw/ESP_EEPROM @ ^2.0.0
|
||||||
robtillaart/RunningMedian @ ^0.3.3
|
robtillaart/RunningMedian @ ^0.3.3
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ unsigned long cRun;
|
|||||||
|
|
||||||
const char* ssid = "wf-home";
|
const char* ssid = "wf-home";
|
||||||
const char* password = "0ndthnrf";
|
const char* password = "0ndthnrf";
|
||||||
const char* mqtt_server = "192.168.1.250";
|
const char* mqtt_server = "192.168.1.111";
|
||||||
|
|
||||||
AsyncMqttClient mqttClient;
|
AsyncMqttClient mqttClient;
|
||||||
Ticker mqttReconnectTimer;
|
Ticker mqttReconnectTimer;
|
||||||
|
|||||||
@@ -5,7 +5,8 @@
|
|||||||
|
|
||||||
const char* ssid = "wf-home";
|
const char* ssid = "wf-home";
|
||||||
const char* password = "0ndthnrf";
|
const char* password = "0ndthnrf";
|
||||||
const char* mqtt_server = "192.168.1.250";
|
const char* mqtt_server = "192.168.1.111";
|
||||||
|
#define TOPIC "home/"
|
||||||
|
|
||||||
#define LED_WF (12)
|
#define LED_WF (12)
|
||||||
#define LED_MQ (13)
|
#define LED_MQ (13)
|
||||||
@@ -115,7 +116,7 @@ void loop() {
|
|||||||
ultoa(millis(), v, 10);
|
ultoa(millis(), v, 10);
|
||||||
digitalWrite(LED_WRK, LOW);
|
digitalWrite(LED_WRK, LOW);
|
||||||
led_ms = millis();
|
led_ms = millis();
|
||||||
mqttClient.publish("/home/kuh/ltblmillis", 0, false, v);
|
mqttClient.publish(TOPIC"kuh/ltblmillis", 0, false, v);
|
||||||
}
|
}
|
||||||
nSec = 0;
|
nSec = 0;
|
||||||
}
|
}
|
||||||
@@ -129,7 +130,7 @@ bool switchLight(uint8_t nLamp, int state, bool pub)
|
|||||||
if (pub){
|
if (pub){
|
||||||
digitalWrite(LED_WRK, LOW);
|
digitalWrite(LED_WRK, LOW);
|
||||||
led_ms = millis();
|
led_ms = millis();
|
||||||
mqttClient.publish("/home/kuh/lighttbl", 1, false, state ? "1" : "0");
|
mqttClient.publish(TOPIC"kuh/lighttbl", 1, false, state ? "1" : "0");
|
||||||
}
|
}
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
@@ -154,9 +155,9 @@ void onWifiDisconnect(const WiFiEventStationModeDisconnected& event) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void onMqttConnect(bool sessionPresent) {
|
void onMqttConnect(bool sessionPresent) {
|
||||||
mqttClient.publish("/home/kuh/lighttbl_set", 1, false, digitalRead(LAMP) == 1 ? "1" : "0");
|
mqttClient.publish(TOPIC"kuh/lighttbl_set", 1, false, digitalRead(LAMP) == 1 ? "1" : "0");
|
||||||
mqttClient.subscribe("/home/kuh/lighttbl_set", 1);
|
mqttClient.subscribe(TOPIC"kuh/lighttbl_set", 1);
|
||||||
mqttClient.publish("/home/kuh/lighttbl", 1, false, digitalRead(LAMP) == 1 ? "1" : "0");
|
mqttClient.publish(TOPIC"kuh/lighttbl", 1, false, digitalRead(LAMP) == 1 ? "1" : "0");
|
||||||
digitalWrite(LED_MQ, HIGH);
|
digitalWrite(LED_MQ, HIGH);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -171,7 +172,7 @@ void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties
|
|||||||
char pl[6];
|
char pl[6];
|
||||||
strncpy(pl, payload, len);
|
strncpy(pl, payload, len);
|
||||||
pl[len] = '\0';
|
pl[len] = '\0';
|
||||||
if(strcmp(topic, "/home/kuh/lighttbl_set") == 0){
|
if(strcmp(topic, TOPIC"kuh/lighttbl_set") == 0){
|
||||||
if (strncmp("1", pl, 1) == 0) switchLight(LAMP, 1, true);//lStat2 = true;
|
if (strncmp("1", pl, 1) == 0) switchLight(LAMP, 1, true);//lStat2 = true;
|
||||||
else switchLight(LAMP, 0, true);//lStat2 = false;
|
else switchLight(LAMP, 0, true);//lStat2 = false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,7 +36,8 @@ uint16_t stat[4];
|
|||||||
|
|
||||||
const char* ssid = "wf-home";
|
const char* ssid = "wf-home";
|
||||||
const char* password = "0ndthnrf";
|
const char* password = "0ndthnrf";
|
||||||
const char* mqtt_server = "192.168.1.250";
|
const char* mqtt_server = "192.168.1.111";
|
||||||
|
#define TOPIC "home/"
|
||||||
|
|
||||||
unsigned long crun;
|
unsigned long crun;
|
||||||
//sensors_event_t temp_event, pressure_event, humidity_event;
|
//sensors_event_t temp_event, pressure_event, humidity_event;
|
||||||
|
|||||||
@@ -15,8 +15,8 @@ framework = arduino
|
|||||||
upload_protocol = espota
|
upload_protocol = espota
|
||||||
upload_port = 192.168.1.147
|
upload_port = 192.168.1.147
|
||||||
lib_deps =
|
lib_deps =
|
||||||
BME280 @ ^3.0.0
|
finitespace/BME280 @ ^3.0.0
|
||||||
milesburton/DallasTemperature @ ^3.9.1
|
milesburton/DallasTemperature @ ^3.9.1
|
||||||
Bounce2 @ ^2.55
|
thomasfredericks/Bounce2 @ ^2.55
|
||||||
LiquidCrystal_PCF8574 @ ^1.2.0
|
mathertel/LiquidCrystal_PCF8574 @ ^1.2.0
|
||||||
AsyncMqttClient @ ^0.8.2
|
marvinroger/AsyncMqttClient @ ^0.8.2
|
||||||
|
|||||||
@@ -146,12 +146,12 @@ void loop() {
|
|||||||
if(mv){
|
if(mv){
|
||||||
mv = true;
|
mv = true;
|
||||||
lcd.setBacklight(255);
|
lcd.setBacklight(255);
|
||||||
mqttClient.publish("/home/kuh/move", 1, false, "1");
|
mqttClient.publish(TOPIC"kuh/move", 1, false, "1");
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
mv = false;
|
mv = false;
|
||||||
lcd.setBacklight(0);
|
lcd.setBacklight(0);
|
||||||
mqttClient.publish("/home/kuh/move", 1, false, "0");
|
mqttClient.publish(TOPIC"kuh/move", 1, false, "0");
|
||||||
}
|
}
|
||||||
prMV = mv;
|
prMV = mv;
|
||||||
}
|
}
|
||||||
@@ -257,40 +257,40 @@ void publishMin()
|
|||||||
digitalWrite(BLUE, HIGH);
|
digitalWrite(BLUE, HIGH);
|
||||||
if(!isnan(tempOut)){
|
if(!isnan(tempOut)){
|
||||||
dtostrf(tempOut, 6, 1, strFVal);
|
dtostrf(tempOut, 6, 1, strFVal);
|
||||||
mqttClient.publish("/home/kuh/temp_out", 1, false, strFVal);
|
mqttClient.publish(TOPIC"kuh/temp_out", 1, false, strFVal);
|
||||||
}
|
}
|
||||||
if(!isnan(tempIn)){
|
if(!isnan(tempIn)){
|
||||||
dtostrf(tempIn, 6, 1, strFVal);
|
dtostrf(tempIn, 6, 1, strFVal);
|
||||||
mqttClient.publish("/home/kuh/temp_in", 1, false, strFVal);
|
mqttClient.publish(TOPIC"kuh/temp_in", 1, false, strFVal);
|
||||||
}
|
}
|
||||||
if(!isnan(hum)){
|
if(!isnan(hum)){
|
||||||
dtostrf(hum, 6, 1, strFVal);
|
dtostrf(hum, 6, 1, strFVal);
|
||||||
mqttClient.publish("/home/kuh/humidity", 1, false, strFVal);
|
mqttClient.publish(TOPIC"kuh/humidity", 1, false, strFVal);
|
||||||
}
|
}
|
||||||
if(!isnan(press)){
|
if(!isnan(press)){
|
||||||
dtostrf(press, 6, 1, strFVal);
|
dtostrf(press, 6, 1, strFVal);
|
||||||
mqttClient.publish("/home/kuh/pressure", 1, false, strFVal);
|
mqttClient.publish(TOPIC"kuh/pressure", 1, false, strFVal);
|
||||||
}
|
}
|
||||||
//itoa(lightSP, strFVal, 10);
|
//itoa(lightSP, strFVal, 10);
|
||||||
//mqttClient.publish("/home/kuh/light_sp", 1, false, strFVal);
|
//mqttClient.publish(TOPIC"kuh/light_sp", 1, false, strFVal);
|
||||||
//itoa(lightDB, strFVal, 10);
|
//itoa(lightDB, strFVal, 10);
|
||||||
//mqttClient.publish("/home/kuh/light_db", 1, false, strFVal);
|
//mqttClient.publish(TOPIC"kuh/light_db", 1, false, strFVal);
|
||||||
itoa(adc, strFVal, 10);
|
itoa(adc, strFVal, 10);
|
||||||
mqttClient.publish("/home/kuh/light_cur", 1, false, strFVal);
|
mqttClient.publish(TOPIC"kuh/light_cur", 1, false, strFVal);
|
||||||
if(!isnan(tempHol)){
|
if(!isnan(tempHol)){
|
||||||
dtostrf(tempHol, 6, 1, strFVal);
|
dtostrf(tempHol, 6, 1, strFVal);
|
||||||
mqttClient.publish("/home/kuh/hol_top", 1, false, strFVal);
|
mqttClient.publish(TOPIC"kuh/hol_top", 1, false, strFVal);
|
||||||
}
|
}
|
||||||
if(!isnan(tempHoM)){
|
if(!isnan(tempHoM)){
|
||||||
dtostrf(tempHoM, 6, 1, strFVal);
|
dtostrf(tempHoM, 6, 1, strFVal);
|
||||||
mqttClient.publish("/home/kuh/hol_down", 1, false, strFVal);
|
mqttClient.publish(TOPIC"kuh/hol_down", 1, false, strFVal);
|
||||||
}
|
}
|
||||||
if(!isnan(tempMor)){
|
if(!isnan(tempMor)){
|
||||||
dtostrf(tempMor, 6, 1, strFVal);
|
dtostrf(tempMor, 6, 1, strFVal);
|
||||||
mqttClient.publish("/home/kuh/moroz", 1, false, strFVal);
|
mqttClient.publish(TOPIC"kuh/moroz", 1, false, strFVal);
|
||||||
}
|
}
|
||||||
ultoa(crun, strFVal, 10);
|
ultoa(crun, strFVal, 10);
|
||||||
mqttClient.publish("/home/kuh/millis", 1, false, strFVal);
|
mqttClient.publish(TOPIC"kuh/millis", 1, false, strFVal);
|
||||||
digitalWrite(BLUE, LOW);
|
digitalWrite(BLUE, LOW);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -354,14 +354,14 @@ void onWifiDisconnect(const WiFiEventStationModeDisconnected& event) {
|
|||||||
void onMqttConnect(bool sessionPresent) {
|
void onMqttConnect(bool sessionPresent) {
|
||||||
char v[6];
|
char v[6];
|
||||||
itoa(lightData.SP, v, 10);
|
itoa(lightData.SP, v, 10);
|
||||||
mqttClient.publish("/home/kuh/light_sp", 1, false, v);
|
mqttClient.publish(TOPIC"kuh/light_sp", 1, false, v);
|
||||||
mqttClient.publish("/home/kuh/light_sp_set", 1, false, v);
|
mqttClient.publish(TOPIC"kuh/light_sp_set", 1, false, v);
|
||||||
itoa(lightData.DB, v, 10);
|
itoa(lightData.DB, v, 10);
|
||||||
mqttClient.publish("/home/kuh/light_db", 1, false, v);
|
mqttClient.publish(TOPIC"kuh/light_db", 1, false, v);
|
||||||
mqttClient.publish("/home/kuh/light_db_set", 1, false, v);
|
mqttClient.publish(TOPIC"kuh/light_db_set", 1, false, v);
|
||||||
mqttClient.publish("/home/kuh/move", 1, false, mv == 1 ? "1" : "0");
|
mqttClient.publish(TOPIC"kuh/move", 1, false, mv == 1 ? "1" : "0");
|
||||||
mqttClient.subscribe("/home/kuh/light_sp_set", 1);
|
mqttClient.subscribe(TOPIC"kuh/light_sp_set", 1);
|
||||||
mqttClient.subscribe("/home/kuh/light_db_set", 1);
|
mqttClient.subscribe(TOPIC"kuh/light_db_set", 1);
|
||||||
digitalWrite(BLUE, LOW);
|
digitalWrite(BLUE, LOW);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -375,17 +375,17 @@ void onMqttDisconnect(AsyncMqttClientDisconnectReason reason) {
|
|||||||
void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties properties, size_t len, size_t index, size_t total) {
|
void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties properties, size_t len, size_t index, size_t total) {
|
||||||
bool w = false;
|
bool w = false;
|
||||||
char v[6];
|
char v[6];
|
||||||
if(strcmp(topic, "/home/kuh/light_sp_set") == 0){
|
if(strcmp(topic, TOPIC"kuh/light_sp_set") == 0){
|
||||||
lightSP = atoi(payload);
|
lightSP = atoi(payload);
|
||||||
w = true;
|
w = true;
|
||||||
itoa(lightData.SP, v, 10);
|
itoa(lightData.SP, v, 10);
|
||||||
mqttClient.publish("/home/kuh/light_sp", 1, false, v);
|
mqttClient.publish(TOPIC"kuh/light_sp", 1, false, v);
|
||||||
}
|
}
|
||||||
if(strcmp(topic, "/home/kuh/light_db_set") == 0){
|
if(strcmp(topic, TOPIC"kuh/light_db_set") == 0){
|
||||||
lightDB = atoi(payload);
|
lightDB = atoi(payload);
|
||||||
w = true;
|
w = true;
|
||||||
itoa(lightData.DB, v, 10);
|
itoa(lightData.DB, v, 10);
|
||||||
mqttClient.publish("/home/kuh/light_db", 1, false, v);
|
mqttClient.publish(TOPIC"kuh/light_db", 1, false, v);
|
||||||
}
|
}
|
||||||
if(w){
|
if(w){
|
||||||
lightData.SP = lightSP;
|
lightData.SP = lightSP;
|
||||||
|
|||||||
@@ -15,7 +15,8 @@
|
|||||||
|
|
||||||
const char* ssid = "wf-home";
|
const char* ssid = "wf-home";
|
||||||
const char* password = "0ndthnrf";
|
const char* password = "0ndthnrf";
|
||||||
const char* mqtt_server = "192.168.1.250";
|
const char* mqtt_server = "192.168.1.111";
|
||||||
|
#define TOPIC "home/"
|
||||||
|
|
||||||
Bounce but1 = Bounce();
|
Bounce but1 = Bounce();
|
||||||
Bounce but2 = Bounce();
|
Bounce but2 = Bounce();
|
||||||
@@ -123,14 +124,14 @@ void loop(){
|
|||||||
digitalWrite(SOCK1, stat1);
|
digitalWrite(SOCK1, stat1);
|
||||||
EEPROM.write(0, stat1);
|
EEPROM.write(0, stat1);
|
||||||
EEPROM.commit();
|
EEPROM.commit();
|
||||||
pubBool("/home/roz1/on1", stat1);
|
pubBool(TOPIC"roz1/on1", stat1);
|
||||||
}
|
}
|
||||||
if(stat2 != oldstat2){
|
if(stat2 != oldstat2){
|
||||||
oldstat2 = stat2;
|
oldstat2 = stat2;
|
||||||
digitalWrite(SOCK2, stat2);
|
digitalWrite(SOCK2, stat2);
|
||||||
EEPROM.write(1, stat2);
|
EEPROM.write(1, stat2);
|
||||||
EEPROM.commit();
|
EEPROM.commit();
|
||||||
pubBool("/home/roz1/on2", stat2);
|
pubBool(TOPIC"roz1/on2", stat2);
|
||||||
}
|
}
|
||||||
if(cRun + 999 < millis()){
|
if(cRun + 999 < millis()){
|
||||||
cRun = millis();
|
cRun = millis();
|
||||||
@@ -139,7 +140,7 @@ void loop(){
|
|||||||
nSec = 0;
|
nSec = 0;
|
||||||
char v[15];
|
char v[15];
|
||||||
ultoa(millis()/1000, v, 10);
|
ultoa(millis()/1000, v, 10);
|
||||||
mqttClient.publish("/home/roz1/millis", 1, false, v);
|
mqttClient.publish(TOPIC"roz1/millis", 1, false, v);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -175,12 +176,12 @@ void onMqttConnect(bool sessionPresent) {
|
|||||||
Serial.println("Connected to MQTT.");
|
Serial.println("Connected to MQTT.");
|
||||||
Serial.print("Session present: ");
|
Serial.print("Session present: ");
|
||||||
Serial.println(sessionPresent);
|
Serial.println(sessionPresent);
|
||||||
mqttClient.publish("/home/roz1/on1", 1, false, stat1 == 0 ? "false" : "true");
|
mqttClient.publish(TOPIC"roz1/on1", 1, false, stat1 == 0 ? "false" : "true");
|
||||||
mqttClient.publish("/home/roz1/on1_set", 1, false, stat1 == 0 ? "false" : "true");
|
mqttClient.publish(TOPIC"roz1/on1_set", 1, false, stat1 == 0 ? "false" : "true");
|
||||||
mqttClient.publish("/home/roz1/on2", 1, false, stat2 == 0 ? "false" : "true");
|
mqttClient.publish(TOPIC"roz1/on2", 1, false, stat2 == 0 ? "false" : "true");
|
||||||
mqttClient.publish("/home/roz1/on2_set", 1, false, stat2 == 0 ? "false" : "true");
|
mqttClient.publish(TOPIC"roz1/on2_set", 1, false, stat2 == 0 ? "false" : "true");
|
||||||
mqttClient.subscribe("/home/roz1/on1_set", 1);
|
mqttClient.subscribe(TOPIC"roz1/on1_set", 1);
|
||||||
mqttClient.subscribe("/home/roz1/on2_set", 1);
|
mqttClient.subscribe(TOPIC"roz1/on2_set", 1);
|
||||||
nSec = 59;
|
nSec = 59;
|
||||||
digitalWrite(LED_MQ, LOW);
|
digitalWrite(LED_MQ, LOW);
|
||||||
}
|
}
|
||||||
@@ -200,7 +201,7 @@ void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties
|
|||||||
pl[len] = 0;
|
pl[len] = 0;
|
||||||
Serial.println(topic);
|
Serial.println(topic);
|
||||||
Serial.println(pl);
|
Serial.println(pl);
|
||||||
if(strcmp(topic, "/home/roz1/on1_set") == 0){
|
if(strcmp(topic, TOPIC"roz1/on1_set") == 0){
|
||||||
if(strcmp(pl, "true") == 0){
|
if(strcmp(pl, "true") == 0){
|
||||||
stat1 = 1;
|
stat1 = 1;
|
||||||
}
|
}
|
||||||
@@ -209,7 +210,7 @@ void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(strcmp(topic, "/home/roz1/on2_set") == 0){
|
if(strcmp(topic, TOPIC"roz1/on2_set") == 0){
|
||||||
if(strcmp(pl, "true") == 0){
|
if(strcmp(pl, "true") == 0){
|
||||||
stat2 = 1;
|
stat2 = 1;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,10 +11,11 @@
|
|||||||
//RemoteDebug Debug;
|
//RemoteDebug Debug;
|
||||||
|
|
||||||
//#endif
|
//#endif
|
||||||
|
#define MAINTOPIC "home"
|
||||||
|
|
||||||
const char* ssid = "wf-home";
|
const char* ssid = "wf-home";
|
||||||
const char* password = "0ndthnrf";
|
const char* password = "0ndthnrf";
|
||||||
const char* mqtt_server = "192.168.1.250";
|
const char* mqtt_server = "192.168.1.111";
|
||||||
|
|
||||||
AsyncMqttClient mqttClient;
|
AsyncMqttClient mqttClient;
|
||||||
Ticker mqttReconnectTimer;
|
Ticker mqttReconnectTimer;
|
||||||
@@ -134,7 +135,7 @@ void loop() {
|
|||||||
cRun = millis();
|
cRun = millis();
|
||||||
char v[11];
|
char v[11];
|
||||||
ultoa(cRun, v, 10);
|
ultoa(cRun, v, 10);
|
||||||
mqttClient.publish("/home/bigroom/millislamp", 0, false, v);
|
mqttClient.publish(MAINTOPIC"/bigroom/millislamp", 0, false, v);
|
||||||
//debugI("*Publish Millis: %u");
|
//debugI("*Publish Millis: %u");
|
||||||
}
|
}
|
||||||
// Debug.handle();
|
// Debug.handle();
|
||||||
@@ -146,7 +147,7 @@ bool switchLight(uint8_t nLamp, bool state, bool pub)
|
|||||||
digitalWrite(nLamp, state);
|
digitalWrite(nLamp, state);
|
||||||
EEPROM.put(nLamp == R_LED1 ? 0 : 1, state);
|
EEPROM.put(nLamp == R_LED1 ? 0 : 1, state);
|
||||||
EEPROM.commit();
|
EEPROM.commit();
|
||||||
String topic = "/home/bigroom/lamp";
|
String topic = MAINTOPIC"/bigroom/lamp";
|
||||||
char n = nLamp == R_LED1 ? '1' : '2';
|
char n = nLamp == R_LED1 ? '1' : '2';
|
||||||
//if (pub){
|
//if (pub){
|
||||||
mqttClient.publish(String(topic + n).c_str(), 1, false, state ? "1" : "0");
|
mqttClient.publish(String(topic + n).c_str(), 1, false, state ? "1" : "0");
|
||||||
@@ -173,12 +174,12 @@ void onWifiDisconnect(const WiFiEventStationModeDisconnected& event) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void onMqttConnect(bool sessionPresent) {
|
void onMqttConnect(bool sessionPresent) {
|
||||||
mqttClient.publish("/home/bigroom/lamp1", 1, false, lStat1 ? "1" : "0");
|
mqttClient.publish(MAINTOPIC"/bigroom/lamp1", 1, false, lStat1 ? "1" : "0");
|
||||||
mqttClient.publish("/home/bigroom/lamp2", 1, false, lStat2 ? "1" : "0");
|
mqttClient.publish(MAINTOPIC"/bigroom/lamp2", 1, false, lStat2 ? "1" : "0");
|
||||||
mqttClient.publish("/home/bigroom/lamp1_set", 1, false, lStat1 ? "1" : "0");
|
mqttClient.publish(MAINTOPIC"/bigroom/lamp1_set", 1, false, lStat1 ? "1" : "0");
|
||||||
mqttClient.publish("/home/bigroom/lamp2_set", 1, false, lStat2 ? "1" : "0");
|
mqttClient.publish(MAINTOPIC"/bigroom/lamp2_set", 1, false, lStat2 ? "1" : "0");
|
||||||
mqttClient.subscribe("/home/bigroom/lamp1_set", 1);
|
mqttClient.subscribe(MAINTOPIC"/bigroom/lamp1_set", 1);
|
||||||
mqttClient.subscribe("/home/bigroom/lamp2_set", 1);
|
mqttClient.subscribe(MAINTOPIC"/bigroom/lamp2_set", 1);
|
||||||
digitalWrite(B_LED, LOW);
|
digitalWrite(B_LED, LOW);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -192,7 +193,7 @@ void onMqttDisconnect(AsyncMqttClientDisconnectReason reason) {
|
|||||||
void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties properties, size_t len, size_t index, size_t total) {
|
void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties properties, size_t len, size_t index, size_t total) {
|
||||||
char s[10];
|
char s[10];
|
||||||
strncpy(s, payload, len);
|
strncpy(s, payload, len);
|
||||||
if(String(topic) == "/home/bigroom/lamp1_set"){
|
if(String(topic) == MAINTOPIC"/bigroom/lamp1_set"){
|
||||||
// if (atoi(payload) == 1) switchLight(R_LED1, 1, false);
|
// if (atoi(payload) == 1) switchLight(R_LED1, 1, false);
|
||||||
if (strncmp("1", payload, 1) == 0){
|
if (strncmp("1", payload, 1) == 0){
|
||||||
switchLight(R_LED1, true, false);
|
switchLight(R_LED1, true, false);
|
||||||
@@ -205,7 +206,7 @@ void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties
|
|||||||
// debugI("*Switch from MQTT F1: %s", s);
|
// debugI("*Switch from MQTT F1: %s", s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(String(topic) == "/home/bigroom/lamp2_set"){
|
if(String(topic) == MAINTOPIC"/bigroom/lamp2_set"){
|
||||||
if (strncmp("1", payload, 1) == 0){
|
if (strncmp("1", payload, 1) == 0){
|
||||||
switchLight(R_LED2, true, false);
|
switchLight(R_LED2, true, false);
|
||||||
// debugI("*Switch from MQTT T2: %s", s);
|
// debugI("*Switch from MQTT T2: %s", s);
|
||||||
|
|||||||
@@ -14,7 +14,8 @@
|
|||||||
|
|
||||||
const char* ssid = "wf-home";
|
const char* ssid = "wf-home";
|
||||||
const char* password = "0ndthnrf";
|
const char* password = "0ndthnrf";
|
||||||
const char* mqtt_server = "192.168.1.250";
|
const char* mqtt_server = "192.168.1.111";
|
||||||
|
#define TOPIC "home/"
|
||||||
|
|
||||||
AsyncMqttClient mqttClient;
|
AsyncMqttClient mqttClient;
|
||||||
Ticker mqttReconnectTimer;
|
Ticker mqttReconnectTimer;
|
||||||
@@ -60,13 +61,13 @@ void oneClick()
|
|||||||
// {
|
// {
|
||||||
// //lStat1 = false;
|
// //lStat1 = false;
|
||||||
// switchLight(R_LED, 0, true);
|
// switchLight(R_LED, 0, true);
|
||||||
// mqttClient.publish("/home/bigroom/lamp1_set", 0, false, "false");
|
// mqttClient.publish(TOPIC"bigroom/lamp1_set", 0, false, "false");
|
||||||
// mqttClient.publish("/home/bigroom/lamp2_set", 0, false, "false");
|
// mqttClient.publish(TOPIC"bigroom/lamp2_set", 0, false, "false");
|
||||||
// mqttClient.publish("/home/midroom/lamp1_set", 0, false, "false");
|
// mqttClient.publish(TOPIC"midroom/lamp1_set", 0, false, "false");
|
||||||
// mqttClient.publish("/home/midroom/lamp2_set", 0, false, "false");
|
// mqttClient.publish(TOPIC"midroom/lamp2_set", 0, false, "false");
|
||||||
// mqttClient.publish("/home/smallroom/lamp1_set", 0, false, "false");
|
// mqttClient.publish(TOPIC"smallroom/lamp1_set", 0, false, "false");
|
||||||
// mqttClient.publish("/home/smallroom/lamp2_set", 0, false, "false");
|
// mqttClient.publish(TOPIC"smallroom/lamp2_set", 0, false, "false");
|
||||||
// mqttClient.publish("/home/kuh/lighttbl", 0, false, "false");
|
// mqttClient.publish(TOPIC"kuh/lighttbl", 0, false, "false");
|
||||||
// }
|
// }
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
@@ -152,7 +153,7 @@ void loop() {
|
|||||||
// digitalWrite(R_LED, lStat1);
|
// digitalWrite(R_LED, lStat1);
|
||||||
// oldLStat1 = lStat1;
|
// oldLStat1 = lStat1;
|
||||||
// if(!rcv)
|
// if(!rcv)
|
||||||
// mqttClient.publish("/home/kor/lamp1", 0, false, lStat1 ? "1" : "0");
|
// mqttClient.publish(TOPIC"kor/lamp1", 0, false, lStat1 ? "1" : "0");
|
||||||
// else
|
// else
|
||||||
// rcv = false;
|
// rcv = false;
|
||||||
// EEPROM.put(0, lStat1);
|
// EEPROM.put(0, lStat1);
|
||||||
@@ -162,7 +163,7 @@ void loop() {
|
|||||||
cRun = millis();
|
cRun = millis();
|
||||||
char v[11];
|
char v[11];
|
||||||
ultoa(cRun, v, 10);
|
ultoa(cRun, v, 10);
|
||||||
mqttClient.publish("/home/kor/millislamp", 0, false, v);
|
mqttClient.publish(TOPIC"kor/millislamp", 0, false, v);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -172,7 +173,7 @@ bool switchLight(uint8_t nLamp, int state, bool pub)
|
|||||||
EEPROM.put(0, state);
|
EEPROM.put(0, state);
|
||||||
EEPROM.commit();
|
EEPROM.commit();
|
||||||
//if (pub)
|
//if (pub)
|
||||||
mqttClient.publish("/home/kor/lamp1", 1, false, state ? "1" : "0");
|
mqttClient.publish(TOPIC"kor/lamp1", 1, false, state ? "1" : "0");
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -200,9 +201,9 @@ void onWifiDisconnect(const WiFiEventStationModeDisconnected& event) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void onMqttConnect(bool sessionPresent) {
|
void onMqttConnect(bool sessionPresent) {
|
||||||
mqttClient.publish("/home/kor/lamp1", 0, false, digitalRead(R_LED) == 1 ? "1" : "0");
|
mqttClient.publish(TOPIC"kor/lamp1", 0, false, digitalRead(R_LED) == 1 ? "1" : "0");
|
||||||
mqttClient.publish("/home/kor/lamp1_set", 0, false, digitalRead(R_LED) == 1 ? "1" : "0");
|
mqttClient.publish(TOPIC"kor/lamp1_set", 0, false, digitalRead(R_LED) == 1 ? "1" : "0");
|
||||||
mqttClient.subscribe("/home/kor/lamp1_set", 1);
|
mqttClient.subscribe(TOPIC"kor/lamp1_set", 1);
|
||||||
digitalWrite(B_LED, LOW);
|
digitalWrite(B_LED, LOW);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -230,7 +231,7 @@ void onMqttUnsubscribe(uint16_t packetId) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties properties, size_t len, size_t index, size_t total) {
|
void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties properties, size_t len, size_t index, size_t total) {
|
||||||
if(strcmp(topic, "/home/kor/lamp1_set") == 0){
|
if(strcmp(topic, TOPIC"kor/lamp1_set") == 0){
|
||||||
if (strncmp("1", payload, 1) == 0) switchLight(R_LED, 1, false);//lStat1 = true;
|
if (strncmp("1", payload, 1) == 0) switchLight(R_LED, 1, false);//lStat1 = true;
|
||||||
else switchLight(R_LED, 0, false);//lStat1 = false;
|
else switchLight(R_LED, 0, false);//lStat1 = false;
|
||||||
//rcv = true;
|
//rcv = true;
|
||||||
|
|||||||
@@ -7,7 +7,9 @@
|
|||||||
|
|
||||||
const char* ssid = "wf-home";
|
const char* ssid = "wf-home";
|
||||||
const char* password = "0ndthnrf";
|
const char* password = "0ndthnrf";
|
||||||
const char* mqtt_server = "192.168.1.250";
|
//const char* mqtt_server = "192.168.1.250";
|
||||||
|
const char* mqtt_server = "192.168.1.111";
|
||||||
|
#define TOPIC "home/"
|
||||||
|
|
||||||
AsyncMqttClient mqttClient;
|
AsyncMqttClient mqttClient;
|
||||||
Ticker mqttReconnectTimer;
|
Ticker mqttReconnectTimer;
|
||||||
@@ -115,7 +117,7 @@ bool switchLight(uint8_t nLamp, int state, bool pub)
|
|||||||
digitalWrite(nLamp, state);
|
digitalWrite(nLamp, state);
|
||||||
EEPROM.put(nLamp == R_LED1 ? 0 : 1, state);
|
EEPROM.put(nLamp == R_LED1 ? 0 : 1, state);
|
||||||
EEPROM.commit();
|
EEPROM.commit();
|
||||||
String topic = "/home/midroom/lamp";
|
String topic = TOPIC"midroom/lamp";
|
||||||
char n = nLamp == R_LED1 ? '1' : '2';
|
char n = nLamp == R_LED1 ? '1' : '2';
|
||||||
//if (pub)
|
//if (pub)
|
||||||
mqttClient.publish(String(topic + n).c_str(), 1, false, state ? "1" : "0");
|
mqttClient.publish(String(topic + n).c_str(), 1, false, state ? "1" : "0");
|
||||||
@@ -140,12 +142,12 @@ void onWifiDisconnect(const WiFiEventStationModeDisconnected& event) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void onMqttConnect(bool sessionPresent) {
|
void onMqttConnect(bool sessionPresent) {
|
||||||
mqttClient.publish("/home/midroom/lamp1", 1, false, digitalRead(R_LED1) == 1 ? "1" : "0");
|
mqttClient.publish(TOPIC"midroom/lamp1", 1, false, digitalRead(R_LED1) == 1 ? "1" : "0");
|
||||||
mqttClient.publish("/home/midroom/lamp2", 1, false, digitalRead(R_LED2) == 1 ? "1" : "0");
|
mqttClient.publish(TOPIC"midroom/lamp2", 1, false, digitalRead(R_LED2) == 1 ? "1" : "0");
|
||||||
mqttClient.publish("/home/midroom/lamp1_set", 1, false, digitalRead(R_LED1) == 1 ? "1" : "0");
|
mqttClient.publish(TOPIC"midroom/lamp1_set", 1, false, digitalRead(R_LED1) == 1 ? "1" : "0");
|
||||||
mqttClient.publish("/home/midroom/lamp2_set", 1, false, digitalRead(R_LED2) == 1 ? "1" : "0");
|
mqttClient.publish(TOPIC"midroom/lamp2_set", 1, false, digitalRead(R_LED2) == 1 ? "1" : "0");
|
||||||
mqttClient.subscribe("/home/midroom/lamp1_set", 1);
|
mqttClient.subscribe(TOPIC"midroom/lamp1_set", 1);
|
||||||
mqttClient.subscribe("/home/midroom/lamp2_set", 1);
|
mqttClient.subscribe(TOPIC"midroom/lamp2_set", 1);
|
||||||
digitalWrite(B_LED, LOW);
|
digitalWrite(B_LED, LOW);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -157,11 +159,11 @@ void onMqttDisconnect(AsyncMqttClientDisconnectReason reason) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties properties, size_t len, size_t index, size_t total) {
|
void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties properties, size_t len, size_t index, size_t total) {
|
||||||
if(strcmp(topic, "/home/midroom/lamp1_set") == 0){
|
if(strcmp(topic, TOPIC"midroom/lamp1_set") == 0){
|
||||||
if (strncmp("1", payload, 1) == 0) switchLight(R_LED1, 1, false);//lStat1 = true;
|
if (strncmp("1", payload, 1) == 0) switchLight(R_LED1, 1, false);//lStat1 = true;
|
||||||
else switchLight(R_LED1, 0, false);//lStat1 = false;
|
else switchLight(R_LED1, 0, false);//lStat1 = false;
|
||||||
}
|
}
|
||||||
if(strcmp(topic, "/home/midroom/lamp2_set") == 0){
|
if(strcmp(topic, TOPIC"midroom/lamp2_set") == 0){
|
||||||
if (strncmp("1", payload, 1) == 0) switchLight(R_LED2, 1, false);//lStat2 = true;
|
if (strncmp("1", payload, 1) == 0) switchLight(R_LED2, 1, false);//lStat2 = true;
|
||||||
else switchLight(R_LED2, 0, false);//lStat2 = false;
|
else switchLight(R_LED2, 0, false);//lStat2 = false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,8 @@
|
|||||||
|
|
||||||
const char* ssid = "wf-home";
|
const char* ssid = "wf-home";
|
||||||
const char* password = "0ndthnrf";
|
const char* password = "0ndthnrf";
|
||||||
const char* mqtt_server = "192.168.1.250";
|
const char* mqtt_server = "192.168.1.111";
|
||||||
|
#define TOPIC "home/"
|
||||||
|
|
||||||
AsyncMqttClient mqttClient;
|
AsyncMqttClient mqttClient;
|
||||||
Ticker mqttReconnectTimer;
|
Ticker mqttReconnectTimer;
|
||||||
@@ -123,7 +124,7 @@ bool switchLight(uint8_t nLamp, int state, bool pub)
|
|||||||
digitalWrite(nLamp, state);
|
digitalWrite(nLamp, state);
|
||||||
EEPROM.put(nLamp == R_LED1 ? 0 : 1, state);
|
EEPROM.put(nLamp == R_LED1 ? 0 : 1, state);
|
||||||
EEPROM.commit();
|
EEPROM.commit();
|
||||||
String topic = "/home/smallroom/lamp";
|
String topic = TOPIC"smallroom/lamp";
|
||||||
char n = nLamp == R_LED1 ? '1' : '2';
|
char n = nLamp == R_LED1 ? '1' : '2';
|
||||||
//if (pub)
|
//if (pub)
|
||||||
mqttClient.publish(String(topic + n).c_str(), 1, false, state ? "1" : "0");
|
mqttClient.publish(String(topic + n).c_str(), 1, false, state ? "1" : "0");
|
||||||
@@ -154,12 +155,12 @@ void onWifiDisconnect(const WiFiEventStationModeDisconnected& event) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void onMqttConnect(bool sessionPresent) {
|
void onMqttConnect(bool sessionPresent) {
|
||||||
mqttClient.publish("/home/smallroom/lamp1", 1, false, digitalRead(R_LED1) == 1 ? "1" : "0");
|
mqttClient.publish(TOPIC"smallroom/lamp1", 1, false, digitalRead(R_LED1) == 1 ? "1" : "0");
|
||||||
mqttClient.publish("/home/smallroom/lamp2", 1, false, digitalRead(R_LED2) == 1 ? "1" : "0");
|
mqttClient.publish(TOPIC"smallroom/lamp2", 1, false, digitalRead(R_LED2) == 1 ? "1" : "0");
|
||||||
mqttClient.publish("/home/smallroom/lamp1_set", 1, false, digitalRead(R_LED1) == 1 ? "1" : "0");
|
mqttClient.publish(TOPIC"smallroom/lamp1_set", 1, false, digitalRead(R_LED1) == 1 ? "1" : "0");
|
||||||
mqttClient.publish("/home/smallroom/lamp2_set", 1, false, digitalRead(R_LED2) == 1 ? "1" : "0");
|
mqttClient.publish(TOPIC"smallroom/lamp2_set", 1, false, digitalRead(R_LED2) == 1 ? "1" : "0");
|
||||||
mqttClient.subscribe("/home/smallroom/lamp1_set", 1);
|
mqttClient.subscribe(TOPIC"smallroom/lamp1_set", 1);
|
||||||
mqttClient.subscribe("/home/smallroom/lamp2_set", 1);
|
mqttClient.subscribe(TOPIC"smallroom/lamp2_set", 1);
|
||||||
digitalWrite(B_LED, LOW);
|
digitalWrite(B_LED, LOW);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -171,11 +172,11 @@ void onMqttDisconnect(AsyncMqttClientDisconnectReason reason) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties properties, size_t len, size_t index, size_t total) {
|
void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties properties, size_t len, size_t index, size_t total) {
|
||||||
if(strcmp(topic, "/home/smallroom/lamp1_set") == 0){
|
if(strcmp(topic, TOPIC"smallroom/lamp1_set") == 0){
|
||||||
if (strncmp("1", payload, 1) == 0) switchLight(R_LED1, 1, false);//lStat1 = true;
|
if (strncmp("1", payload, 1) == 0) switchLight(R_LED1, 1, false);//lStat1 = true;
|
||||||
else switchLight(R_LED1, 0, false);//lStat1 = false;
|
else switchLight(R_LED1, 0, false);//lStat1 = false;
|
||||||
}
|
}
|
||||||
if(strcmp(topic, "/home/smallroom/lamp2_set") == 0){
|
if(strcmp(topic, TOPIC"smallroom/lamp2_set") == 0){
|
||||||
if (strncmp("1", payload, 1) == 0) switchLight(R_LED2, 1, false);//lStat2 = true;
|
if (strncmp("1", payload, 1) == 0) switchLight(R_LED2, 1, false);//lStat2 = true;
|
||||||
else switchLight(R_LED2, 0, false);//lStat2 = false;
|
else switchLight(R_LED2, 0, false);//lStat2 = false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,9 @@
|
|||||||
#define WIFI_SSID "wf-home"
|
#define WIFI_SSID "wf-home"
|
||||||
#define WIFI_PASSWORD "0ndthnrf"
|
#define WIFI_PASSWORD "0ndthnrf"
|
||||||
#define MY_HOSTNAME "ESP8266_GW"
|
#define MY_HOSTNAME "ESP8266_GW"
|
||||||
#define MQTT_SERV "192.168.1.250"
|
//#define MQTT_SERV "192.168.1.250"
|
||||||
|
#define MQTT_SERV "192.168.1.111"
|
||||||
|
#define TOPIC "home/"
|
||||||
|
|
||||||
#define MAX_PAGE (4)
|
#define MAX_PAGE (4)
|
||||||
#define MAX_HSP (99)
|
#define MAX_HSP (99)
|
||||||
@@ -68,7 +70,8 @@ Ticker mqttReconnectTimer;
|
|||||||
WiFiEventHandler wifiConnectHandler;
|
WiFiEventHandler wifiConnectHandler;
|
||||||
WiFiEventHandler wifiDisconnectHandler;
|
WiFiEventHandler wifiDisconnectHandler;
|
||||||
Ticker wifiReconnectTimer;
|
Ticker wifiReconnectTimer;
|
||||||
const char* mqtt_server = "192.168.1.250";
|
//const char* mqtt_server = "192.168.1.250";
|
||||||
|
const char* mqtt_server = "192.168.1.111";
|
||||||
char v[12];
|
char v[12];
|
||||||
|
|
||||||
struct contacts
|
struct contacts
|
||||||
|
|||||||
@@ -185,7 +185,7 @@ void loop()
|
|||||||
if (!vvannaSent1){
|
if (!vvannaSent1){
|
||||||
vvannaSent1 = true;
|
vvannaSent1 = true;
|
||||||
vvannaSent0 = false;
|
vvannaSent0 = false;
|
||||||
mqttClient.publish("/home/vt/vvanna", 1, false, "1");
|
mqttClient.publish(TOPIC"vt/vvanna", 1, false, "1");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(hum <= wUstavki.hSP){
|
else if(hum <= wUstavki.hSP){
|
||||||
@@ -193,7 +193,7 @@ void loop()
|
|||||||
if (!vvannaSent0){
|
if (!vvannaSent0){
|
||||||
vvannaSent0 = true;
|
vvannaSent0 = true;
|
||||||
vvannaSent1 = false;
|
vvannaSent1 = false;
|
||||||
mqttClient.publish("/home/vt/vvanna", 1, false, "0");
|
mqttClient.publish(TOPIC"vt/vvanna", 1, false, "0");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} // loop ()
|
} // loop ()
|
||||||
@@ -229,7 +229,7 @@ void buttLongClick()
|
|||||||
lcd.setBacklight(255);
|
lcd.setBacklight(255);
|
||||||
if (page == 3){
|
if (page == 3){
|
||||||
pcf.write(LED_RED, 1);
|
pcf.write(LED_RED, 1);
|
||||||
mqttClient.publish("/home/vt/flood", 1, false, "0");
|
mqttClient.publish(TOPIC"vt/flood", 1, false, "0");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (modeEdit == 0){
|
if (modeEdit == 0){
|
||||||
@@ -272,7 +272,7 @@ void chkCount()
|
|||||||
wCounter.QC += 0.01f;
|
wCounter.QC += 0.01f;
|
||||||
ee.writeBlock(0, (uint8_t*)&wCounter, sizeof(wCounter));
|
ee.writeBlock(0, (uint8_t*)&wCounter, sizeof(wCounter));
|
||||||
sprintf(v, "%.2f", wCounter.QC);
|
sprintf(v, "%.2f", wCounter.QC);
|
||||||
mqttClient.publish("/home/vt/qcold", 1, false, v);
|
mqttClient.publish(TOPIC"vt/qcold", 1, false, v);
|
||||||
Serial.printf("QCold=%f\n", wCounter.QC);
|
Serial.printf("QCold=%f\n", wCounter.QC);
|
||||||
//pcf.write(7, led);
|
//pcf.write(7, led);
|
||||||
//led = !led;
|
//led = !led;
|
||||||
@@ -281,13 +281,13 @@ void chkCount()
|
|||||||
wCounter.QH += 0.01f;
|
wCounter.QH += 0.01f;
|
||||||
ee.writeBlock(0, (uint8_t*)&wCounter, sizeof(wCounter));
|
ee.writeBlock(0, (uint8_t*)&wCounter, sizeof(wCounter));
|
||||||
sprintf(v, "%.2f", wCounter.QH);
|
sprintf(v, "%.2f", wCounter.QH);
|
||||||
mqttClient.publish("/home/vt/qhot", 1, false, v);
|
mqttClient.publish(TOPIC"vt/qhot", 1, false, v);
|
||||||
Serial.printf("QHot=%f\n", wCounter.QH);
|
Serial.printf("QHot=%f\n", wCounter.QH);
|
||||||
//pcf.write(7, led);
|
//pcf.write(7, led);
|
||||||
//led = !led;
|
//led = !led;
|
||||||
}
|
}
|
||||||
if(c_flood.chngDown((b >> FLOOD) & 0x01)){
|
if(c_flood.chngDown((b >> FLOOD) & 0x01)){
|
||||||
mqttClient.publish("/home/vt/flood", 1, false, "1");
|
mqttClient.publish(TOPIC"vt/flood", 1, false, "1");
|
||||||
pcf.write(LED_RED, 0);
|
pcf.write(LED_RED, 0);
|
||||||
//Send MQTT Flood
|
//Send MQTT Flood
|
||||||
Serial.printf("Flood\n");
|
Serial.printf("Flood\n");
|
||||||
@@ -495,7 +495,7 @@ void chkLight()
|
|||||||
#endif
|
#endif
|
||||||
lOn = true;
|
lOn = true;
|
||||||
digitalWrite(VENT_TUAL, LOW);
|
digitalWrite(VENT_TUAL, LOW);
|
||||||
mqttClient.publish("/home/vt/vtual", 1, false, "1");
|
mqttClient.publish(TOPIC"vt/vtual", 1, false, "1");
|
||||||
//sec = 0;
|
//sec = 0;
|
||||||
}
|
}
|
||||||
if(lOn) sec = 0;
|
if(lOn) sec = 0;
|
||||||
@@ -516,7 +516,7 @@ void chkLight()
|
|||||||
#endif
|
#endif
|
||||||
lOn = false;
|
lOn = false;
|
||||||
digitalWrite(VENT_TUAL, HIGH);
|
digitalWrite(VENT_TUAL, HIGH);
|
||||||
mqttClient.publish("/home/vt/vtual", 1, false, "0");
|
mqttClient.publish(TOPIC"vt/vtual", 1, false, "0");
|
||||||
sec = 0;
|
sec = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -567,30 +567,30 @@ void onMqttConnect(bool sessionPresent) {
|
|||||||
// //Serial1.println(packetIdSub);
|
// //Serial1.println(packetIdSub);
|
||||||
//packetIdSub =
|
//packetIdSub =
|
||||||
sprintf(v, "%.2f", wCounter.QH);
|
sprintf(v, "%.2f", wCounter.QH);
|
||||||
mqttClient.publish("/home/vt/qhot", 1, false, v);
|
mqttClient.publish(TOPIC"vt/qhot", 1, false, v);
|
||||||
mqttClient.publish("/home/vt/qhot_set", 1, false, v);
|
mqttClient.publish(TOPIC"vt/qhot_set", 1, false, v);
|
||||||
sprintf(v, "%.2f", wCounter.QC);
|
sprintf(v, "%.2f", wCounter.QC);
|
||||||
mqttClient.publish("/home/vt/qcold", 1, false, v);
|
mqttClient.publish(TOPIC"vt/qcold", 1, false, v);
|
||||||
mqttClient.publish("/home/vt/qcold_set", 1, false, v);
|
mqttClient.publish(TOPIC"vt/qcold_set", 1, false, v);
|
||||||
itoa(wUstavki.hDB, v, 10);
|
itoa(wUstavki.hDB, v, 10);
|
||||||
mqttClient.publish("/home/vt/hdb", 1, false, v);
|
mqttClient.publish(TOPIC"vt/hdb", 1, false, v);
|
||||||
itoa(wUstavki.hSP, v, 10);
|
itoa(wUstavki.hSP, v, 10);
|
||||||
mqttClient.publish("/home/vt/hsp", 1, false, v);
|
mqttClient.publish(TOPIC"vt/hsp", 1, false, v);
|
||||||
itoa(ventUst.tWork, v, 10);
|
itoa(ventUst.tWork, v, 10);
|
||||||
mqttClient.publish("/home/vt/twork", 1, false, v);
|
mqttClient.publish(TOPIC"vt/twork", 1, false, v);
|
||||||
itoa(ventUst.tPause, v, 10);
|
itoa(ventUst.tPause, v, 10);
|
||||||
mqttClient.publish("/home/vt/tpause", 1, false, v);
|
mqttClient.publish(TOPIC"vt/tpause", 1, false, v);
|
||||||
mqttClient.subscribe("/home/vt/qhot_set", 1);
|
mqttClient.subscribe(TOPIC"vt/qhot_set", 1);
|
||||||
mqttClient.subscribe("/home/vt/qcold_set", 1);
|
mqttClient.subscribe(TOPIC"vt/qcold_set", 1);
|
||||||
mqttClient.subscribe("/home/vt/tpause_set", 1);
|
mqttClient.subscribe(TOPIC"vt/tpause_set", 1);
|
||||||
mqttClient.subscribe("/home/vt/twork_set", 1);
|
mqttClient.subscribe(TOPIC"vt/twork_set", 1);
|
||||||
mqttClient.subscribe("/home/vt/hsp_set", 1);
|
mqttClient.subscribe(TOPIC"vt/hsp_set", 1);
|
||||||
mqttClient.subscribe("/home/vt/hdb_set", 1);
|
mqttClient.subscribe(TOPIC"vt/hdb_set", 1);
|
||||||
mqttClient.subscribe("/home/vt/flood", 1);
|
mqttClient.subscribe(TOPIC"vt/flood", 1);
|
||||||
////Serial1.print("Subscribing Lamp2, packetId: ");
|
////Serial1.print("Subscribing Lamp2, packetId: ");
|
||||||
////Serial1.println(packetIdSub);
|
////Serial1.println(packetIdSub);
|
||||||
////Serial1.println("Publishing at Lamp 1");
|
////Serial1.println("Publishing at Lamp 1");
|
||||||
//mqttClient.publish("/home/kor/lamp2", 1, false, lStat2 ? "1" : "0");
|
//mqttClient.publish(TOPIC"kor/lamp2", 1, false, lStat2 ? "1" : "0");
|
||||||
////Serial1.println("Publishing at Lamp 2");
|
////Serial1.println("Publishing at Lamp 2");
|
||||||
|
|
||||||
pcf.write(LED_BLUE, 0);
|
pcf.write(LED_BLUE, 0);
|
||||||
@@ -621,43 +621,43 @@ void onMqttUnsubscribe(uint16_t packetId) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties properties, size_t len, size_t index, size_t total) {
|
void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties properties, size_t len, size_t index, size_t total) {
|
||||||
if(strcmp(topic, "/home/vt/qhot_set") == 0){
|
if(strcmp(topic, TOPIC"vt/qhot_set") == 0){
|
||||||
wCounter.QH = atof(payload);
|
wCounter.QH = atof(payload);
|
||||||
ee.writeBlock(0, (uint8_t*)&wCounter, sizeof(wCounter));
|
ee.writeBlock(0, (uint8_t*)&wCounter, sizeof(wCounter));
|
||||||
sprintf(v, "%.2f", wCounter.QH);
|
sprintf(v, "%.2f", wCounter.QH);
|
||||||
mqttClient.publish("/home/vt/qhot", 1, false, v);
|
mqttClient.publish(TOPIC"vt/qhot", 1, false, v);
|
||||||
} else
|
} else
|
||||||
if(strcmp(topic, "/home/vt/qcold_set") == 0){
|
if(strcmp(topic, TOPIC"vt/qcold_set") == 0){
|
||||||
wCounter.QC = atof(payload);
|
wCounter.QC = atof(payload);
|
||||||
ee.writeBlock(0, (uint8_t*)&wCounter, sizeof(wCounter));
|
ee.writeBlock(0, (uint8_t*)&wCounter, sizeof(wCounter));
|
||||||
sprintf(v, "%.2f", wCounter.QC);
|
sprintf(v, "%.2f", wCounter.QC);
|
||||||
mqttClient.publish("/home/vt/qcold", 1, false, v);
|
mqttClient.publish(TOPIC"vt/qcold", 1, false, v);
|
||||||
} else
|
} else
|
||||||
if(strcmp(topic, "/home/vt/tpause_set") == 0){
|
if(strcmp(topic, TOPIC"vt/tpause_set") == 0){
|
||||||
ventUst.tPause = atoi(payload);
|
ventUst.tPause = atoi(payload);
|
||||||
ee.writeBlock(16, (uint8_t*)&ventUst, sizeof(wCounter));
|
ee.writeBlock(16, (uint8_t*)&ventUst, sizeof(wCounter));
|
||||||
itoa(ventUst.tPause, v, 10);
|
itoa(ventUst.tPause, v, 10);
|
||||||
mqttClient.publish("/home/vt/tpause", 1, false, v);
|
mqttClient.publish(TOPIC"vt/tpause", 1, false, v);
|
||||||
} else
|
} else
|
||||||
if(strcmp(topic, "/home/vt/twork_set") == 0){
|
if(strcmp(topic, TOPIC"vt/twork_set") == 0){
|
||||||
ventUst.tWork = atoi(payload);
|
ventUst.tWork = atoi(payload);
|
||||||
ee.writeBlock(16, (uint8_t*)&ventUst, sizeof(wCounter));
|
ee.writeBlock(16, (uint8_t*)&ventUst, sizeof(wCounter));
|
||||||
itoa(ventUst.tWork, v, 10);
|
itoa(ventUst.tWork, v, 10);
|
||||||
mqttClient.publish("/home/vt/twork", 1, false, v);
|
mqttClient.publish(TOPIC"vt/twork", 1, false, v);
|
||||||
} else
|
} else
|
||||||
if(strcmp(topic, "/home/vt/hsp_set") == 0){
|
if(strcmp(topic, TOPIC"vt/hsp_set") == 0){
|
||||||
wUstavki.hSP = atoi(payload);
|
wUstavki.hSP = atoi(payload);
|
||||||
ee.writeBlock(8, (uint8_t*)&wUstavki, sizeof(wCounter));
|
ee.writeBlock(8, (uint8_t*)&wUstavki, sizeof(wCounter));
|
||||||
itoa(wUstavki.hSP, v, 10);
|
itoa(wUstavki.hSP, v, 10);
|
||||||
mqttClient.publish("/home/vt/hsp", 1, false, v);
|
mqttClient.publish(TOPIC"vt/hsp", 1, false, v);
|
||||||
} else
|
} else
|
||||||
if(strcmp(topic, "/home/vt/hdb_set") == 0){
|
if(strcmp(topic, TOPIC"vt/hdb_set") == 0){
|
||||||
wUstavki.hDB = atoi(payload);
|
wUstavki.hDB = atoi(payload);
|
||||||
ee.writeBlock(8, (uint8_t*)&wUstavki, sizeof(wCounter));
|
ee.writeBlock(8, (uint8_t*)&wUstavki, sizeof(wCounter));
|
||||||
itoa(wUstavki.hDB, v, 10);
|
itoa(wUstavki.hDB, v, 10);
|
||||||
mqttClient.publish("/home/vt/hdb", 1, false, v);
|
mqttClient.publish(TOPIC"vt/hdb", 1, false, v);
|
||||||
} else
|
} else
|
||||||
if(strcmp(topic, "/home/vt/flood") == 0){
|
if(strcmp(topic, TOPIC"vt/flood") == 0){
|
||||||
pcf.write(LED_RED, !atoi(payload));
|
pcf.write(LED_RED, !atoi(payload));
|
||||||
c_flood = atoi(payload);
|
c_flood = atoi(payload);
|
||||||
}
|
}
|
||||||
@@ -672,15 +672,15 @@ void onMqttPublish(uint16_t packetId) {
|
|||||||
|
|
||||||
void sendData(){
|
void sendData(){
|
||||||
sprintf(v, "%.2f", temp);
|
sprintf(v, "%.2f", temp);
|
||||||
mqttClient.publish("/home/vt/vtemp", 1, false, v);
|
mqttClient.publish(TOPIC"vt/vtemp", 1, false, v);
|
||||||
sprintf(v, "%.2f", hum);
|
sprintf(v, "%.2f", hum);
|
||||||
mqttClient.publish("/home/vt/vhum", 1, false, v);
|
mqttClient.publish(TOPIC"vt/vhum", 1, false, v);
|
||||||
sprintf(v, "%.2f", cTemp);
|
sprintf(v, "%.2f", cTemp);
|
||||||
mqttClient.publish("/home/vt/tcold", 1, false, v);
|
mqttClient.publish(TOPIC"vt/tcold", 1, false, v);
|
||||||
sprintf(v, "%.2f", hTemp);
|
sprintf(v, "%.2f", hTemp);
|
||||||
mqttClient.publish("/home/vt/thot", 1, false, v);
|
mqttClient.publish(TOPIC"vt/thot", 1, false, v);
|
||||||
sprintf(v, "%.2f", mws);
|
sprintf(v, "%.2f", mws);
|
||||||
mqttClient.publish("/home/vt/wpress", 1, false, v);
|
mqttClient.publish(TOPIC"vt/wpress", 1, false, v);
|
||||||
Serial.print("millis: "); Serial.print(millis());
|
Serial.print("millis: "); Serial.print(millis());
|
||||||
Serial.println(" Sent data");
|
Serial.println(" Sent data");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user