Difference between revisions of "Dedicated SBC Camera Monitor"

From ZoneMinder Wiki
Jump to navigationJump to search
 
(95 intermediate revisions by 2 users not shown)
Line 1: Line 1:
A guide for setting up a dedicated kiosk SBC (here beaglebone) or Desktop that will monitor the video feed from a camera that you choose, auto logging into the video feed. OS will be devuan, WM will be dwm, terminal st, and browser will be surf. It will be a minimal installation with no DE, no extra programs. Leaner than LXDE.
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 on a mid-late 2000's used desktop. RPI's would probably only be able to run less streams, maybe 10-15.


Second, I'll include steps on setting up I2C on the beagle and being able to read a value from a sensor. Combine this with [[ZMTrigger]].
This is much more difficult than connecting a coaxial cable to a CRT such that an analog, older setup would have.


This page is a WIP. It was tested on Debian 8/9. This guide has some other tips in [[Dedicated_RPI_Camera_Monitor]] and [[Desktop_SBC_Camera_Monitor]]. These pages will be incorporated into one page as time permits. There are other ways to do this. You can also have ZMNinja on a dedicated client per http://zoneminder.blogspot.com/p/odroid.html
== Setup ==
== Setup ==
=== Installation ===
=== Installation ===
Requirements:
 
* >=4GB SD Card (not a cheap one)
'''Requirements'''
* SBC (although this works on a desktop)
* >8GB HDD / SD
* SBC (RPI4 or equivalent) / old pc (core 2 duo or newer)
* Internet connection
* Internet connection
* Computer monitor
* Computer monitor
* HDMI cable for BBB (I use a HDMI to DVI adaptor).
Install beaglebone black using elinux.com's [http://elinux.org/BeagleBoardDebian BeagleBoardDebian] page.
Use the direct image (under Demo, below NetInstall). Not the netinstall, which is slower, unless you know what you are doing.
After you boot from SD card, make sure the network interface is set to load in:
<pre>
nano /etc/network/interfaces
</pre>
Then migrate to devuan using [https://git.devuan.org/dev1fanboy/Upgrade-Install-Devuan/wikis/Upgrade-to-Devuan Dev1fanboy Upgrade-Install-Devuan wiki guide]. Skip the part about the display environment. Reboot after apt-get dist-upgrade. Try the purge of libsystemd0 in DE section, may not work. RCN repo seems to want it.


Next complete the following commands
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.


<pre> sudo su</pre>
=== OS ===
<pre> apt-get install xorg libx11-dev libxft-dev libxinerama-dev gcc make htop sudo tcpdump</pre>
Install debian without X/Wayland. Install only SSH and the file system utilities from the ISO wizard.
Complete these for Surf
<pre> apt-get install libwebkitgtk-dev libgtk2.0-dev linux-headers-$(uname -r)</pre>
Then download our three stars of the night.
<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
* 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>
Install dwm from scratch or from the repos (scratch is easier for editing the config file).
cd dwm
apt-get install firefox-esr
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 ===
=== Auto Start Computer ===
<pre>apt-get remove nfs-common rpcbind wpasupplicant avahi-daemon ofono apache2</pre>
Of course, leave wpasupplicant if you use wifi.
Net installer may want to install acpid. Beware of removing cron. Just disable the service.


Should be about 40MB RAM, and <5% CPU.
The first thing we want to do, is get it so the computer will start without user interaction.
Remove Exim4 if you want as well.


==== Clock ====
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.
This is optional. You can decide whether you need to keep time or not.
<pre># apt-get install ntpdate</pre>
Set cron to run ntpdate periodically
<pre>*/5 * * * * ntpdate pool.ntp.org</pre>
This is leaner than running ntpd 24/7


=== Auto Start ===


Here you edit .xinitrc, /etc/rc.local, /etc/inittab, and .bashrc to make the machine auto startx without requiring a login, and have it load surf with the path of the zm server monitor feed. We will also 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


Added to /etc/inittab (replace existing):
<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:
Copy /etc/profile to user that will be auto logging in:
<pre>
cp /etc/profile /home/USERNAME/.bash_profile
cp /etc/profile ~/.bash_profile
</pre>


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


When startx loads, it will pull settings from ~/.xinitrc for USERNAME so edit that:
Appended to /home/USERNAME/.bash_profile :
<pre>
exec startx
#!/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>


==== Browsers ====
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
or firefox might look something like:
#!/bin/bash
/usr/bin/firefox &
exec dwm
or the path for chromium might be:
#!/bin/bash
chromium-browser --home-page http://127.0.0.1/resource --no-sandbox --window-size=1920,1280 --start-fullscreen --test-type
exec dwm
Note that only firefox can view more than 6 streams at once, and requires a switch in about:config to do this (see tips section).


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


Next disable screensaver per [https://wiki.archlinux.org/index.php/Display_Power_Management_Signaling Arch Wiki: Display Power Management SIgnaling]


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


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


These go before the other commands in .xinitrc.  
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 &
<browser command here>
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.
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.


=== Final Steps ===
=== Fine Tuning ===
 
At this point, you should be able to connect a monitor to the Beagle and get a video feed. However there will be two problems. One, it is not full screen. Two it may or may not be flickering.
 
==== Flickering Video ====
 
This is a known issue with BBB. The simple solution is: install devmem2 or some other memory editing program, change a register. 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
devmem2 0x4c000054 w 0x00FFFFF10
</pre>


Install steps source: [https://www.scivision.co/devmem2-on-the-beaglebone-black/ Scivision: Devmem2 on the beaglebone black]
At this point, you should be able to boot the SBC or desktop and receive a video feed without user interaction. All the users have to do is press the power button.
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.


==== Choosing the proper page to view on the browser ====


==== Full Screen Video Feed ====
See [[External Live Stream]]. I currently use the API version, where you host the page on the ZM server. It's easier to manage multiple machines pointing to one server than to manage each machines self hosted page.


1) Point browser to a local html page with the link to the monitor embedded in an img tag
==== Refresh Screen Periodically ====
OR
2) have a local web server run and point surf to a hosted html page.


1 Is easiest. Make an html file
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:
<pre>
<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>
</pre>
Call it on .xinitrc
<pre>
surf file:///home/username/file.html
</pre>
You will need to customize the width and height of the img tag to fit your monitor. In my case I put st in the .xinitrc
of my bbb, restarted, and from the terminal ran <code>xrandr</code> to see what display it was using. I had 1440x900
but the highest width and height I could get out of surf without borders causing trouble was 1415 and 875.


== Using the Breakout Headers ==
Install xdotool
=== Device Trees and Pin Initialization ===
# apt-get install xdotool


Here are some notes, from my own setup of I2C on the BBB. It can be confusing if you are new to the BBB. This guide is helpful for configuring the peripherals or GPIO of the BBB.


<pre>https://github.com/beagleboard/bb.org-overlays</pre>
Edit surf config.h and add the following to the keybindings section, then make and make install.
Follow this link. Ignore the part about pre built kernels if you used the RCN based installer or image from elinux.org's [http://elinux.org/BeagleBoardDebian BeagleBoardDebian]. You already have cape manager support.
{ 0, GDK_F5,  reload, { .b = FALSE } },


If you don't have DTC where is asks for it in the 2nd step for dtc -version, ignore that step. The ./dtc_overlay.sh script will install the latest compatible device tree compiler.


Next
Add to /etc/crontab
<pre>https://github.com/cdsteinkuehler/beaglebone-universal-io</pre>
DISPLAY=:0
And use this to '''configure''' the pins.
*/5 * * * * username /usr/bin/xdotool key F5


There are also preset modes with the pins configured in various states, but I found it more satisfying to customize them to my needs.


<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.
cd ..
git clone https://github.com/cdsteinkuehler/beaglebone-universal-io
cd beaglebone-universal-io
</pre>
No installation is required for config-pin.


Test it now:
==== Accessing headless X via VNC ====
<pre> ./config-pin overlay cape-universal</pre>


This will allow a lot of pins to be edited. This must be done first. Then you can configure pins. There are other modes as well, see github. Cape-universal exports all pins except for HDMI and EMMC pins.
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.


<pre>
<pre>
#:~/beaglebone-universal-io# cat /sys/devices/platform/bone_capemgr/slots
sudo apt-get install xserver-xorg-legacy
0: PF----  -1
add:
1: PF----  -1
allowed-users:anybody
2: PF----  -1
in /etc/X11/Xwrapper.config
3: PF----  -1
apt-get install x11vnc
7: P-O-L-  0 Override Board Name, 00A0,Override Manuf, cape-universal
</pre>
</pre>
Final command may be something like
ssh -L 5900:localhost:5900 user@pineboard  x11vnc -safer  -localhost -nopw -once -auth /tmp/serverauth*  -display :0


Now you can run something like this:
If you are doing headless on vnc, get rid of startx on bash profile
<pre>
and just run it manually.
./config-pin p8_07 hi
</pre>
To set Pin 07 on header 8 to GPIO HI


To see more options
Test x11vnc with
<pre>./config-pin -h</pre>
x11vnc -display :0
But none of the other flags to start. When in doubt, break the commands down to make troubleshooting easier.


e.g.
== Tips ==
<pre>./config-pin -l 9_11
default gpio gpio_pu gpio_pd uart</pre>
Showing us we can set the pin to UART or one of the GPIO modes.
<pre> ./config-pin -a 9_11 uart</pre>
Then we can access the UART through either the direct memory registers, or the linux file system access (search online for more details).


The config-pin overlay cape-universal can be set in /etc/rc.local as well as individual pin settings.
* dd or clonezilla the disc to an img to deploy in multiple places .


=== I2C Usage ===
* When troubleshooting any streams that flicker, try to downscale the video, per [[External Live Stream]] for clients. I.e. include the stream=50 or some percentage lower than 100 in the ZM path.


<pre>
* 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.
# apt-get install i2c-tools
</pre>


List
* It's possible to lock down the keyboard. I don't have the need, but you can make a reasonably secure kiosk. Look online.
<pre>
# i2cdetect -l
</pre>


The i2c peripheral, after being connected to the BBB, will be on one of the three i2c buses.
* Firefox starts in workspace 9, so you might have to change over to it in dwm upon boot. You can remove all workspaces except for #1, and then ff will boot by default
Either 0,1, or 2.
<pre>
# i2cdetect -r 0
</pre>
Here we search on 0.


I used a BMP180 barometer and mine showed up at 77.
* For viewing more than 6 monitors, you may need to use firefox. See [https://wiki.zoneminder.com/Dummies_Guide#Notes Dummies Guide - Notes]


Unfortunately, the sensor can't be read from without a driver. What you
* To start firefox in full screen mode: The best add-on for this I've found is [https://addons.mozilla.org/en-us/firefox/addon/mfull/ mFull]. It can be configured to load full screen, and to remove or autohide the toolbars and navigation bar. There is also RKiosk but this disables all keys and is not needed in my scenario. I've seen some strange behavior with this plugin. On some machines it works and on other machines it will not work. Note that mFull was used in Firefox 52 or earlier.
will need to do is recompile the kernel with that driver included, as linux has
a driver for the BMP085, but not by default.
 
 
 
References:
(from http://elinux.org/EBC_Exercise_12_I2C)
[http://beaglebone.cameon.net/home/i2c-devices]
[https://datko.net/2013/11/03/bbb_i2c/]
 
=== Recompile Kernel With Sensor Driver ===
 
I tried building the kernel natively on the Beagle, but this failed. It is best to cross compile from a Debian based distro. I received an error trying to cross compile on Gentoo.
 
http://elinux.org/EBC_Installing_Kernel_Source
is a good guide that doesn't require javascript (as RCN's docs do).
 
Finally, with the kernel built with support for your i2c device, (in this case a barometer):


* To shutdown, use crontab.
<pre>
<pre>
su root
# nano /etc/crontab
echo bmp085 0x77 > /sys/class/i2c-adaptor/i2c-1/new_device
00 18 * * * root /sbin/poweroff
</pre>
</pre>
Again, these steps are only valid for the bmp085, and when it's on i2c-1.
The problem is you need full path to poweroff or shutdown -h now. If you are on a separate lan, you may need to use ntp and query some local ntp server, if RTC is off.
Review dmesg
<pre>
$ dmesg -T
</pre>
 
Finally for the BMP085, you can navigate to /sys/bus/i2c/drivers/bmp085/1-0077/
and review what the file system provides access to from the BMP driver to interface with the sensor.
 
 
 
References:
[http://elinux.org/Beagleboard:BMP_on_the_Beagle_Bone_Black]
[http://raspberrypi.stackexchange.com/questions/43821/cannot-perform-echo-command-to-load-driver-for-rtc-module]
 
== Troubleshooting ==
 
=== Video feed freezes once a day? ===


I've had the video crash on me on average once a day at 720p. Lowering the resolution to 640x480 or using a more powerful SBC may help.
== See Also ==


*[[Desktop SBC Camera Monitor]]


=== Installing and updating programs takes too long! ===
*[[Beaglebone Black - Devuan Jessie]]


While these SBCs are slower than a desktop, it is also possible you have a counterfeit SD card that is slowing down all installs. A counterfeit or non name brand SD may take one day, what takes 2 hours to do with a name brand card.
*[http://zoneminder.blogspot.com/p/odroid.html Zoneminder Blogspot - ODroid XU4 Zoneminder Client]


=== Video feed flickers, syslog says FIFO underflow! ===
*[https://wiki.alpinelinux.org/wiki/Raspberry_Pi_3_-_Browser_Client#Digital_Signage Alpine Linux Version] - The above guide was adapted for digital signage on an RPI4


See install steps regarding adjusting memory addresses with devmem2.
[[Category:Dummies_Guide]]

Latest revision as of 06:20, 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 on a mid-late 2000's used desktop. RPI's would probably only be able to run less streams, maybe 10-15.


This page is a WIP. It was tested on Debian 8/9. This guide has some other tips in Dedicated_RPI_Camera_Monitor and Desktop_SBC_Camera_Monitor. These pages will be incorporated into one page as time permits. There are other ways to do this. You can also have ZMNinja on a dedicated client per http://zoneminder.blogspot.com/p/odroid.html

Setup

Installation

Requirements

  • >8GB HDD / SD
  • SBC (RPI4 or equivalent) / old pc (core 2 duo or newer)
  • 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.

OS

Install debian without X/Wayland. Install only SSH and the file system utilities from the ISO wizard.

Install dwm from scratch or from the repos (scratch is easier for editing the config file).

apt-get install firefox-esr

Auto Start Computer

The first thing we want to do, is get it so the computer will start without user interaction.

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

Browsers

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

or firefox might look something like:

#!/bin/bash
/usr/bin/firefox &
exec dwm

or the path for chromium might be:

#!/bin/bash
chromium-browser --home-page http://127.0.0.1/resource --no-sandbox --window-size=1920,1280 --start-fullscreen --test-type
exec dwm

Note that only firefox can view more than 6 streams at once, and requires a switch in about:config to do this (see tips section).

Users & Screensaver

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 &
<browser command here>
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. All the users have to do is press the power button.

Choosing the proper page to view on the browser

See External Live Stream. I currently use the API version, where you host the page on the ZM server. It's easier to manage multiple machines pointing to one server than to manage each machines self hosted page.

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.

Tips

  • dd or clonezilla the disc to an img to deploy in multiple places .
  • When troubleshooting any streams that flicker, try to downscale the video, per External Live Stream for clients. I.e. include the stream=50 or some percentage lower than 100 in the ZM path.
  • 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.
  • It's possible to lock down the keyboard. I don't have the need, but you can make a reasonably secure kiosk. Look online.
  • Firefox starts in workspace 9, so you might have to change over to it in dwm upon boot. You can remove all workspaces except for #1, and then ff will boot by default
  • To start firefox in full screen mode: The best add-on for this I've found is mFull. It can be configured to load full screen, and to remove or autohide the toolbars and navigation bar. There is also RKiosk but this disables all keys and is not needed in my scenario. I've seen some strange behavior with this plugin. On some machines it works and on other machines it will not work. Note that mFull was used in Firefox 52 or earlier.
  • To shutdown, use crontab.
# nano /etc/crontab
00 18 * * * root /sbin/poweroff

The problem is you need full path to poweroff or shutdown -h now. If you are on a separate lan, you may need to use ntp and query some local ntp server, if RTC is off.

See Also