Page 2 of 3

Re: Live events counter on my website

Posted: Wed Apr 26, 2017 3:00 am
by rockedge
try this version of code that is using mysqli, the same way as a stand alone in /var/www/html and see if it works!!
set $which_monitor to your monitor id.

Code: Select all

<?php
$which_monitor = 2;

$link = mysqli_connect("localhost", "zmuser", "zmpass", "zm");  

/* check connection */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
} 

if ($result = mysqli_query($link, "SELECT * FROM `Events` WHERE `MonitorId`=$which_monitor")) {
    echo "Total # of Events :".mysqli_num_rows($result);
    
    /* free result set */
    mysqli_free_result($result);
}

?>

Re: Live events counter on my website

Posted: Wed Apr 26, 2017 7:28 am
by kmg454
Finally this works, a bit strange that this works without a username and password but this is because the file belongs to root i guess.
I am glad that this works so I can use it on my website.

Now i have to find out how to show the events of today edit the mysqli_query with StartTime and EndTime i think
Thanks

Re: Live events counter on my website

Posted: Wed Apr 26, 2017 2:38 pm
by rockedge
Nice! if you would like to secure the php file you can try and move the php program to the WordPress site root and add this to the top of the php code directly after the <?php

Code: Select all

defined( 'ABSPATH' ) or die( 'No script kiddies please!' );

Re: Live events counter on my website

Posted: Wed Apr 26, 2017 3:05 pm
by kmg454
I have the PHP file on the zoneminder server and an Iframe on the Wordpress website because this is another server.
It just now show the traffic counter of the last 5 day's i am investigate how to show only the counter of today, because there is no table in the database with hold this data, so i have to filter it with StartTime and EndTime

http://kinderdyk.nl/webcam-kinderdijk/

Re: Live events counter on my website

Posted: Wed Apr 26, 2017 5:15 pm
by rockedge
Nice!
Here is a version with the query that only selects events from the current day.

Code: Select all

<?php

$which_monitor = 2;

$link = mysqli_connect("localhost", "zmuser", "zmpass", "zm");  

/* check connection */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
} 

if ($result = mysqli_query($link, "SELECT * FROM `Events` WHERE `MonitorId`=$which_monitor AND `StartTime` >= DATE_SUB(NOW(), INTERVAL 24 HOUR)")) {

    echo "Total # of Events :".mysqli_num_rows($result);
    
    /* free result set */
    mysqli_free_result($result);
}

?>

Re: Live events counter on my website

Posted: Wed Apr 26, 2017 5:40 pm
by kmg454
Thank you very much this is exact what I needed I was struggling with the StartTime Query but now it works 100%

Re: Live events counter on my website

Posted: Wed Apr 26, 2017 7:19 pm
by rockedge
your welcome :D

Re: Live events counter on my website

Posted: Fri Apr 28, 2017 8:34 am
by kmg454
I changed the query a bit:
if ($result = mysqli_query($link, "SELECT * FROM `Events` WHERE `MonitorId`=$which_monitor AND `StartTime` >= DATE_SUB(CURDATE(), INTERVAL 0 DAY)"))
Now I can count the traffic for this date, with the other statement NOW() and interval of 24 HOUR the value changed every minute when time goes by.

Re: Live events counter on my website

Posted: Fri Apr 28, 2017 12:25 pm
by rockedge
Yes that does look even better. I will make a note. Works great!

Re: Live events counter on my website

Posted: Wed Aug 23, 2017 7:40 am
by kmg454
The script works 100% and the counting is very accurate, but this brings me to a new challenge.
I want count cars and bikes with the same camera, so i made two zones named cars and bikes, but I can't find in the database where it store these names of the zones when they are triggered.

Re: Live events counter on my website

Posted: Wed Aug 23, 2017 2:23 pm
by rockedge
I understand. There is a way using the Darknet neural network and YOLO to examine a few of the Alarm frames and let it identify what is in the selected frame. I have managed to do this but it is not really practical as of yet. Uses a lot of CPU resources and the zone method you are looking to work with may do the trick. Can you show us the Zone(s) setup you propose to use? I will track down some more info on this as I am still working on using the zones to track a train traveling on a set of tracks and identify whether the train is traveling left to right or right to left.

P.S. what was the link to the event counter and the village website?

Re: Live events counter on my website

Posted: Wed Aug 23, 2017 3:01 pm
by kmg454
Hi.
I just have two small zones one called Cars and one called Pedestrians to try count both separated.
Searched the database for the names of the zones but can't find them so I think Zoneminder does nothing with the names but working with an #ID or something.


http://www.leefbaarheidkinderdijk.nl/we ... lenstraat/

Re: Live events counter on my website

Posted: Wed Aug 23, 2017 3:07 pm
by kmg454
If this is to difficult I can always make two monitors for the same camera and make two scripts one for cars and one for pedestrians or bikes :-)

Re: Live events counter on my website

Posted: Wed Aug 23, 2017 6:02 pm
by rockedge
I found the zone names in the db in table "Zones" the field is "Name"

Re: Live events counter on my website

Posted: Wed Aug 23, 2017 6:34 pm
by Baylink
KMG: You're looking for *which zone triggered an event*, right?

Expect that to be a combination of Monitor ID# and Zone #; names are never used for such things, so that users can change them with breaking things.