mirror of
https://github.com/rstrouse/ESPSomfy-RTS.git
synced 2025-12-13 11:02:12 +01:00
Coding for sun and wind flag processing v1.7.0
* Added MQTT control for sunFlag and tiltTarget. * Move my position if it is set per sun sensor instructions. * Add sun/wind states to persistence. * Bump restore file version
This commit is contained in:
parent
883dd63d3f
commit
2ecc0de36e
8 changed files with 21 additions and 8 deletions
13
MQTT.cpp
13
MQTT.cpp
|
|
@ -78,6 +78,10 @@ void MQTTClass::receive(const char *topic, byte*payload, uint32_t length) {
|
|||
if(val >= 0 && val <= 100)
|
||||
shade->moveToTarget(atoi(value));
|
||||
}
|
||||
if(strncmp(command, "tiltTarget", sizeof(command)) == 0) {
|
||||
if(val >= 0 && val <= 100)
|
||||
shade->moveToTiltTarget(atoi(value));
|
||||
}
|
||||
else if(strncmp(command, "direction", sizeof(command)) == 0) {
|
||||
if(val < 0)
|
||||
shade->sendCommand(somfy_commands::Up);
|
||||
|
|
@ -90,6 +94,10 @@ void MQTTClass::receive(const char *topic, byte*payload, uint32_t length) {
|
|||
if(val >= 0 && val <= 100)
|
||||
shade->setMyPosition(val);
|
||||
}
|
||||
else if(strncmp(command, "sunFlag", sizeof(command)) == 0) {
|
||||
if(val >= 0) shade->sendCommand(somfy_commands::SunFlag);
|
||||
else shade->sendCommand(somfy_commands::Flag);
|
||||
}
|
||||
}
|
||||
}
|
||||
bool MQTTClass::connect() {
|
||||
|
|
@ -110,8 +118,10 @@ bool MQTTClass::connect() {
|
|||
Serial.println(this->clientId);
|
||||
somfy.publish();
|
||||
this->subscribe("shades/+/target/set");
|
||||
this->subscribe("shades/+/tiltTarget/set");
|
||||
this->subscribe("shades/+/direction/set");
|
||||
this->subscribe("shades/+/mypos/set");
|
||||
this->subscribe("shades/+/sunFlag/set");
|
||||
mqttClient.setCallback(MQTTClass::receive);
|
||||
this->lastConnect = millis();
|
||||
return true;
|
||||
|
|
@ -132,6 +142,9 @@ bool MQTTClass::disconnect() {
|
|||
if(mqttClient.connected()) {
|
||||
this->unsubscribe("shades/+/target/set");
|
||||
this->unsubscribe("shades/+/direction/set");
|
||||
this->unsubscribe("shades/+/tiltTarget/set");
|
||||
this->unsubscribe("shades/+/mypos/set");
|
||||
this->unsubscribe("shades/+/sunFlag/set");
|
||||
mqttClient.disconnect();
|
||||
}
|
||||
return true;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue