Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix retain flag faulty after VirtualBool switch. #412

Merged
merged 3 commits into from
Aug 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion models/Config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ properties:
type: string
minLength: 1
mqtt_retained:
type: bool
type: boolean
mqtt_user:
type: string
minLength: 1
Expand Down
6 changes: 4 additions & 2 deletions src/app_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,19 +334,21 @@ void config_save_emoncms(bool enable, String server, String node, String apikey,
void
config_save_mqtt(bool enable, int protocol, String server, uint16_t port, String topic, bool retained, String user, String pass, String solar, String grid_ie, String live_pwr, bool reject_unauthorized)
{
uint32_t newflags = flags & ~(CONFIG_SERVICE_MQTT | CONFIG_MQTT_PROTOCOL | CONFIG_MQTT_ALLOW_ANY_CERT);
uint32_t newflags = flags & ~(CONFIG_SERVICE_MQTT | CONFIG_MQTT_PROTOCOL | CONFIG_MQTT_ALLOW_ANY_CERT | CONFIG_MQTT_RETAINED);
if(enable) {
newflags |= CONFIG_SERVICE_MQTT;
}
if(!reject_unauthorized) {
newflags |= CONFIG_MQTT_ALLOW_ANY_CERT;
}
if (retained) {
newflags |= CONFIG_MQTT_RETAINED;
}
newflags |= protocol << 4;

config.set("mqtt_server", server);
config.set("mqtt_port", port);
config.set("mqtt_topic", topic);
config.set("mqtt_retained", retained);
config.set("mqtt_user", user);
config.set("mqtt_pass", pass);
config.set("mqtt_solar", solar);
Expand Down
3 changes: 1 addition & 2 deletions src/app_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ extern String emoncms_fingerprint;
extern String mqtt_server;
extern uint32_t mqtt_port;
extern String mqtt_topic;
extern bool mqtt_retained;
extern String mqtt_user;
extern String mqtt_pass;
extern String mqtt_solar;
Expand Down Expand Up @@ -114,7 +113,7 @@ inline uint8_t config_mqtt_protocol() {
}

inline bool config_mqtt_retained() {
return (flags & CONFIG_MQTT_RETAINED);
return CONFIG_MQTT_RETAINED == (flags & CONFIG_MQTT_RETAINED);
}

inline bool config_mqtt_reject_unauthorized() {
Expand Down
2 changes: 1 addition & 1 deletion src/mqtt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ mqtt_publish(JsonDocument &data) {
String topic = mqtt_topic + "/";
topic += kv.key().c_str();
String val = kv.value().as<String>();
mqttclient.publish(topic, val, mqtt_retained);
mqttclient.publish(topic, val, config_mqtt_retained());
topic = mqtt_topic + "/";
}

Expand Down
2 changes: 1 addition & 1 deletion src/web_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ handleSaveMqtt(MongooseHttpServerRequest *request) {

char tmpStr[200];
snprintf(tmpStr, sizeof(tmpStr), "Saved: %s %s %d %s %s %s %s", mqtt_server.c_str(),
mqtt_topic.c_str(), mqtt_retained, mqtt_user.c_str(), mqtt_pass.c_str(),
mqtt_topic.c_str(), config_mqtt_retained(), mqtt_user.c_str(), mqtt_pass.c_str(),
mqtt_solar.c_str(), mqtt_grid_ie.c_str());
DBUGLN(tmpStr);

Expand Down