Mosquitto get data from another MQTT Broker - lollipop camera

Hi, im trying to get data from another MQTT Broker (Lollipop Baby Camera).
Im able to connect to that Broker via MQTT Explorer app with this confifguration:
obrázok
Username and password empty, encryption enabled, cert validation disabled.

Im trying to create mosquitto addon configuration in mosquitto.conf file. I have tried multiple things, but all the time it ends with:

1653175898: Connecting bridge (step 1) lollipop_mqtt (192.168.100.25:1883)
1653175898: Connecting bridge (step 2) lollipop_mqtt (192.168.100.25:1883)
1653175898: Client local.core-mosquitto.lollipop_mqtt closed its connection.

Example of configuration i was trying to use:

connection lollipop_mqtt
address 192.168.100.25:1883
bridge_insecure true
local_username <username>
local_password <password>
topic # in 0 lollipop/ <mainTopicId>/

Can someone help me with that config?

Where exactly are you entering that?

directly into mosquitto.conf file in share/mosquitto folder and i have changed customize in addon configuration to:

active: true
folder: mosquitto

I have solved that:
Export lollipop camera cert

  1. e.g in firefox navigate to camera mqtt server - https://<lollipop camera ip>:1883/
  2. in url bar click on ‘Not secure’
  3. navigate to cert dialog and certification path
  4. open lollipop.camera certificate
  5. save that lollipop.camera certificate as Base64 encoded cert

  6. copy that cert to e.g. \share\mosquitto\certs\ . My cert got name lollipop.crt

Change mosquitto addon config

  1. change in configuration customize section
    active: true

  2. create mosquitto.conf in \share\mosquitto\ (location is specified in that configuration customize section)

  3. paste this to mosquitto.conf and change to your ip, name, password, cert file location and topic.

connection lollipop_mqtt
address <lollipop camera ip>:1883
bridge_insecure true
notifications false
try_private false
bridge_cafile /share/mosquitto/certs/lollipop.crt
local_username <mqtt username>
local_password <mqtt password>
topic # in 0 lollipop/ <main camera topic>/
  1. restart mosquitto addon in hassio

And after that you can see in mqtt explorer
obrázok

How to get main camera topic?
You can use MQTT Explorer

  1. connect to lollipop camera (change ip to your lollipop camera ip):
    obrázok
    connect and you can see your main topic (some characters) here:
    obrázok

Source:
I was using this blog to get needed information: https://www.lafois.com/2022/02/04/lollipop-camera-reverse-engineering/
On that blog are steps how to get video stream into e.g. hassio.

mosquitto.conf documentation: https://mosquitto.org/man/mosquitto-conf-5.html

2 Likes

Hi - I’m trying to set this up. Can you explain how to get this into home assistant? I have followed the steps to get to this point but I don’t know how to set up sensors to show up in home assistant.
Thanks!

Hi, have a look on this:

this is sensor configuration for noise:

mqtt:
  sensor:
    - name: Lollipop noise
      state_topic: "lollipop/liveNote"
      value_template: "{{ value_json.result.noise | round(1) }}"

there was change of this config in latest release, so when you are not on 2022.06 configuration looks little bit different. You can also have different topic in ‘state_topic’.

Noise like this is this not best sensor, because its updating every second, so it can store a lot values in database. I need to change it to ok/notOK value in that template. But you can create sensors of other topics like that.

got it thank you! Super helpful.
I’ve seen that, when there is a noise or movement, lollipop sends a preNotify channel. I’m thinking of using that instead to get values and possibly have time from last event or something. Bit complex and I’m still working my way through HA configs and how to set everything up.

@caear1987 is this still working for you? I cannot seem to get my mqtt broker to connect to lollipop.
I keep getting:
Connecting bridge lollipop_mqtt (192.168.1.208:1883)
but it doesn’t seem to connect and I cannot get any other logs / details.

I can connect directly via mqtt broker to the lollipop and see that it is publishing fine. I also have the certificate included etc per above. this was working fine but appears to have stopped working and unclear why.

Any ideas?

You can increase your mosquitto logging.

I have this in my mosquitto.conf file:

log_dest file /mosquitto/log/mosquitto.log
log_type all

Am I missing something?

Good question. Perhaps

connection_messages true

see mosquitto.conf man page | Eclipse Mosquitto for all options. Also I am not 100% sure if “all” includes “debug”.

hmmm it’s odd but I’m not getting the bridge showing up at all in the logs. It’s in my mosquitto.conf file and I know it’s picking all of the details from that file so unclear what is wrong.

Here is my mosquitto.conf. Am I doing something wrong? Is there any way to

persistence true
persistence_location /mosquitto/data/
listener 1883
log_dest file /mosquitto/log/mosquitto.log
log_type debug
log_timestamp_format %Y-%m-%dT%H:%M:%S
connection_messages true

## Authentication ##
#allow_anonymous false
password_file /mosquitto/config/password.txt

connection lollipop_mqtt
address 192.168.1.208:1883
bridge_insecure true
notifications false
try_private false
bridge_cafile /mosquitto/certs/lollipop.cer
local_username <username>
local_password <password>
topic # in 0 lollipop/ MElFAuie5o/

I’ve replaced my username and password with and

I probably don’t know enough about mqtt bridging to be any more help.

EDIT: maybe here Mosquitto MQTT Bridge-Usage and Configuration

For me its still working.

I have all files in share/mosquito folder and this link is in .conf file
bridge_cafile /share/mosquitto/certs/lollipop.crt

im not sure, but when you change mosquitto addon config (active true in customize section), .conf file need to be in share\mosquitto folder.
whats your files location?

thanks - I’m running HA core so have MQTT set up in a separate docker instance as opposed to within HA as an add-on (that option doesn’t exist for HA Core)

I can see the bridge in the logs now but it just says:

2022-09-14T21:05:37: Connecting bridge lollipop_mqtt (192.168.1.208:1883)

There’s no other logs and I have it on log_type debug. it’s very odd

ok - so turned out to be an issue w/ the new version of MQTT. I’ve downgraded to 2.0.14 and it works fine… sorry for the trouble

Out of interest, what version gave you trouble.

2.0.15 (latest)
See discussion here: 2.0.15 regression: bridge is not created, with "Expiring client local.xxx due to timeout" · Issue #2634 · eclipse/mosquitto · GitHub

First of all thanks to this thread so I could configure my Home Assistant instance and Mosquitto to receive the messages from the camera.
I went one step further, because I wanted to have a Switch in Home Assistant to enable/disable Sleep Mode on the camera, and guess what: it’s done by MQTT.

The first thing is that with the configuration provided in this thread, the bridge between the two MQTT servers is only one direction (from lollipop to your Mosquitto server). So you receive the messages from the camera to your Mosquitto topic, but if you send messages to that topic, the camera doesn’t receive them.

To enable bi-directional bridge the only thing needed to change is the last line:

topic # in 0 lollipop/ <main camera topic>/

to

topic # both 0 lollipop/ <main camera topic>/

Now the messages sent to the lollipop/ topic in your Mosquitto server will be received by the camera.

Next step we need to configure the Switch by itself, that means: sending the ON and OFF commands to enable and disable the Sleep Mode, and also getting the status of the Sleep Mode. Everything can be achieved using MQTT.

To enable/disable the sleep mode we need to send a json message to the lollipop/camSetting topic.
The message should be something like:

{"method": "camSetting", "params": { "standby_mode": false }, "id": 14}

The id attribute can have any numeric value, the only thing that changes between enabling and disabling sleep mode is the boolean value of standby_mode attribute.

Now we need the status of the Sleep mode, we can get this from the lollipop/cameraStatus/return topic, it publishes messages like:

42["messageReply",{"method":"cameraStatus","id":20,"params":{"appSessionId":null,"info":"owner"},"result":{"status":1,"bindSensor":"","bindSensorName":"","bindStatus":1,"temp":-1000.0,"humidity":-1000.0,"noise":60.159999999999997,"air":-1000.0,"wifiSsid":"MyWiFi","wifiQuality":82.0,"playingMusic":false,"firmwareVersion":"2022041400-g5bca956","standby_mode":false,"privacyMode":false}}]

As you can see, this is something similar to a JSON message, but it’s not exactly a JSON.

Last thing: as the messages on this topic are not retained, we need to publish a message on the lollipop/cameraStatus topic to get the status on the previous topic. The message should be like:

{"params": { "info": "owner" }, "id": 20, "method": "cameraStatus" }

Every time you publish this message to the topic, then it returns the status on the previous topic.

So now that we know how it works, it’s time to configure the Switch!
In your configuration.yaml, you can define it in mqtt/switch section like:

    - name: "Lollipop Sleep Mode"
      state_topic: "lollipop/cameraStatus/return"
      value_template: "{{ 'ON' if (value[18:-1]|from_json).result.standby_mode else 'OFF' }}"
      json_attributes_topic: "lollipop/cameraStatus/return"
      json_attributes_template: "{{ (value[18:-1]|from_json).result|tojson }}"
      command_topic: "lollipop/camSetting"
      state_on: "ON"
      state_off: "OFF"
      payload_off: '{"method": "camSetting", "params": { "standby_mode": false }, "id": 14}'
      payload_on: '{"method": "camSetting", "params": { "standby_mode": true }, "id": 14}'
      unique_id: "lollipop_sleep_mode"

As you can see, the only “tricky” thing is that we need to do a substring of the returned status message to get the json formatted content, everything else is exactly what we talked before.

Only one thing remains: Create an automation to keep the status always updated.

So the triggers for the automation must be two:

  • Home assistant boot
  • MQTT messages on topic lollipop/camSetting/return

The second is because, every time the standby_mode changes (from Home Assistant or from the app), a message is sent to that topic.

No conditions are needed for this automation.

And the action must be publish a MQTT Message to lollipop/cameraStatus as we’ve seen before:

{"params": { "info": "owner" }, "id": 20, "method": "cameraStatus" }

After this, we can reboot Home Assistant and we’ll have a Switch to control the Sleep Mode of the camera.

I hope this can be useful to somebody!

1 Like

@XPatt
Thanks Xavi! This is very interesting. Is there a way to start the music via this method? Do you know what the payload needs to be?