Difference between revisions of "Dedicated SBC Camera Monitor"

From ZoneMinder Wiki
Jump to navigationJump to search
Line 1: Line 1:
A guide to setup an SBC (Beaglebone black) or Desktop that will monitor a video feed from ZM. Simply add power, and the video feed will appear on boot.
This is a guide for setting up a dedicated computer (core 2 duo or newer) or SBC (RPI recommended) to view all streams at once. I run this with about 28 streams with live montage of some reasonable slow but usable FPS.
 
OS will be Devuan Jessie, WM will be dwm, terminal st, and browser will be surf. It will be a minimal installation. Leaner than LXDE, the default DE for beaglebone.
 
I'll include optional steps to setup Device Trees and the I2C peripheral (Beaglebone specific) and read a sensor. Combine with [[ZMTrigger]].
 
This is noticeably more difficult than connecting a coaxial cable to a CRT such that an analog, older setup would have. But is more flexible. A desktop is generally recommended here, but SBC's can be used as well.
 
After you setup this OS once, it's advisable to copy to an img and then deploy on as many machines as necessary. A good size for the single OS root partition might be 4GB.
 
''Tested in 03/2017 on a Desktop and Beaglebone with Devuan Jessie''
 
Note that in the end, due to faulty video display, I ended up using an old laptop instead. A BBB is able to handle one stream, but seemed to have a bug in the final deployment.


Update: 08/2018 Tested with Rpi3 and Debian Stretch migrated to Devuan Ascii here [[Dedicated_RPI_Camera_Monitor]]
Update: 08/2018 Tested with Rpi3 and Debian Stretch migrated to Devuan Ascii here [[Dedicated_RPI_Camera_Monitor]]
Line 22: Line 10:


'''Requirements'''
'''Requirements'''
* At least 4GB SD
* >4GB HDD / SD
* SBC / Desktop / Laptop
* SBC / Desktop / Laptop
* Internet connection
* Internet connection
* Computer monitor
* Computer monitor
* HDMI cable for BBB (I use a HDMI to DVI adaptor)


Install Beaglebone Black Debian Jessie using elinux.com's [http://elinux.org/BeagleBoardDebian BeagleBoardDebian] page.
This guide used to cover install steps for a BBB, but that will be kept in the history. This guide will now just cover general desktop setup steps.


Use the direct image (under Demo, below NetInstall). Not the netinstall, which is slower, unless you know what you are doing.
=== Install ===
Install debian without X.


After booting from the SD card, make sure the network interface is set to load in:
<pre>
nano /etc/network/interfaces
</pre>


Next, migrate to Devuan using [https://git.devuan.org/dev1fanboy/Upgrade-Install-Devuan/wikis/Upgrade-to-Devuan  Dev1fanboy Upgrade-Install-Devuan wiki guide]. Skip most of the part about the display environment. Reboot after apt-get dist-upgrade. Try the purge of libsystemd0 in DE section, if you like. May not work. RCN repo seems to want it.
=== Auto Start Computer ===
Edit .xinitrc, /etc/rc.local, /etc/inittab, and .bash_profile to auto startx without requiring a login, load the browser (firefox, chromium, or surf) with the path of the zm server monitor feed, and disable the screensaver.




Complete the following commands
Added to /etc/inittab (comment out existing, and add this below. Replace username with your new user):
<pre> su root</pre>
1:2345:respawn:/bin/login -f USERNAME tty1 </dev/tty1 >/dev/tty1 2>&1
Remove non-free from /etc/apt/sources
<pre> nano /etc/apt/sources.list</pre>
<pre> apt-get install xorg libx11-dev libxft-dev libxinerama-dev gcc make htop sudo tcpdump git</pre>
For Surf
<pre> apt-get install libwebkitgtk-dev libgtk2.0-dev linux-headers-$(uname -r)</pre>
Download simple programs
<pre> git clone http://git.suckless.org/dwm && git clone git://git.suckless.org/st && git clone git://git.suckless.org/surf</pre>
Edit the config for dwm
<pre> nano dwm/config.def.h</pre>
* Later Disable the bar
* Later Remove all workspaces except for 1 (*tags)
* Set Mod4Mask as modkey (redmond key)
* Set MODKEY|Shiftmask to 0 and XK_c to XK_F12 for killclient (personal preference)
* Later disable spawm of dmenucmd and termcmd, but for now leave enabled.


<pre>
cd dwm
make
make install
cd ../st
nano config.def.h
</pre>
* Set termname[] to xterm (resolves some issues with programs that don't understand default termname).
<pre>
make
make install
cd ../surf
nano config.def.h
</pre>
* Review options
* Later set runinfullscreen to TRUE
* Later set kioskmode to TRUE once debugging is over
<pre>
make
make install
</pre>


=== Cleanup ===
Copy /etc/profile to user that will be auto logging in:
<pre>apt-get remove nfs-common rpcbind wpasupplicant avahi-daemon ofono apache2</pre>
cp /etc/profile /home/USERNAME/.bash_profile
Leave wpasupplicant if you use wifi.
Net installer may want to install acpid. Beware of removing cron. Just disable the service. Remove Exim4 if you want.
 
At this point maybe 40MB RAM, and <5% CPU. Compare to LXDE.
 
==== Clock ====
Only needed if you are keeping time.
<pre># apt-get install openntpd</pre>
You can run ntpdate for manual updates but an ntpd daemon
seems to run better (albeit, it opens ports and uses
more resources).


=== Auto Start ===
Edit .xinitrc, /etc/rc.local, /etc/inittab, and .bash_profile to auto startx without requiring a login, load surf with the path of the zm server monitor feed, and disable the screensaver.
Added to /etc/inittab (comment out existing, and add this below. Replace username with your new user):
<pre>
1:2345:respawn:/bin/login -f USERNAME tty1 </dev/tty1 >/dev/tty1 2>&1
</pre>
Copy /etc/profile to user that will be auto logging in:
<pre>
cp /etc/profile /home/USERNAME/.bash_profile
</pre>


Appended to /home/USERNAME/.bash_profile :
Appended to /home/USERNAME/.bash_profile :
<pre>
exec startx
exec startx
</pre>


When startx loads, it will pull settings from ~/.xinitrc for USERNAME so edit that (note that .xinitrc requires '''&''' after all commands that are not the final wm).
When startx loads, it will pull settings from ~/.xinitrc for USERNAME so edit that (note that .xinitrc requires '''&''' after all commands that are not the final wm).
<pre>
#!/bin/bash
/usr/local/bin/surf "localhost/zm/cgi-bin/nph-zms??mode=jpeg&monitor=1&scale=100&maxfps=5&buffer=1000&user=user&pass=pass" &
exec dwm
</pre>


#!/bin/bash
/usr/local/bin/surf "localhost/zm/cgi-bin/nph-zms??mode=jpeg&monitor=1&scale=100&maxfps=5&buffer=1000&user=user&pass=pass" &
exec dwm


Add an additional user beside the one used for the auto login, otherwise ssh will fail.  
Add an additional user beside the one used for the auto login, otherwise ssh will fail.  
ssh will try to startx when it loads, and it won't be able to. Add USERNAME2 permissions to sudoers.
ssh will try to startx when it loads, and it won't be able to. Add USERNAME2 permissions to sudoers.
<pre>
# adduser USERNAME2
# adduser USERNAME2
nano /etc/sudoers
nano /etc/sudoers
</pre>




Disable screensaver for the first USERNAME per [https://wiki.archlinux.org/index.php/Display_Power_Management_Signaling Arch Wiki: Display Power Management Signaling]


Disable screensaver for the first USERNAME per [https://wiki.archlinux.org/index.php/Display_Power_Management_Signaling Arch Wiki: Display Power Management SIgnaling]
nano /home/USERNAME/.xinitrc
 
export DISPLAY=:0 &
<pre>
xset s off &
nano /home/USERNAME/.xinitrc
xset -dpms &
 
export DISPLAY=:0 &
xset s off &
xset -dpms &
</pre>


These go before the other commands in .xinitrc, as they have the & symbol.
These go before the other commands in .xinitrc, as they have the & symbol.
The total .xinitrc will be something like:
The total .xinitrc will be something like:
<pre>
#!/bin/bash
#!/bin/bash
export DISPLAY=:0 &
export DISPLAY=:0 &
xset s off &
xset s off &
xset -dpms &
xset -dpms &
/usr/local/bin/surf "localhost/zm/cgi-bin/nph-zms??mode=jpeg&monitor=1&scale=100&maxfps=5&buffer=1000&user=user&pass=pass" &
/usr/local/bin/surf "localhost/zm/cgi-bin/nph-zms??mode=jpeg&monitor=1&scale=100&maxfps=5&buffer=1000&user=user&pass=pass" &
exec dwm
exec dwm
</pre>


Note: When troubleshooting xset. You must be the same user that is running X (ssh in as different user, then su to user). And, you must export DISPLAY to :0 or similar. Finally xset q should query the current settings.
Note: When troubleshooting xset. You must be the same user that is running X (ssh in as different user, then su to user). And, you must export DISPLAY to :0 or similar. Finally xset q should query the current settings.
Line 156: Line 69:
=== Fine Tuning ===
=== Fine Tuning ===


At this point, you should be able to boot the SBC or desktop and receive a video feed without user interaction. However there are two problems (Beagle). One, it is not full screen. Two, video may be flickering.
At this point, you should be able to boot the SBC or desktop and receive a video feed without user interaction.  
 
==== Flickering Video ====
 
This is a known issue with Beaglebone. The simple solution is: install devmem2 or some other memory editing program, change an address. For details of why this is occuring see: [http://www.spinics.net/lists/dri-devel/msg102380.html] and [http://processors.wiki.ti.com/index.php/DA8xx_LCDC_Linux_FB_FAQs] or search online.
 
Steps:
<pre>
git clone https://github.com/VCTLabs/devmem2
cd devmem2
make
make install
</pre>
Append the memory adjustment to rc.local
<pre>
nano /etc/rc.local
devmem2 0x4c000054 w 0x00FFFFF10
</pre>
 
Watch syslog and FIFO errors should immediately stop upon entering write command on memory.
 
Install steps source: [https://www.scivision.co/devmem2-on-the-beaglebone-black/ Scivision: Devmem2 on the beaglebone black]
The author of devmem2 (Jan-Derk Bakker, website and code found at lartmaker.nl), his website is down at the moment. You can view the root domain at internet archive, but the page for devmem2 is not available. Others like VCTLabs above have copied his code to various spots. See also the Notes section below.


==== Full Screen Video Feed ====
==== Full Screen Video Feed ====
Line 194: Line 85:
</pre>
</pre>
Call it on .xinitrc before dwm
Call it on .xinitrc before dwm
<pre>
 
surf file:///home/username/file.html &
surf file:///home/username/file.html &
</pre>
 
Customize the width and height of the img tag to fit your monitor. In my case I put st in the .xinitrc
Customize the width and height of the img tag to fit your monitor. In my case I put st in the .xinitrc
of my beagle instead of surf, restarted, and from the terminal ran <code>xrandr</code> to see what display it was using. I had 1440x900 but the width and height I could get out of surf without borders causing trouble was 1415 and 875. Multiple img tags can be embedded into an html file however you like. See also [[Example Camera View HTML]]
of my beagle instead of surf, restarted, and from the terminal ran <code>xrandr</code> to see what display it was using. I had 1440x900 but the width and height I could get out of surf without borders causing trouble was 1415 and 875. Multiple img tags can be embedded into an html file however you like. See also [[Example Camera View HTML]]
Line 205: Line 96:


Install xdotool
Install xdotool
<pre>
# apt-get install xdotool
# apt-get install xdotool
 
</pre>


Edit surf config.h and add the following to the keybindings section, then make and make install.
Edit surf config.h and add the following to the keybindings section, then make and make install.
<pre>
{ 0, GDK_F5,  reload, { .b = FALSE } },
{ 0, GDK_F5,  reload, { .b = FALSE } },
 
</pre>


Add to /etc/crontab
Add to /etc/crontab
<pre>
DISPLAY=:0
DISPLAY=:0
*/5 * * * * username /usr/bin/xdotool key F5
*/5 * * * * username /usr/bin/xdotool key F5
 
</pre>


To make sure this works, with the browser watching a camera stream, restart apache2 on the ZM server, and the browser feed will freeze. A successful F5 from xdotool will refresh the screen, as long as surf has a keybinding for it.
To make sure this works, with the browser watching a camera stream, restart apache2 on the ZM server, and the browser feed will freeze. A successful F5 from xdotool will refresh the screen, as long as surf has a keybinding for it.
Line 245: Line 133:
== Todo ==
== Todo ==


* Make a guide similar to the above, but using stali, sabotage, or a similar static binary distro (would be faster / leaner).
* Make a guide similar to the above, but using stali, sabotage, or a similar static binary distro (would be faster / leaner). Alpine is the mainstream option in this category.
 
* This link here [https://web.archive.org/http://blog.lemoneerlabs.com/3rdParty/Darling_BBB_30fps_DRAFT.html] goes a step further into optimizing video processing for the beaglebone black. While the kernel is probably already optimized for bbb hardware, there is room on the software side to compile for optimizations.
 
* Also, consider the RPi and its Hardware encoding capabilities, roughly documented here in [https://forums.zoneminder.com/viewtopic.php?f=34&t=26112 the forums].


== Notes / Errata==
== Notes / Errata==


* The above install requires about 2GB (make partition 3GB or 4GB to be safe). dd or clonezilla the partition to an img to reuse later.
* dd or clonezilla the disc to an img to deploy in multiple places .


* When troubleshooting any dropouts from watching the video feed, make sure to downscale the video, per [[Example_Camera_View_HTML]] for clients.
* When troubleshooting any dropouts from watching the video feed, make sure to downscale the video, per [[External Live Stream]] for clients.


== Troubleshooting ==
== Troubleshooting ==
Line 262: Line 146:


On an SBC a counterfeit SD card could be the cause. A counterfeit or non name brand SD may take one day, what takes 2 hours to do with a name brand card.
On an SBC a counterfeit SD card could be the cause. A counterfeit or non name brand SD may take one day, what takes 2 hours to do with a name brand card.
=== Video monitor flickers, syslog says FIFO underflow! ===
See install steps regarding adjusting memory addresses with devmem2.


=== How do I disable keypresses for kiosk mode? ===
=== How do I disable keypresses for kiosk mode? ===
Line 271: Line 151:
I don't have the need, but it's possible to do further lockdown. Look online.
I don't have the need, but it's possible to do further lockdown. Look online.


=== Video is still flickering after devmem2 changes! ===
See my note. More research is needed. I was able to see the BBB running a ~3FPS 720p stream without error at one point, but at a later point, it began to drop out occasionally. It may be best to either run the viewing feed at a lower resolution, or to use a more powerful ARM based board (or a desktop if you don't need low power).


== See Also ==
== See Also ==

Revision as of 06:40, 3 November 2023

This is a guide for setting up a dedicated computer (core 2 duo or newer) or SBC (RPI recommended) to view all streams at once. I run this with about 28 streams with live montage of some reasonable slow but usable FPS.

Update: 08/2018 Tested with Rpi3 and Debian Stretch migrated to Devuan Ascii here Dedicated_RPI_Camera_Monitor

Another companion to this guide is the Desktop_SBC_Camera_Monitor

11/2018: See also Zoneminder Blogspot - ODroid XU4 Zoneminder Client guide.

Setup

Installation

Requirements

  • >4GB HDD / SD
  • SBC / Desktop / Laptop
  • Internet connection
  • Computer monitor

This guide used to cover install steps for a BBB, but that will be kept in the history. This guide will now just cover general desktop setup steps.

Install

Install debian without X.


Auto Start Computer

Edit .xinitrc, /etc/rc.local, /etc/inittab, and .bash_profile to auto startx without requiring a login, load the browser (firefox, chromium, or surf) with the path of the zm server monitor feed, and disable the screensaver.


Added to /etc/inittab (comment out existing, and add this below. Replace username with your new user):

1:2345:respawn:/bin/login -f USERNAME tty1 </dev/tty1 >/dev/tty1 2>&1


Copy /etc/profile to user that will be auto logging in:

cp /etc/profile /home/USERNAME/.bash_profile


Appended to /home/USERNAME/.bash_profile :

exec startx

When startx loads, it will pull settings from ~/.xinitrc for USERNAME so edit that (note that .xinitrc requires & after all commands that are not the final wm).

#!/bin/bash
/usr/local/bin/surf "localhost/zm/cgi-bin/nph-zms??mode=jpeg&monitor=1&scale=100&maxfps=5&buffer=1000&user=user&pass=pass" &
exec dwm

Add an additional user beside the one used for the auto login, otherwise ssh will fail. ssh will try to startx when it loads, and it won't be able to. Add USERNAME2 permissions to sudoers.

# adduser USERNAME2
nano /etc/sudoers


Disable screensaver for the first USERNAME per Arch Wiki: Display Power Management Signaling

nano /home/USERNAME/.xinitrc
export DISPLAY=:0 &
xset s off &
xset -dpms &

These go before the other commands in .xinitrc, as they have the & symbol. The total .xinitrc will be something like:

#!/bin/bash
export DISPLAY=:0 &
xset s off &
xset -dpms &
/usr/local/bin/surf "localhost/zm/cgi-bin/nph-zms??mode=jpeg&monitor=1&scale=100&maxfps=5&buffer=1000&user=user&pass=pass" &
exec dwm

Note: When troubleshooting xset. You must be the same user that is running X (ssh in as different user, then su to user). And, you must export DISPLAY to :0 or similar. Finally xset q should query the current settings.

Fine Tuning

At this point, you should be able to boot the SBC or desktop and receive a video feed without user interaction.

Full Screen Video Feed

Two options come to mind:

  • Point browser to a local html page with the link to the monitor embedded in an img tag

OR

  • have a local web server run and point surf to a hosted html page.

First Is easiest. Make an html file. Be sure to include http prefix.

<html>
<img width="###px" height=###px" src="http://serverip/zm/cgi-bin/nph-zms?mode=jpeg&monitor=####&scale=100&maxfps=5&user=username&pass=password" />
</html>

Call it on .xinitrc before dwm

surf file:///home/username/file.html &

Customize the width and height of the img tag to fit your monitor. In my case I put st in the .xinitrc of my beagle instead of surf, restarted, and from the terminal ran xrandr to see what display it was using. I had 1440x900 but the width and height I could get out of surf without borders causing trouble was 1415 and 875. Multiple img tags can be embedded into an html file however you like. See also Example Camera View HTML

Refresh Screen Periodically

You will want to have the web browser refresh every few minutes. Otherwise, if the feed drops out, it will not return unless you reboot. The way I accomplished this was:

Install xdotool

# apt-get install xdotool


Edit surf config.h and add the following to the keybindings section, then make and make install.

{ 0, GDK_F5,  reload, { .b = FALSE } },


Add to /etc/crontab

DISPLAY=:0
*/5 * * * * username /usr/bin/xdotool key F5


To make sure this works, with the browser watching a camera stream, restart apache2 on the ZM server, and the browser feed will freeze. A successful F5 from xdotool will refresh the screen, as long as surf has a keybinding for it.

Accessing headless X via VNC

In the case that you have a headless device (no monitor attached) yet X is running, here's some tips for accessing the desktop via VNC.

sudo apt-get install xserver-xorg-legacy
add:
allowed-users:anybody 
in /etc/X11/Xwrapper.config
apt-get install x11vnc

Final command may be something like

ssh -L 5900:localhost:5900 user@pineboard  x11vnc -safer  -localhost -nopw -once -auth /tmp/serverauth*   -display :0 

If you are doing headless on vnc, get rid of startx on bash profile and just run it manually.

Test x11vnc with

x11vnc -display :0

But none of the other flags to start. When in doubt, break the commands down to make troubleshooting easier.

Todo

  • Make a guide similar to the above, but using stali, sabotage, or a similar static binary distro (would be faster / leaner). Alpine is the mainstream option in this category.

Notes / Errata

  • dd or clonezilla the disc to an img to deploy in multiple places .
  • When troubleshooting any dropouts from watching the video feed, make sure to downscale the video, per External Live Stream for clients.

Troubleshooting

Installing and updating is slow!

On an SBC a counterfeit SD card could be the cause. A counterfeit or non name brand SD may take one day, what takes 2 hours to do with a name brand card.

How do I disable keypresses for kiosk mode?

I don't have the need, but it's possible to do further lockdown. Look online.


See Also