Extend States adding more parameters.

Anything you want added or changed in future versions of ZoneMinder? Post here and there's a chance it will get in! Search to make sure it hasn't already been requested.
Post Reply
gola10
Posts: 150
Joined: Wed Nov 01, 2006 3:16 pm
Location: Panama

Extend States adding more parameters.

Post by gola10 »

I would like to be able to change during NIGHT for rxample to grey the capture pallete of certain monitors and maybe the Pixels to save disk space.
Why not store in States all the informations relate to the setting of a monitor and not only if it is enable or not and its function?

Thanks
User avatar
cordel
Posts: 5210
Joined: Fri Mar 05, 2004 4:47 pm
Location: /USA/Washington/Seattle

Post by cordel »

You can basicly already do this. Create two monitors for each camera, one grey scale and the other color and use runstates to do what you want.
gola10
Posts: 150
Joined: Wed Nov 01, 2006 3:16 pm
Location: Panama

Post by gola10 »

I will read on the forum how to do it as you sugest.
Just an idea from a newbie.
If we add one field (state) to the monitor database, the state could be recorded and when zm is started with /usr/local/bin/zmpkg.pl Day it will be loader with the information of the monitors that has Day on the state field.
Naturaly, we must have a record for each monitor that has this new field without data (blank) and because it would take efect when starting ZM without parameter (Day, night).
Prevision should be taken to record on the monitors database the setting for all monitors when saving a new state and also in case of deleting a state to delete all records pointing to that state.
gola10
Posts: 150
Joined: Wed Nov 01, 2006 3:16 pm
Location: Panama

Post by gola10 »

Another way to do it.
As there are presets for camera while adding a Monitor, whe could have presets for monitors for different states on a new database . When starting ZM with a defined state, the data in the new database that correspond to the state wanted, would be copied to the actual monitor database.
There would be always a defaulf state to be used when starting ZM without state indicated.
If we go farther, we could have two diferent types of states. A global one that affects on all the monitors and a second one that affects only a few monitors.
Then we could start ZM whit a global state let say NIght,Weekend.
The night state would be global so all monitors has this state defines and it would be loaded but Weekend is no global so only a few minitors has it defined and in this case the weekend setting would replace for some monitors the state set by Night.
gola10
Posts: 150
Joined: Wed Nov 01, 2006 3:16 pm
Location: Panama

Post by gola10 »

I need different setting of monitor for Day and Night. It was suggested that a work around would be to set two mintors for each camera. One with daytime setting and the other with night settings. Using States, i can enable those monitors that has day settings during day and so on.
It works but i am sure there is a clean way of doing it.

I have an idea but i do not know exactly how to implement it because i do not have the needed programming skills.
I has seen that Webmin let me backup the entire database or only one file. In this case i would backup Monitors database with Day time settings and do another backup of Monitors with Night time settings.
With a cron, i could stop Zoneminder and restore the corresponding backup of monitors if it is Day time or night time.

Could it be done?
Which command is used to tell Mysql to restore a backup?

I will apprecite any help.
gola10
Posts: 150
Joined: Wed Nov 01, 2006 3:16 pm
Location: Panama

Post by gola10 »

Another way to do it.
I am not a programmer and would like to know if there is any problem doing this.

First DO A FULL BACKUP OF ZM DATABASE JUST IN CASE.
I have set zoneminder with my "Day time" needs and with webmin i has entered to the Monitors table and select under webmin "Export as CVS"
Then selected File Format=Tab separed
Include column names in CSV?=no
Save to file .."/path to file/day
SQL where clause for rows to export=Export all rows
and then chose "Export Now"
Now set Zoneminder according to my night needs. In my case, all cameras "Grey".
Save it with webmin as "/path to file/night".
I has created a directory named "scripts" under ZM. so my "/path to file/"is /var/www/html/zm/scripts/
The script is as follow:
Script "Change_state
----------------------------------------------------------------------------------------------------
if [ -f $1 ]; then
/usr/lib/zm/bin/zmpkg.pl stop
sleep 3
cp /var/www/html/zm/scripts/$1 /var/www/html/zm/scripts/Monitors
sudo mysqlimport --replace --local zm "/var/www/html/zm/scripts/Monitors"
/usr/lib/zm/bin/zmpkg.pl start
-----------------------------------------------------------------------------------------------------
Note: I need to copy day or night to Monitors since the mysqlimport command will require that the name of the file to restore must be equal to the table name. Also there is a way to pass password and user name but it did not worked for me. I suppose that according to the way ZM is installed, in some cases this parameters could be needed. In my case ROOT was the right user.

By running "Change_state day" or "Change_state night" i can set any field on the Monitors table as i need.
I has used cron to do the change automatically as root and using the same script without the sudo command. It has worked for a few days now.
This could be easier if i would have a script to send the information of table Monitors to a CVS file and replace what i do with webmin. But, i do not have much programming knowleage to do it.
gola10
Posts: 150
Joined: Wed Nov 01, 2006 3:16 pm
Location: Panama

Post by gola10 »

Just found that instead of using Webmin to save (export) to csv file the content of Monitors table there is this instruction that does the same
mysqldump -h localhost -u root --tab=. zm Monitors > Monitors.txt
Two files will be written. Monitors.sql and Monitors.txt. Monitors.txt is the one that has your settings of your cameras.
Important: The directory where the file Monitors.txt is going to be written must be 777 (rwx by others).

Then Monitors.txt should be copied to another file, "Day Setting" for example because each time this command is executes,it will override the last one.
gola10
Posts: 150
Joined: Wed Nov 01, 2006 3:16 pm
Location: Panama

File relation

Post by gola10 »

I has been using this method to change the settings of a monitor thru cron and it has work for a while but somtimes there is a problem.
Sometimes i set a monitor 640x480 color during day and 320x240 grey during night, this may turn the monitor "red" and it will not work anymore unless i create a new monitor to this particular Video??.

I thing the cause is that there are other files related to monitors and importing only monitors with different settings may create conflicts with other files.

COULD SOMEONE TELL ME WHICH FILES ARE RELATED TO MONITORS?

If possible, i would try to export and restore this files too and not only Monitors.
jameswilson
Posts: 5111
Joined: Wed Jun 08, 2005 8:07 pm
Location: Midlands UK

Post by jameswilson »

changing res is not a simple job and you must restart zm after the changes.
James Wilson

Disclaimer: The above is pure theory and may work on a good day with the wind behind it. etc etc.
http://www.securitywarehouse.co.uk
gola10
Posts: 150
Joined: Wed Nov 01, 2006 3:16 pm
Location: Panama

Post by gola10 »

I have had a better result than before if i save Monitors and Zones. If do not save Zones too, sometimes the monitor did not work anymore with some settings combinations.
i created a directory named scripts in /var/www/html/zm/ where i keep this scripts and its saved files.
WARNING!
IF YOU USE THIS IS UNDER YOUR OWN RISK. I AM NOT AN EXPERT. THIS COULD DAMAGE YOUR DATABASE.

First, I set each monitor as i need and then run this script that i called "savemon". Like this
./savemon day or whatever name you want to give to it (night, weekend, etc)

This is the script savemon that should be run as root
---------------------------- savemon ----------------------------------------------------------
#!/bin/sh

if [ "$1" != "" ] ; then
mysqldump -h localhost -u root -pmko0nji9 --tab=. zm Monitors
cp /var/www/html/zm/scripts/Monitors.txt /var/www/html/zm/scripts/$1.Monitors
rm /var/www/html/zm/scripts/Monitors.txt
rm /var/www/html/zm/scripts/Monitors.sql

mysqldump -h localhost -u root -pmko0nji9 --tab=. zm Zones
cp /var/www/html/zm/scripts/Zones.txt /var/www/html/zm/scripts/$1.Zones
rm /var/www/html/zm/scripts/Zones.txt
rm /var/www/html/zm/scripts/Zones.sql

else echo "Nothing done, you omitted the name "
fi
---------------------------------------------------------------------------------------------
The monitors and zones setting are saved. Notice that password should be included "mko0nji9" in my case. A file day.Monitors and day.Zones has been created by this script.

Then i set monitors and zones the way i want it at night and run ./savemon night.
A file night.Monitors and night.Zones has been created by this script.

Using cron and a script i called change_state i restore this setting as i need.
let say change_state day
------------------- change_state----------------------
#!/bin/sh

if [ -f "/var/www/html/zm/scripts/"$1.Monitors ]; then
/usr/lib/zm/bin/zmpkg.pl stop
sleep 3
cp /var/www/html/zm/scripts/$1.Monitors /var/www/html/zm/scripts/Monitors
mysqlimport --replace --user="root" --password="mko0nji9" --local zm "/var/www/html/zm/scripts/Monitors"
sleep 3
cp /var/www/html/zm/scripts/$1.Zones /var/www/html/zm/scripts/Zones
mysqlimport --replace --user="root" --password="mko0nji9" --local zm "/var/www/html/zm/scripts/Zones"
sleep 3
/usr/lib/zm/bin/zmpkg.pl start
else echo " Nothing done"
fi
-----------------------------------------------------------------------------------------------
It has been working for a few weeks and i have setting like color during day and grey during night, also diferent resolutions on the same monitor during day and night. Also during day the monitors are set as "record" and during night as modect.
Post Reply