Shell Scripting a Camera Server

Adding functionality to an embedded device doesn't have to be complex. How about some shell scripting?
Ways of Exposing Functionality

Exposing functionality always is an issue in embedded development—how much effort should be put into easy customization? In this case, much effort has gone into it—no two surveillance installations are alike.

The browser-based interface is easy to use, feature-full and meant for human consumption. It is often not especially well suited for machine automation.

The HTTP API is a simple request-response API, made for automation, offering most options available in the browser-based interface. It generally returns just a status code or the bare requested object, like a snapshot or video stream. This lends itself well to remote control, and several third-party vendors sell software that uses this API for controlling tens to hundreds of cameras from one or a few central nodes.

The PHP3 lite dialect is the easiest option for adding custom dynamic pages to the browser-based interface, and it can also be used for general-purpose internal scripting.

Shell scripting, via the provided sh-compatible shell and attendant utilities, is flexible and quick when some local intelligence is needed—for example, reacting to the push of a doorbell by snapping a picture, then opening a gate via a relay.

And if some advanced local smarts is needed, the GCC SDK for the platform is available.

What Do We Have?

As previously mentioned, we chose shell scripting for the issue at hand. In the relevant firmware revision, we had quite a few programs worth using:

  • BusyBox: including sash shell as /bin/sh.

  • mish: minix sh-compatible shell.

  • utask: task scheduler, not cron-compatible.

  • bufferd: image capture/buffering.

  • sftpclient: simple FTP client.

  • shttpclient: simple HTTP client.

  • smtpclient: simple mailer.

Of special note is the unobtrusive shttpclient. This allows us to use the HTTP API from internal shell scripts, which we needed for PTZ control. It also could be used in many other ways, of course—signalling events to another Webserver or video server, uploading pictures via HTTP, and other things not needing more than basic authentication. It is a simple HTTP client, after all, not wget or cURL.

Problems we encountered when pushing this into production use mostly turned out to have nothing to do with the scripting. We had some intermittent failures to upload images—these turned out to be caused by a climbing vine colonizing one of the antennas for the wireless bridge.

All good things end. I'll leave you now, but first, the final script we cobbled together is shown in Listing 1. Not particularly elegant, granted, but small and not that hard to write, thanks to the consideration of the original embedded developers. That's a fair lesson to take away from this, isn't it?

Resources for this article: /article/8695.

Erik Inge Bolso is a UNIX consultant and epee fencer who lives in Molde, Norway, and has been running Linux since 1996. Another of his hobbies can be found via a Google search for “balrog genealogy”, and he can be reached at ljcomment@tvilsom.org.

______________________

Webinar
One Click, Universal Protection: Implementing Centralized Security Policies on Linux Systems

As Linux continues to play an ever increasing role in corporate data centers and institutions, ensuring the integrity and protection of these systems must be a priority. With 60% of the world's websites and an increasing share of organization's mission-critical workloads running on Linux, failing to stop malware and other advanced threats on Linux can increasingly impact an organization's reputation and bottom line.

Learn More

Sponsored by Bit9

Webinar
Linux Backup and Recovery Webinar

Most companies incorporate backup procedures for critical data, which can be restored quickly if a loss occurs. However, fewer companies are prepared for catastrophic system failures, in which they lose all data, the entire operating system, applications, settings, patches and more, reducing their system(s) to “bare metal.” After all, before data can be restored to a system, there must be a system to restore it to.

In this one hour webinar, learn how to enhance your existing backup strategies for better disaster recovery preparedness using Storix System Backup Administrator (SBAdmin), a highly flexible bare-metal recovery solution for UNIX and Linux systems.

Learn More

Sponsored by Storix