Sunoo / homebridge-dafang-mqtt-republish

Exposes Dafang Hacks Features as HomeKit Accessories
BSD 2-Clause "Simplified" License
12 stars 0 forks source link

"Multiple cameras configured" error, can't figure out where they are! #168

Closed jlg89 closed 3 years ago

jlg89 commented 3 years ago

I'm seeing this in my log, and camera MQTT events aren't working:

3/9/2021, 8:17:14 AM [Dafang MQTT] Initializing dafangMqtt platform...
3/9/2021, 8:17:14 AM [Dafang MQTT] Configuring "GarageCam" on topic "yonder-alerts/garagecam".
3/9/2021, 8:17:14 AM [Dafang MQTT] Configuring "GateCam" on topic "yonder-alerts/gatecam".
3/9/2021, 8:17:14 AM [Dafang MQTT] WARNING: Multiple cameras named "GateCam" configured. Only the first loaded will function.
3/9/2021, 8:17:14 AM [Dafang MQTT] WARNING: Multiple cameras with topic "yonder-alerts/gatecam" configured. Only the first loaded will function.
3/9/2021, 8:17:14 AM [Dafang MQTT] There was error with the config so this camera was ignored.
3/9/2021, 8:17:14 AM [Dafang MQTT] Configuring "DoorbellCam" on topic "yonder-alerts/doorbellcam".
3/9/2021, 8:17:14 AM [Dafang MQTT] WARNING: Multiple cameras named "DoorbellCam" configured. Only the first loaded will function.
3/9/2021, 8:17:14 AM [Dafang MQTT] WARNING: Multiple cameras with topic "yonder-alerts/doorbellcam" configured. Only the first loaded will function.
3/9/2021, 8:17:14 AM [Dafang MQTT] There was error with the config so this camera was ignored.
3/9/2021, 8:17:14 AM [Dafang MQTT] Configuring "StudyCam" on topic "yonder-alerts/studycam".
3/9/2021, 8:17:14 AM [Dafang MQTT] WARNING: Multiple cameras named "StudyCam" configured. Only the first loaded will function.
3/9/2021, 8:17:14 AM [Dafang MQTT] WARNING: Multiple cameras with topic "yonder-alerts/studycam" configured. Only the first loaded will function.
3/9/2021, 8:17:14 AM [Dafang MQTT] There was error with the config so this camera was ignored.

Each camera is defined exactly once in the dafangMqtt section and in the Camera-ffmpeg sections of config.json. I've tried deleting everything in the "accessories" directory, and there are no duplicates in the "persist" directory. Where else do I need to look?

Sunoo commented 3 years ago

Please share your config.

The code that generates those warnings only looks at the config, not the persist folders or anything, so something must be configured wrong.

jlg89 commented 3 years ago
{
    "server": {
        "port": 80,
        "origin": "*",
        "autostart": 0,
        "home_setup_id": "X-HM://0023ISYWY8F22",
        "polling_seconds": 5
    },
    "client": {
        "default_route": "status",
        "inactive_logoff": 30,
        "theme": "hoobs-light",
        "locale": "en",
        "temp_units": "fahrenheit",
        "country_code": "US",
        "postal_code": "77856",
        "longitude": "-96.485237",
        "latitude": "31.02602"
    },
    "bridge": {
        "name": "HOOBS",
        "port": 51826,
        "pin": "031-45-154",
        "username": "2A:CE:F1:B1:5F:F6"
    },
    "description": "",
    "ports": {},
    "accessories": [
        {
            "accessory": "HTTP-TEMPERATURE",
            "name": "Outside",
            "getUrl": "http://192.168.77.8:3000/api/status/oat",
            "unit": "fahrenheit",
            "plugin_map": {
                "plugin_name": "homebridge-http-temperature-sensor",
                "index": 0
            }
        },
        {
            "accessory": "apcupsd",
            "name": "Main UPS",
            "location": "192.168.77.1",
            "model": "Back-UPS ES 850G2",
            "serialNo": "4B2026P30612",
            "firmware": "931-a10-D/USB_FW:a1",
            "plugin_map": {
                "plugin_name": "homebridge-accessory-apcupsd",
                "index": 0
            }
        }
    ],
    "platforms": [
        {
            "platform": "myQ",
            "plugin_map": {
                "plugin_name": "homebridge-myq"
            },
            "email": "*",
            "password": "*"
        },
        {
            "platform": "Camera-ffmpeg",
            "plugin_map": {
                "plugin_name": "homebridge-camera-ffmpeg"
            },
            "name": "Camera FFmpeg",
            "cameras": [
                {
                    "name": "GarageCam",
                    "manufacturer": "Wyze",
                    "model": "Wyzecam Pan",
                    "folder": "/home/hoobs/cameras/garagecam",
                    "motion": true,
                    "motionTimeout": 0,
                    "videoConfig": {
                        "source": "-i rtsp://192.168.77.5:8554/unicast",
                        "stillImageSource": "-i rtsp://192.168.77.5:8554/unicast -vframes 1 -r 1",
                        "vcodec": "copy",
                        "audio": true,
                        "debug": false
                    }
                },
                {
                    "name": "DoorbellCam",
                    "manufacturer": "August Home",
                    "model": "Doorbell Cam Pro",
                    "serialNumber": "D2GWS0013U",
                    "folder": "/home/hoobs/cameras/doorbellcam",
                    "motion": true,
                    "motionTimeout": 15,
                    "videoConfig": {
                        "source": "-f video4linux2 -i /dev/video0",
                        "stillImageSource": "-i http://127.0.0.1:8081",
                        "maxStreams": 2,
                        "maxWidth": 480,
                        "maxHeight": 640,
                        "maxFPS": 10,
                        "audio": false,
                        "debug": false
                    }
                },
                {
                    "name": "GateCam",
                    "manufacturer": "Wyze",
                    "model": "Wyzecam V2",
                    "folder": "/home/hoobs/cameras/gatecam",
                    "motion": true,
                    "motionTimeout": 0,
                    "videoConfig": {
                        "source": "-i rtsp://192.168.77.13:8554/unicast",
                        "stillImageSource": "-i rtsp://192.168.77.13:8554/unicast -vframes 1 -r 1",
                        "vcodec": "copy",
                        "audio": true,
                        "debug": false
                    }
                },
                {
                    "name": "StudyCam",
                    "manufacturer": "Wyze",
                    "model": "Wyzecam Pan",
                    "folder": "/home/hoobs/cameras/studycam",
                    "motion": true,
                    "motionTimeout": 0,
                    "videoConfig": {
                        "source": "-i rtsp://192.168.77.12:8554/unicast",
                        "stillImageSource": "-i rtsp://192.168.77.12:8554/unicast -vframes 1 -r 1",
                        "vcodec": "copy",
                        "audio": true,
                        "debug": false
                    }
                }
            ],
            "mqtt": "127.0.0.1",
            "portmqtt": 1883,
            "usermqtt": "mqtt-user",
            "passmqtt": "mqtt-password",
            "topic": "yonder-alerts",
            "porthttp": 8089,
            "interfaceName": "eth0"
        },
        {
            "platform": "HarmonyHubWebSocket",
            "plugin_map": {
                "plugin_name": "homebridge-harmony"
            },
            "name": "Harmony Hub",
            "hubIP": "192.168.77.9",
            "hubName": "Harmony Hub",
            "publishAllTVAsExternalAccessory": true,
            "TVAccessory": false,
            "mainActivity": "Watch Apple TV",
            "switchAccessories": true,
            "publishGeneralMuteSwitch": true,
            "publishGeneralVolumeSlider": true,
            "linkVolumeControlToTV": true,
            "publishSwitchActivitiesAsIndividualAccessories": true,
            "publishDevicesAsIndividualAccessories": true,
            "publishSequencesAsIndividualAccessories": true,
            "publishHomeControlsAsIndividualAccessories": true,
            "showCommandsAtStartup": false,
            "addAllActivitiesToSkippedIfSameStateActivitiesList": false,
            "playPauseBehavior": false,
            "cleanCache": false,
            "configureAccesscontrol": false
        },
        {
            "platform": "NeatoVacuumRobot",
            "plugin_map": {
                "plugin_name": "homebridge-neato"
            },
            "email": "*",
            "password": "*"
        },
        {
            "platform": "dafangMqtt",
            "plugin_map": {
                "plugin_name": "homebridge-dafang-mqtt-republish"
            },
            "name": "Dafang MQTT",
            "server": "127.0.0.1",
            "port": 1883,
            "homebridge_topic": "yonder-alerts",
            "cameras": [
                {
                    "name": "GarageCam",
                    "dafang_topic": "yonder-alerts/garagecam",
                    "cooldown": 15,
                    "accessories": {
                        "recording": true,
                        "snapshot": true,
                        "reboot": true,
                        "motorsVertical": true,
                        "motorsHorizontal": true
                    }
                },
                {
                    "name": "GateCam",
                    "dafang_topic": "yonder-alerts/gatecam",
                    "cooldown": 15,
                    "accessories": {
                        "recording": true,
                        "snapshot": true,
                        "reboot": true
                    }
                },
                {
                    "name": "DoorbellCam",
                    "dafang_topic": "yonder-alerts/doorbellcam",
                    "cooldown": 15
                },
                {
                    "name": "StudyCam",
                    "dafang_topic": "yonder-alerts/studycam",
                    "cooldown": 15,
                    "accessories": {
                        "recording": true,
                        "snapshot": true,
                        "reboot": true,
                        "motorsVertical": true,
                        "motorsHorizontal": true
                    }
                }
            ]
        },
        {
            "platform": "TplinkSmarthome",
            "plugin_map": {
                "plugin_name": "homebridge-tplink-smarthome"
            },
            "name": "TplinkSmarthome",
            "addCustomCharacteristics": true,
            "deviceTypes": [
                "plug",
                "bulb"
            ]
        },
        {
            "platform": "InfinitudePlatform",
            "plugin_map": {
                "plugin_name": "homebridge-infinitude-schedules"
            },
            "verboseLog": false,
            "shutOffAway": false,
            "holdUntilNextActivity": false,
            "url": "http://127.0.0.1:3000"
        }
    ]
}
Sunoo commented 3 years ago

Not familiar with that plugin_map attribute in each of these config sections, is this HOOBS or something?

jlg89 commented 3 years ago

Yes.

HOOBS 3.3.3 Homebridge 1.3.1 Node 14.15.1

Raspberry Pi 3 Model B Plus Rev 1.3 Raspbian "Buster" 10, kernel 5.4.72-v7+

Sunoo commented 3 years ago

Okay, I haven’t done testing with HOOBS quite yet, but I have a HOOBS device being delivered tomorrow for testing purposes. Once that comes in, I’ll see if I can recreate the issue there, maybe they do something different than Homebridge does.

mkellsy commented 3 years ago

This almost looks like there's 2 instances of HOOBS running. I've come across this when testing Homebridge 1.3.x.

Right run ps -a and see if there are multiple node processes.

I see this happen when HOOBS is ran by the system via the hoobs.service file and another via the terminal.

I hope this helps.

jlg89 commented 3 years ago

"ps ax|grep hoobs" shows two hoobs processes running, but I have no idea why that would be, or whether or not that's expected behavior. I haven't done anything to startup a second process. There's only one hoobs.service file in /etc/systemd/system.

mkellsy commented 3 years ago

If you haven't try rebooting. That might clear it up.

There may be 2 hoobs processes one for the hub and one for the bridge (I think, been working on a new version)

Is there a homebridge.service file in /etc/systems/system? Also if you stop the hoobs process. Is there still a hoobs or node in your process list?

jlg89 commented 3 years ago

If I "Stop Service" using the HOOBS webUI, one of the hoobs processes disappears. So it would seem that one of the processes is the "master" that runs the webUI, and the other is the one that handles all the accessories.

There is a /etc/systemd/system/hoobs.service file:

[Unit]
Description=HOOBS
After=network-online.target

[Service]
Type=simple
User=hoobs
ExecStart=/usr/local/bin/hoobs
Restart=on-failure
RestartSec=3
KillMode=process

[Install]
WantedBy=multi-user.target
mkellsy commented 3 years ago

Yes /usr/local/bin/hoobs starts an API and the UI. Then it starts Homebridge. The API is the control plane.

To control the services without the UI you have to use ssh from another computer.

ssh hoobs@hoobs.local

The password is hoobsadmin.

mkellsy commented 3 years ago

Let's see what Sunoo finds. I am starting to think it's a config issue.

Sunoo commented 3 years ago

My goal is to look into this issue and attempt to recreate it this weekend. Pretty crazy time for me at the moment, unfortunately.

jlg89 commented 3 years ago

No pressure, I really appreciate the very impressive work you've put into all of your plugins.

FWIW, I'm not sure exactly when this particular issue started occurring, but it could have something to do with Homebridge 1.3.x and/or HOOBS 3.3.x.

Sunoo commented 3 years ago

I did some testing under Homebridge 1.3.0, though maybe not as thoroughly as I could have, and it worked. I just had a lot of plugins to try to make sure we’re broken by that version’s changes. I’ll play around some more when I have a second, and see if I can make it break under Homebridge, and if not I’ll try under HOOBS once UPS gets that to me.

jlg89 commented 3 years ago

If I can do anything to help, let me know. I'm good in the guts of UNIX.

Sunoo commented 3 years ago

I’ll keep that in mind. I’m just a bit stumped as to what is causing this, since your config looks like it should be valid. The only way I could see the error happening would be if somehow the config is duplicated by Homebridge/HOOBS. Hopefully once I have a chance to load your config into a HOOBS setup, I’ll be able to work out exactly what’s happening.

jlg89 commented 3 years ago

I disabled the error flagging in index.js for camera.name and camera.dafang_topic...

            if (this.cameras.find(camera => camera.name === camera.name)) {
                this.log.warn('WARNING: Multiple cameras named "' + camera.name + '" configured. Only the first loaded will function.');
                error = false;
            }
            if (this.cameras.find(camera => camera.dafang_topic === camera.dafang_topic)) {
                this.log.warn('WARNING: Multiple cameras with topic "' + camera.dafang_topic + '" configured. Only the first loaded will function.');
                error = false;
            }

...and it looks like all the MQTT traffic is doing its thing. Camera controls work, motion detect events are sending images, etc. It's not making it into HomeKit for some reason, though.

mosquitto debug log:

1615399951: Received PINGREQ from mosqsub|270-StudyCam
1615399951: Sending PINGRESP to mosqsub|270-StudyCam
1615399959: New client connected from 192.168.77.12 as mosqpub|7150-StudyCam (c1, k60, u'mqtt-user').
1615399959: Sending CONNACK to mosqpub|7150-StudyCam (0, 0)
1615399959: Received PUBLISH from mosqpub|7150-StudyCam (d0, q0, r0, m0, 'yonder-alerts/studycam/motion', ... (2 bytes))
1615399959: Sending PUBLISH to mosqsub|270-StudyCam (d0, q0, r0, m0, 'yonder-alerts/studycam/motion', ... (2 bytes))
1615399959: Received DISCONNECT from mosqpub|7150-StudyCam
1615399959: Client mosqpub|7150-StudyCam disconnected.
1615399960: New client connected from 192.168.77.12 as mosqpub|7154-StudyCam (c1, k60, u'mqtt-user').
1615399960: Sending CONNACK to mosqpub|7154-StudyCam (0, 0)
1615399960: Received PUBLISH from mosqpub|7154-StudyCam (d0, q0, r0, m0, 'yonder-alerts/studycam/motion/snapshot/image', ... (15257 bytes))
1615399960: Sending PUBLISH to mosqsub|270-StudyCam (d0, q0, r0, m0, 'yonder-alerts/studycam/motion/snapshot/image', ... (15257 bytes))
1615399960: Received DISCONNECT from mosqpub|7154-StudyCam
1615399960: Client mosqpub|7154-StudyCam disconnected.
1615399961: New client connected from 192.168.77.12 as mosqpub|7158-StudyCam (c1, k60, u'mqtt-user').
1615399961: Sending CONNACK to mosqpub|7158-StudyCam (0, 0)
1615399961: Received PUBLISH from mosqpub|7158-StudyCam (d0, q0, r0, m0, 'yonder-alerts/studycam/motion', ... (3 bytes))
1615399961: Sending PUBLISH to mosqsub|270-StudyCam (d0, q0, r0, m0, 'yonder-alerts/studycam/motion', ... (3 bytes))
1615399961: Received DISCONNECT from mosqpub|7158-StudyCam
1615399961: Client mosqpub|7158-StudyCam disconnected.

HOOBS log:

3/10/2021, 12:14:00 PM [Camera FFmpeg] [StudyCam] Snapshot requested: 1280 x 720
3/10/2021, 12:14:00 PM [Camera FFmpeg] [StudyCam] Snapshot command: /home/hoobs/.hoobs/node_modules/ffmpeg-for-homebridge/ffmpeg -i rtsp://192.168.77.12:8554/unicast -vframes 1 -r 1 -frames:v 1 -f image2 - -hide_banner -loglevel error
3/10/2021, 12:14:04 PM [Camera FFmpeg] [StudyCam] Fetching snapshot took 3.8 seconds.
3/10/2021, 12:14:04 PM [Camera FFmpeg] [StudyCam] Sending snapshot: 1280 x 720
3/10/2021, 12:14:04 PM [Camera FFmpeg] [StudyCam] Resize command: /home/hoobs/.hoobs/node_modules/ffmpeg-for-homebridge/ffmpeg -i pipe: -frames:v 1 -filter:v scale='min(1280,iw)':'min(720,ih)':force_original_aspect_ratio=decrease -f image2 -
3/10/2021, 12:14:07 PM [Camera FFmpeg] [GarageCam] [Snapshot] [mp3float @ 0x3ad8890] Header missing
            
Sunoo commented 3 years ago

Sounds like you maybe have two separate issues going on then.

jlg89 commented 3 years ago

I noticed I didn't have an "mqtt:" section in my camera-ffmpeg config. So, the camera I'm testing now looks like this:

    {
        "name": "StudyCam",
        "manufacturer": "Wyze",
        "model": "Wyzecam Pan",
        "motion": true,
        "motionTimeout": 0,
        "debug": true,
        "videoConfig": {
            "source": "-i rtsp://192.168.77.12:8554/unicast",
            "stillImageSource": "-i rtsp://192.168.77.12:8554/unicast -vframes 1 -r 1",
            "vcodec": "copy",
            "audio": true,
            "debug": true
        },
        "mqtt": {
            "motionTopic": "yonder-alerts/studycam"
        }
    }

I'm still not getting motion detect notifications in HomeKit; do I need to use a different motionTopic setting for a Dafang-Hacks camera?

jlg89 commented 3 years ago

Now we got notifications in HomeKit. Sheez.

    {
        "name": "StudyCam",
        "manufacturer": "Wyze",
        "model": "Wyzecam Pan",
        "motion": true,
        "motionTimeout": 0,
        "videoConfig": {
            "source": "-i rtsp://192.168.77.12:8554/unicast",
            "stillImageSource": "-i rtsp://192.168.77.12:8554/unicast -vframes 1 -r 1",
            "vcodec": "copy",
            "audio": true,
            "debug": true
        },
        "mqtt": {
            "motionTopic": "yonder-alerts/studycam/motion",
            "motionMessage": "ON",
            "motionResetTopic": "yonder-alerts/studycam/motion",
            "motionResetMessage": "OFF"
        }
    }
Sunoo commented 3 years ago

Sorry about that, I missed that when I was looking at your config before. Yea, I completely reworked MQTT support in Camera FFmpeg a few versions ago to better support more devices natively without relying on these sorts of helper plugins. Glad you got that resolved.

I still need to work out why this plugin is barfing on your config though.

Sunoo commented 3 years ago

Sorry for the slow response, it’s been a bit crazy for me.

I believe I’ve found the cause of this issue, just need to do a bit more testing, and I’ll get the new version published. Should be this weekend.

jlg89 commented 3 years ago

Dude, I have customers who have been waiting on a software update for 5+ months! Most of that holdup has been regulatory red tape, but still, I'm getting paid to do it. You don't have to apologize for slow response on free software, especially something as ultra-functional as your stuff. Take your time, live your life. Praying for less craziness. :)

Sunoo commented 3 years ago

Sorry for the delay, moving took a lot out of me. v2.3.1 should fix this issue.

jlg89 commented 3 years ago

Congrats on the move. I hate moving.

Looks like you fixed the issue. No more errors, and it all seems to be happy now.

Sunoo commented 3 years ago

Fantastic! It turned out to be an incredibly stupid mistake (aren’t they always?) that I didn’t catch because I only have one WyzeCam.