Skip to content

Commit

Permalink
remote control update
Browse files Browse the repository at this point in the history
  • Loading branch information
jeecrypt committed Sep 22, 2019
1 parent 7893063 commit 5bf7ade
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
1 change: 1 addition & 0 deletions JeeUI2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ void jeeui2::var(String key, String value)
return;
}
}
if(rc)publish("jee/set/" + key, value, true);
if(dbg)Serial.print("WRITE: ");
if(dbg)Serial.println("key (" + key + String(F(") value (")) + value.substring(0, 15) + String(F(") RAM: ")) + ESP.getFreeHeap());
cfg[key] = value;
Expand Down
2 changes: 2 additions & 0 deletions JeeUI2.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ class jeeui2

bool dbg = false;

bool rc;


void connectToMqtt();
void onMqttConnect();
Expand Down
18 changes: 11 additions & 7 deletions mqtt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ String jeeui2::id(String topic){
bool mqtt_connected = false;
bool mqtt_connect = false;





void jeeui2::onMqttSubscribe(uint16_t packetId, uint8_t qos) {

}
Expand Down Expand Up @@ -61,7 +57,7 @@ void jeeui2::mqtt(String pref, String host, int port, String user, String pass,
mqtt_update();

_t_prf_current = m_pref;
if (remotecontrol) _t_remotecontrol = true;
if (remotecontrol) _t_remotecontrol = true; rc = true;
mqt = mqttFunction;

}
Expand Down Expand Up @@ -219,8 +215,11 @@ void jeeui2::remControl(){
}
}
else {
var(_t_tpc_current, _t_pld_current);
as();
if(param(_t_tpc_current) != _t_pld_current){
var(_t_tpc_current, _t_pld_current);
as();
}

}
}
_t_tpc_current = "";
Expand Down Expand Up @@ -261,6 +260,11 @@ void jeeui2::publish(String topic, String payload, bool retained){
mqttClient.publish(id(topic).c_str(), 0, retained, payload.c_str());
}

void jeeui2::publish(String topic, String payload){
if (!connected || !mqtt_enable) return;
mqttClient.publish(id(topic).c_str(), 0, false, payload.c_str());
}

void jeeui2::pub_mqtt(String key, String value){
if(!_t_remotecontrol) return;
publish(key, value, true);
Expand Down

0 comments on commit 5bf7ade

Please sign in to comment.