simplest alarm visualization possible -4 LEDs on serial port

If you've made a patch to quick fix a bug or to add a new feature not yet in the main tree then post it here so others can try it out.
User avatar
robi
Posts: 477
Joined: Sat Mar 17, 2007 10:48 am

Post by robi »

ktheking wrote:But if you want to use the solution of 'krzys31337' -the one with the direct single serial port- ,then your limited to 2-3 leds ,with 2 buttons max.
What buttons?
v1.25.0 + Ubuntu Linux 12.04 Server
ktheking
Posts: 70
Joined: Fri Oct 12, 2007 11:53 am

Post by ktheking »

robi wrote :
What buttons?
http://mercury.chem.pitt.edu/~sasha/Lin ... e186.shtml : A serial line computer shutdown button and LED
haus
Posts: 213
Joined: Thu Oct 11, 2007 5:10 am

Post by haus »

There's also this:

http://www.swen.uwaterloo.ca/~drayside/altinput/

gives 3 buttons, maybe a "restart" and then a couple of zmpkg state options, like "arm" and "disarm".
progzmaster
Posts: 3
Joined: Sun Feb 10, 2008 1:39 am
Location: Hungary

Post by progzmaster »

robi wrote:One can hook up as many Tibbo serial ports on a network as he wants. All devices are installed inside the OS as virtual ports, while the physical ports are on the network with IP's. Everything is transparent for the programs.
There are much cheaper way to do this. If you hook up a microcontroller (with USART in it) to a serial port, you have many I/O lines. However, it needs electronic and microcontroller programming skills. Almost anything can be done with this, your experience (and imagine) is the major limiting factor.
Few days ago I finished a device which contains 3 dimmers and 3 relays, one LDR input (Light Dependent Resistor) to measure outdoor environment brightness, one switch and one potmeter input. The sensors can be read out and the complete device can be controlable on serial port.

This is an over-engineered solution :) of a need for switching ON an outdoor lamp in dimmed state and switching on an infrared lamp when there is dark outside.

I installed 'termnetd' daemon to ZM server, so I can access the device on telnet from everywhere (actually I wrote a Windows client which connects to the device. Currently not interacts with ZM at all).
It's very fun to remote control the lamp :D
Gabor Moczik
haus
Posts: 213
Joined: Thu Oct 11, 2007 5:10 am

USB thumbdrive as "key"

Post by haus »

I wanted to bump this thread a bit to mention an idea and see if anyone else has completed any of the ideas written here so far. ZoneMinder is great, and I have a reasonably hardware-access-controlled (locked in a high cabinet) ZM system with power backup. All I'm missing at this point, aside from higher-quality cameras, is a reasonable way to set what I call an "arm" state and a "disarm" state, in the form of ZoneMinder states.

The WAF needs to be very high, of course.

At the moment when we leave, I log into console using XHTML on my mobile phone and click the "arm" run state. When we get home, I have to log in again and select the "disarm" state. I'd like this to be controlled by a switch or button or ... . Since I'm the only one who can control the system, there's no easy way for the system to be armed when I'm not around to physically arm it.

I've been thinking about the various serial and parallel light/switch options (SLED, etc.) and now I'm wondering if there might be a much simpler method. USB thumbdrives are ridiculously cheap now - I probably have 5 of them in various desk drawers. What about a remote USB jack in a non-obvious place, attached to the ZM server. If you want "disarmed" you plug in a USB drive that has some file on it (the secret key, if you will). If you want "armed" you just remove the USB key. (For me, Armed indicates "modect" on a series of indoor cams that are set up with filters to upload via FTP and send email alerts; disarmed is either "off" or "monitor" on those cams, so that the upload/email filters aren't triggered by normal activity when we're here).

Linux should be able to detect the insertion/removal of a USB drive, and in theory there ought to be a way to run a script upon insertion/removal. (Maybe not removal - maybe that's a cron/polling scenario, where you leave the ZM runstate as-is until the most recent poll indicates that the necessary file on the USB drive isn't present any more).

The USB jack could be as far away from the ZM box as USB standards allow (is it 5 meters?), which probably gives a reasonable range of "hiding places" where a random female end of a USB extension cable wouldn't be all that obvious. And there'd have to be a specific filename (or file with specific contents) on the drive, not just any old USB thumbdrive would work.

Just putting the idea out there, any thoughts?

Edit: I guess the topic of this thread morphed between visualization and control; in this case I'm much more concerned with control than visualization.

Edit 2: under Ubuntu, it looks like udev is the way to go here. I think this could be a really nice solution, and it looks like the action to run the script could even be specific to a USB thumb drive's hardware ID (or several - one for each family member).
haus
Posts: 213
Joined: Thu Oct 11, 2007 5:10 am

Post by haus »

Edit:

Dude.

Grab your USB stick's UUID by running:

Code: Select all

udevmonitor --udev --environment
and then plugging in your USB stick. The screen will show a slew of info, including the ID_FS_UUID near the bottom of the output. Then put the following text in your /etc/udev/rules.d/80-programs.rules file, replacing <<USB_UUID>> with the real UUID:

Code: Select all

# Set zoneminder run state when USB key inserted/removed
ENV{ID_FS_UUID}=="<<USB UUID>>", GOTO="ZM_KEY_CHECK"

GOTO="ZM_KEY_END"

LABEL="ZM_KEY_CHECK"

ACTION=="add", RUN+="/usr/bin/zmpkg.pl disarm &"
ACTION=="remove", RUN+="/usr/bin/zmpkg.pl arm &"

LABEL="ZM_KEY_END"
You'll need runstates to match "arm" and "disarm" above, of course (or roll your own) - start, stop, whatever your needs are.


Thanks to Ardaen on ubuntuforums.org for documenting this process in perfect detail back in October 2007.


No need for any wrapper script at all; this works perfectly and it can be keyed to a specific USB stick. It would probably be easier to have a script check a file on the USB stick itself, but this way I don't even have to deal with mounting the stick in /media (since Ubuntu server doesn't automount for me) and I'm not in the mood to write yet another script for this; the above solution will be fine for me.


If your USB stick doesn't have a UUID, you can probably find something else to use. My preferred stick turned out to have a blank UUID but it had an "ID_SERIAL_SHORT" (basically a serial number).


*** old stuff (before I got the above working): ***

Quick self-reply:

Basically, it's working, though it needs refinement. With a udev rule in 80-programs.rules:

Code: Select all

KERNEL =="sdb", RUN+="/usr/bin/zmpkg.pl disarm &"
it'll disarm the system whenever any USB key is inserted or removed (like I said, it needs refinement).

Basically, the rest of the project will involve making a wrapper script that's intelligent enough to figure out if the proper key file is on the USB stick or not, and decide whether to arm or disarm based on whether the file exists or not.

So, if USB stick inserted, run "wrapper.pl" - wrapper checks on sdb and looks for some file. If it finds it, disarm. If not, arm.
User avatar
robi
Posts: 477
Joined: Sat Mar 17, 2007 10:48 am

Post by robi »

Wow! very Nice!

My box is 60meters away from the location where I'd do the arming/disarming. So unfortunately this is not fesable for me. What a pity!

But I do have an ASUS WL-500g Premium router running Linux, which has two USB ports, near to the desired location.

I think I should install an automation like you described on the router itself, and issue the arm/disarm of the ZM box through the network.

One question: Most thumbdrives have a status LED. Could the LED on the thumbdrive be used somehow as a feedback for the success or failure of the arm/disarm operation?

Like: flash 3 times short for success arm. Or flash 20 times long for unknown, errorneous status of the ZM box.

One could use status-checker thumbdrives, based on their serial number, etc... thumb drives which do nothing, just report via their led, the status of the box. I can go real paranoic :shock:
v1.25.0 + Ubuntu Linux 12.04 Server
haus
Posts: 213
Joined: Thu Oct 11, 2007 5:10 am

Post by haus »

Thanks Robi, I thought it was pretty cool too! :)

So I think you can extend USB with cat5...another potential option. I've also seen USB wall plates that extend the allowable distance (search for "USB wall plate" and you'll find them). Not cheap, though. But your router solution is interesting too, though it adds a point of failure.

I've been thinking about the USB light issue myself. I'm not sure if there's a way to control the USB light. I've also been re-thinking the plug/unplug state to something where you'd plug in to arm and disarm, so you have a USB key attached to your keys and you plug it in for a moment before you leave the house, then pull it out and it stays armed. The simplest way of achieving that would be a toggle function; detect what state ZM is in and "flip" to the other state. But then you *need* an LED to show what state you're in, or you have no idea what's going on when you put the drive in.

The other option is to get a thumb drive with a green LED, so that when it's in, there's a green light (for disarm). LOL.

I'm not sure what the next step is, I think I'm going to lean toward the "momentary plug" idea with a status light, but I'll have to review this thread to see if I can figure out how to do a status light.

If you find a bi/tri-color USB thumbdrive let me know. :) That would open up some interesting possibilities if the LED color could be controlled.
haus
Posts: 213
Joined: Thu Oct 11, 2007 5:10 am

Post by haus »

Another idea - there are some keyboard LED blinking tools around; one could specially modify a standard keyboard by basically removing everything but the LEDs, change their color, and then make a script that blinks the various lights according to your own rules. I'm not sure how easy it is to separate the guts of a keyboard...might generate some errors in the OS.

It's possible to turn *off* a thumbdrive LED by ejecting the drive (Ubuntu eject command? I saw it in a forum somewhere). umount doesn't do it because there could be other partitions on the drive, so it has to be eject. Though once the drive is ejected maybe you can't "Reinsert" using a software command. Otherwise you could eject/reinsert to blink the light. But it's like using a Cray IV to hammer in a nail. Sort of brutish.

I like the keyboard LED idea myself, and an experimental keyboard could be had for almost nothing.
ktheking
Posts: 70
Joined: Fri Oct 12, 2007 11:53 am

Post by ktheking »

Hello all ,

It has been a long while since I've posted anything on the ZM forum.
But I'm back :-)
I've been trying over and over again to get the arduino on the road ,but this turned into a project on it's own.
On the guidance of a new collegue of mine , I've stumbled upon this nice gizmo :

http://www.byvac.com/bv/bv4102.htm

Serial Dot LED Matrix Display

I've ordered one ,and see how it turns out. (I pretty optimimstic).

This might be the thing I (and others too I think) was/were looking for.

Keep you posted about how this'll work.
craver84
Posts: 96
Joined: Sun Aug 31, 2008 7:35 am

Post by craver84 »

Hi everyone,
following this guide
http://www.epanorama.net/circuits/paral ... rogramming
now i have a parallel port that can light up to 8 leds.

with this programm I turn them on or off

Code: Select all

#include <stdio>
#include <stdlib>
#include <unistd>
#include <asm>

#define base 0x378           /* printer port base address */
#define value 255            /* numeric value to send to printer port */

main(int argc, char **argv)
{
   if (ioperm(base,1,1))
    fprintf(stderr, "Couldn't get the port at %x\n", base), exit(1);

   outb(value, base);
}

Save the source code to file lpt_test.c and compile it with command:

gcc -O lpt_test.c -o lpt_test
What I want to do is to turn on led 1 for alarms on monitor 1, led 2 for monitor 2, ....
How can I do this? Has anyone any ideas?
haus
Posts: 213
Joined: Thu Oct 11, 2007 5:10 am

Post by haus »

Sure, use this perl script with a "system()" call or "exec()" call (depending on the circumstances) to do what you need with your LED script.

http://www.zoneminder.com/wiki/index.ph ... n_alarm.3F

Where it says "do your stuff here" insert a line like

Code: Select all

system("lptout 0xFF");
craver84
Posts: 96
Joined: Sun Aug 31, 2008 7:35 am

Post by craver84 »

OK,
I've created a file called test:

Code: Select all

#!/usr/bin/perl -w

use strict;

use ZoneMinder;

$| = 1;

zmDbgInit( "myscript", level=>0, to_log=>0, to_syslog=>0, to_term=>1 );

my $dbh = DBI->connect( "DBI:mysql:database=".ZM_DB_NAME.";host=".ZM_DB_HOST, ZM_DB_USER, ZM_DB_PASS );

my $sql = "select M.*, max(E.Id) as LastEventId from Monitors as M left join Events as E on M.Id = E.MonitorId where M.Function != 'None' group by (M.Id)";
my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );

my $res = $sth->execute() or die( "Can't execute '$sql': ".$sth->errstr() );
my @monitors;
while ( my $monitor = $sth->fetchrow_hashref() )
{
    push( @monitors, $monitor );
}

while( 1 )
{
    foreach my $monitor ( @monitors )
    {
        next if ( !zmShmVerify( $monitor ) );
 
        if ( my $last_event_id = zmHasAlarmed( $monitor, $monitor->{LastEventId} ) )
        {
            $monitor->{LastEventId} = $last_event_id;
            print( "Monitor ".$monitor->{Name}." has alarmed\n" );
            #
            # Do your stuff here
            #
        }
    }
    sleep( 1 );
}
chmod u+x test
sudo perl ./test

but I've got this error

Code: Select all

Undefined subroutine &main::zmShmVerify called at ZM_PERL line 27.
What's happend?


PS: I've installed ZM from source following this guide
http://www.zoneminder.com/wiki/index.ph ... ola-0.7%29
Post Reply