Live events counter on my website

Forum for questions and support relating to the 1.30.x releases only.
rockedge
Posts: 1173
Joined: Fri Apr 04, 2014 1:46 pm
Location: Connecticut,USA

Re: Live events counter on my website

Post 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);
}

?>
kmg454
Posts: 58
Joined: Tue Apr 11, 2017 7:43 am

Re: Live events counter on my website

Post 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
rockedge
Posts: 1173
Joined: Fri Apr 04, 2014 1:46 pm
Location: Connecticut,USA

Re: Live events counter on my website

Post 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!' );
kmg454
Posts: 58
Joined: Tue Apr 11, 2017 7:43 am

Re: Live events counter on my website

Post 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/
rockedge
Posts: 1173
Joined: Fri Apr 04, 2014 1:46 pm
Location: Connecticut,USA

Re: Live events counter on my website

Post 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);
}

?>
kmg454
Posts: 58
Joined: Tue Apr 11, 2017 7:43 am

Re: Live events counter on my website

Post by kmg454 »

Thank you very much this is exact what I needed I was struggling with the StartTime Query but now it works 100%
rockedge
Posts: 1173
Joined: Fri Apr 04, 2014 1:46 pm
Location: Connecticut,USA

Re: Live events counter on my website

Post by rockedge »

your welcome :D
kmg454
Posts: 58
Joined: Tue Apr 11, 2017 7:43 am

Re: Live events counter on my website

Post 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.
rockedge
Posts: 1173
Joined: Fri Apr 04, 2014 1:46 pm
Location: Connecticut,USA

Re: Live events counter on my website

Post by rockedge »

Yes that does look even better. I will make a note. Works great!
kmg454
Posts: 58
Joined: Tue Apr 11, 2017 7:43 am

Re: Live events counter on my website

Post 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.
rockedge
Posts: 1173
Joined: Fri Apr 04, 2014 1:46 pm
Location: Connecticut,USA

Re: Live events counter on my website

Post 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?
kmg454
Posts: 58
Joined: Tue Apr 11, 2017 7:43 am

Re: Live events counter on my website

Post 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/
kmg454
Posts: 58
Joined: Tue Apr 11, 2017 7:43 am

Re: Live events counter on my website

Post 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 :-)
rockedge
Posts: 1173
Joined: Fri Apr 04, 2014 1:46 pm
Location: Connecticut,USA

Re: Live events counter on my website

Post by rockedge »

I found the zone names in the db in table "Zones" the field is "Name"
Baylink
Posts: 338
Joined: Sun Jun 19, 2005 3:19 am

Re: Live events counter on my website

Post 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.
Locked