blakadder / berry-drivers

MicRadar and Seeed Studio mmWave sensor drivers for Tasmota written in Berry
GNU General Public License v3.0
6 stars 0 forks source link

MQTT messages published without full topic #1

Open Goose66 opened 9 months ago

Goose66 commented 9 months ago

MQTT messages are being published without considering the configured "Full Topic". For example, in the R24D driver, in parse_config() method, the topic for the CONFIG messages is built like this:

    # print("Parsed message:", result)
    # check if word exists in buffer then update the value if needed, won't publish anything if the value doesn't change
    if self.cfg_buffer.find(cw) != nil 
      if self.cfg_buffer[cw].find(field)
        self.cfg_buffer[cw].setitem(field,data)
        # print(f"Config Buffer update {field} with {data}")  
        var pubtopic = "stat/" + topic + "/CONFIG"
        var mp = f"{{\"{self.sensorname}\":{json.dump(result)}}}"
        mqtt.publish(pubtopic, mp, false)
      end
    else
      self.publish2log(f"{field}: {data}", 2)
    end

resulting in messages published to "stat/\<device ID>/CONFIG". But if the full topic is configured to, e.g., "tasmota/%prefix%/%topic%", then any listeners for "tasmota/stat/\<device ID>/CONFIG" messages will not receive the messages.

blakadder commented 9 months ago

yes, that's why you need to change the relevant lines for your setup

Goose66 commented 9 months ago

Ok. In case it's helpful for future users, here are the changes we made to the r24d.be file:

  1. After var topic = tasmota.cmd('Status ', true)['Status']['Topic'] we added the following line: var fulltopic = tasmota.cmd('FullTopic ', true)['FullTopic']
  2. We changed the three instances of var pubtopic = to build from the fulltopic. E.g., we changed: var pubtopic = "stat/" + topic + "/CONFIG" to: var pubtopic = string.replace(string.replace(fulltopic, "%topic%", topic), "%prefix%", "stat") + "CONFIG"