New iobroker
This commit is contained in:
@@ -24,7 +24,8 @@ leds lBlue(LED_BLUE, 200);
|
||||
|
||||
const char* ssid = "wf-home";
|
||||
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;
|
||||
bool izm = false;
|
||||
@@ -110,13 +111,13 @@ void loop() {
|
||||
mv = digitalRead(MOVE_SENS);
|
||||
if(mv != oldmv){
|
||||
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(((adc < delta) && !lsSent) || ((adc >= (delta + 5)) && !lbSent)){
|
||||
char strFVal[6];
|
||||
itoa(adc, strFVal, 10);
|
||||
client.publish("/home/smallroom/light", strFVal);
|
||||
client.publish(TOPIC"smallroom/light", strFVal);
|
||||
oldadc = adc;
|
||||
if(adc < delta) {lsSent = true; lbSent = false;}
|
||||
else {lbSent = true; lsSent = false;}
|
||||
@@ -151,8 +152,8 @@ void reconnect() {
|
||||
// можно подписаться не только на один, а на несколько топиков
|
||||
char v[6];
|
||||
itoa(delta, v, 10);
|
||||
client.publish("/home/smallroom/ldelta", v);
|
||||
client.subscribe("/home/smallroom/ldelta");
|
||||
client.publish(TOPIC"smallroom/ldelta", v);
|
||||
client.subscribe(TOPIC"smallroom/ldelta");
|
||||
} else {
|
||||
//Serial.print("failed, rc="); // "подключение не удалось"
|
||||
//Serial.print(client.state());
|
||||
@@ -170,18 +171,18 @@ void publishMin()
|
||||
//digitalWrite(LED_BLUE, HIGH);
|
||||
if(!isnan(temp)){
|
||||
dtostrf(temp, 6, 1, strFVal);
|
||||
client.publish("/home/smallroom/temp", strFVal);
|
||||
client.publish(TOPIC"smallroom/temp", strFVal);
|
||||
}
|
||||
if(!isnan(rel_hum)){
|
||||
dtostrf(rel_hum, 6, 1, strFVal);
|
||||
client.publish("/home/smallroom/rel_hum", strFVal);
|
||||
client.publish(TOPIC"smallroom/rel_hum", strFVal);
|
||||
}
|
||||
ultoa(adc, strFVal, 10);
|
||||
client.publish("/home/smallroom/light", strFVal);
|
||||
client.publish(TOPIC"smallroom/light", strFVal);
|
||||
ultoa(cRun, strFVal, 10);
|
||||
client.publish("/home/smallroom/millis", strFVal);
|
||||
client.publish(TOPIC"smallroom/millis", strFVal);
|
||||
itoa(delta, strFVal, 10);
|
||||
client.publish("/home/smallroom/ldelta", strFVal);
|
||||
client.publish(TOPIC"smallroom/ldelta", strFVal);
|
||||
//digitalWrite(LED_BLUE, LOW);
|
||||
}
|
||||
}
|
||||
@@ -213,7 +214,7 @@ void publishSec()
|
||||
}
|
||||
|
||||
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';
|
||||
String pl = String((char*)payload);
|
||||
delta = pl.toInt();// atoi((char*)payload);
|
||||
|
||||
Reference in New Issue
Block a user