Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call webhook on motion #257

Closed
ivanfor opened this issue Mar 18, 2021 · 6 comments
Closed

Call webhook on motion #257

ivanfor opened this issue Mar 18, 2021 · 6 comments
Labels

Comments

@ivanfor
Copy link

ivanfor commented Mar 18, 2021

Hi.
What would be the best way of calling a webhook after motion? I don't want to rely on mqtt only for this.
I've been reading #30 and seems that ipc_read should be the way, shouldn't it?

@roleoroleo
Copy link
Owner

ipc_read is able to read the queue (using a queue number > 0).
But it depens on what action you want to run.
Try to use the stdout of the command.

@ivanfor
Copy link
Author

ivanfor commented Mar 19, 2021

There's something weird when you pipe stdout of ipc_read to whetever, it seems to get stuch after the first read.
Next examples are taken at the same time:

root@yi1080:/tmp/sd# ipc_read -n 5
MOTION_START
MOTION_STOP
MOTION_START
MOTION_STOP
MOTION_START
MOTION_STOP

root@yi1080:~# ipc_read -n 6 > /tmp/queue &
root@yi1080:~# tail -F /tmp/queue
MOTION_START
root@yi1080:~# ipc_read -n 7 | while read queue ; do echo $queue ; done
MOTION_START

I just can't understand this behavior. Can anybody try to reproduce it? Am I going crazy? ;)
Can the "-n" number have something to do? I've tried several, but based of what is stated in #30, any number between 4 and 9 can be used indistinctly.

P.S.: tried after a reboot with no changes.

@roleoroleo
Copy link
Owner

ipc_multiplexer reads from the original queue /ipc_dispatch and copies the messages to /ipc_dispatch_x where x is a number 0-9
mqttv4 uses /ipc_dispatch_1
/ipc_dispatch_2 to /ipc_dispatch_9 are free.
When ipc_read starts, it clears the message queue.

@ivanfor
Copy link
Author

ivanfor commented Mar 20, 2021

I've made some progress.
First, although I don't fully understand the reason why stdout doesn't work when piped, it gets fixed with a fflush(stdout); in ipc_read.c.

root@xcompiler:~/crosscompiler/yi1080allwinner/yi-hack-Allwinner/src/ipc_cmd/ipc_cmd# git diff ipc_read.c 
diff --git a/src/ipc_cmd/ipc_cmd/ipc_read.c b/src/ipc_cmd/ipc_cmd/ipc_read.c
index 11b0070..77aedb9 100644
--- a/src/ipc_cmd/ipc_cmd/ipc_read.c
+++ b/src/ipc_cmd/ipc_cmd/ipc_read.c
@@ -76,6 +76,7 @@ static int parse_message(char *msg, ssize_t len)
 
     msg[len] = '\0';
     printf("%s\n", msg);
+    fflush(stdout);
 
     return 0;
 }

@roleoroleo , I can send a PR if you want, although being a so simple change it isn't probably worth it.
Besides, in case someone is interested, I've done a script in order to get a webhook called in motion events:

#!/bin/bash

. /home/yi-hack/script/env.sh

QUEUE=9   
URL_MON='http://whatever.url/you/need/to/be/called'
URL_MOFF=''

ipc_read -n $QUEUE | while read event ; do
	case $event in
		"MOTION_START")
			echo "Motion start!!"
			[ -z $URL_MON ] || wget -q -O - $URL_MON
		;;
		"MOTION_STOP")
			echo "Motion end!!"
			[ -z $URL_MOFF ] || wget -q -O - $URL_MOFF
		;;
		*)
			echo "$line - Not implemented"
		;;
	esac
done

@roleoroleo
Copy link
Owner

I will add the fflush
Thank you.

Copy link

github-actions bot commented Apr 7, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the Stale label Apr 7, 2024
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale May 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants