roleoroleo / sonoff-hack

Custom firmware for Sonoff GK-200MP2B camera
GNU General Public License v3.0
203 stars 48 forks source link

Proof-Of-Concept PR: immediate motion detection on S-CAM #142

Open couriersud opened 1 year ago

couriersud commented 1 year ago

I am creating this PR to document a possible solution for immediate motion feedback via mqtt on S-CAM devices. Earlier information was provide in issue #113.

The code is far from production quality and contains hard-coded values. The purpose is to document all what I have done to get this working.

darkxst commented 1 year ago

Hi, Your shell scripts are fine for a proof of concept, however this is not the correct approach to actually implement this. All of the MQTT handling is in the custom module mqtt-sonoff, so that is where this inotify handling should go. This program is a C daemon, which you can't integrate it with the busybox inotify daemon. Which means this needs to be done in C.

All of the code for handling motion events is already in there, so would only need to implement the inotify part of it and disconnect the current sql trigger. You would probably need to create a new thread to monitor for inotify events, which can then call the existing callback for motion events.

Do you have any experience with C programming? happy to give some pointers on how it might be implemented if you want to have a crack at?

couriersud commented 1 year ago

I started programming some 40 years ago :-) The limiting factor is quality time. I have thought about your proposal. Busybox inotifyd source has all the code needed to plug into mqtt-sonoff. Due to limited time I needed a quick solution to get this going and wanted to document the basic approach. I'll put the mqtt-sonoff changes on my todo list.

roleoroleo commented 1 year ago

I will add the inotify code to mqtt-sonoff daemon.

roleoroleo commented 1 year ago

Do you want to try this binary? To activate inotify mode you need to set MQTT_IPCSYS_DB=2 immagine

mqtt-sonoff.tar.gz

couriersud commented 1 year ago

Excellent :-) Works like a dream.

roleoroleo commented 1 year ago

Good. I will commit the code.

roleoroleo commented 1 year ago

Please test the pre-release: https://github.com/roleoroleo/sonoff-hack/issues/144