bertmelis / VitoWiFi

Communicate with Viessmann boilers using the optolink for ESP8266 and ESP32
MIT License
118 stars 39 forks source link

VitoWiFi.readDatapoint() only on MQTT request #74

Closed GnomiBerlin closed 2 years ago

GnomiBerlin commented 2 years ago

Installation specifics Heating type: Vitotronic 200 KW2 Protocol: KW Board: ESP8266 Wemos D1 mini Hardware: own IR components

Question: I want a MQTT update not in a loop but for some values on request only. But it works not as expected?!

Example: if i use below line with all related configurations, I get an MQTT: VITOWIFI/gettimerzirkusa with its value each minute. getTimerZirkuSa.setCallback(DP8TimerCallbackHandler); //fuer Timer

then I added: in the MQTT receiving part, for a new MQTT message "retrievetimerzirkusa" to get the DP "gettimerzirkusa" on request:

if (strcmp(topic, "VITOWIFI/retrievetimerzirkusa") == 0) {
    VitoWiFi.readDatapoint(getTimerZirkuSa);
  }

and mqttClient.subscribe("VITOWIFI/retrievetimerzirkusa", 0);

to get no updates per minute, I took out: //getTimerZirkuSa.setCallback(DP8TimerCallbackHandler); //fuer Timer

What did I not understand?

Thanks.

bertmelis commented 2 years ago

It it possible to share the whole code (remove credentials)?

GnomiBerlin commented 2 years ago

temporary dropbox exchange deleted again

GnomiBerlin commented 2 years ago

I found a way for my problem.

I used the group identifier for "synchronize" and "on_request" datapoints. e.g.:

DPTemp getTempA("gettempa", "synchronize", 0x0800);               //Aussentemperatur
DPStat getAlarmStatus("getalarmstatus", "synchronize", 0x0847);   //Sammelstoerung Ja/Nein  0x0A82 0x7579
DP8Timer getAnlagenzeit("getanlagenzeit", "synchronize", 0x088E);   //Anlagenzeit  DPHours 0x088E DPCount
DP8Timer getTimerZirkuSa("gettimerzirkusa", "on_request", 0x2228);   //Zirkulationspumpe Zeiten Samstag
DP8Timer setTimerZirkuSa("settimerzirkusa", "on_request", 0x2228);   //Zirkulationspumpe Zeiten Samstag
...

in the loop part I changed VitoWiFi.readAll() --> VitoWiFi.readGroup("synchronize") for all on minute received values:

void loop() {
  if (!bStopVito) {
    VitoWiFi.loop();
    if (updateVitoWiFi && mqttClient.connected()) {
      updateVitoWiFi = false;
      VitoWiFi.readGroup("synchronize");   //VitoWiFi.readAll();
    }
  }
...

for all "on_request" datapoints I added MQTT subscriptions and its handling:

if (strcmp(topic, "VITOWIFI/settimerzirkusa") == 0) {
    uint64_t setTimer = strtoull(payload, NULL, 16);
    DPValue value(setTimer);
    VitoWiFi.writeDatapoint(setTimerZirkuSa, value);   // 06000730160018300000000000000000 = FFFFFFFF93803B30
    VitoWiFi.readDatapoint(getTimerZirkuSa);
  }
  if (strcmp(topic, "VITOWIFI/retrievetimerzirkusa") == 0) {
    uint64_t setTimer = strtoull(payload, NULL, 16);
    DPValue value(setTimer);
    VitoWiFi.readDatapoint(getTimerZirkuSa);
  }

I hope this is clearly described.

Is the idea o.k. or any other ideas? If yes I can close the issue.

bertmelis commented 2 years ago

I don't think there is anything wrong with this way of work.

GnomiBerlin commented 2 years ago

With workaround solved