Setup a Build Environment

The subsequent articles in this blog all rely on the same build environment. If you plan to follow along, you need to perform the following steps first. All of these steps assume the underlying operating system is Linux. The steps described here are a bit drawn out, but the good news is you only have to do it once.

ZoneMinder

A fully installed and working ZoneMinder server, complete with at least one working surveillance camera, is required. Explaining how to install ZoneMinder is beyond the scope of this article. If you have not already done this, then head on over to the ZoneMinder website to learn how to get it working.

Also note that, the ZoneMinder server should run in a separate environment from the one in which you plan to use to program the esp8266. That might mean running on physically separate machines, using virtual machines, or even a Docker container. It is up to you.

Once you have a functional ZoneMinder server, one must enable the zmtrigger service. This is done from the web console. Click Options -> System, check the OPT_TRIGGERS checkbox, and then click the Save button. Restart ZoneMinder from the web console, and you should be good to go.

You can verify the zmtrigger service is running by using telnet from another machine on your network. What follows is an example of how to use telnet from the command line to verify the zmtrigger service is running on a machine with ip address 192.168.1.122:
abauer@Ubuntu-Desktop:~$ telnet 192.168.1.122 6802
Trying 192.168.1.122...
Connected to 192.168.1.122.
Escape character is '^]'.
^]

telnet> quit
Connection closed.
abauer@Ubuntu-Desktop:~$

If you see a message other than "Connected to....", then there was a problem. Verify you can ping the destination and verify the local firewall on the ZoneMinder server is not blocking the request.

CAUTION: By default zmtrigger, listens on tcpip port 6802, and accepts unencrypted commands without any authentication. Yes, that's right. Be careful with this. Many of ZoneMinder's core features were written many years ago, when security was not such a concern.

Arduino IDE

Download and install the latest version of the Arduino IDE software. As of this writing, the latest version is 1.6.7. Note that some Linux distributions, such as Ubuntu, have a version of the Arduino IDE in their repository. That makes for a really easy installation, but unfortunately the version of the Arduino software currently provided by Ubuntu is too old for our purposes. You need to download the software directly from the Arduino site instead.

To do that, just go to the Arduino site and follow the download prompts. You should end up with a file on your system that looks like arduino-1.6.7-linux64.tar.xz. Then just decompress the files. This is how I did it on my system.

cd
tar -xvf ~/Downloads/arduino-1.6.7-linux64.tar.xz

This will leave you with a folder called arduino-1.6.7 under your home folder.

ESP8266 Core for Arduino

Next up is the software which allows one to program the ESP8266 within the Arduino IDE. There are two ways to get this software. I'm going to describe how to get the software through the Arduino Boards Manager because it is the easier of the two. This will get you the latest, stable release. If it becomes apparent that we need a newer version, then I'll describe the second method.

Start Arduino. On my system, that is done from the command line like so:

~/arduino-1.6.7/arduino &

After the Arduino software opens, select File -> Preferences. Notice the field labeled "Additional Board Manager URLs". Enter the following into the field and click OK:
http://arduino.esp8266.com/stable/package_esp8266com_index.json

Next, click Tools -> Board: -> Boards Manager

Boards Manager with esp8266 Installed
From the Boards Manager select "Contributed" from the drop-down menu, then select and install the latest version of esp8266. Close the window once the esp8266 library is marked as "Installed" as shown in the photo.

Finally, select Tools -> Board: one more time. Instead of selecting the Boards Manager, scroll down a ways and select "Generic ESP8266 Module".

At this point, you have installed the minimum amount of software to program an ESP8266 though the Arduino IDE. However, there are some additional libraries you should install, which will make the end result much more user friendly.

WiFiManager Class for the ESP8266

While not absolutely necessary, this library allows one to change the parameters used in your sketch, such as the wifi network credentials, without having to recompile and upload a new sketch. This feature alone makes it well worth the effort.

This library can be installed from the Arduino IDE. Select Sketch -> Include Library -> Manage Libraries... In the search field enter "wifimanager", then select and install the newest available version. Click Close when you are done.

For a graphical representation of these steps, head over to the WiFiManager documentation.

ArduinoJson Library for the WiFiManager

This is the last step. I promise! The WifiManager class stores configuration information on the ESP8266 in a JSON formatted config file. You need to install this library to enable that functionality.

This library installs the same way as the WiFiManager library. From the Arduino menu, select Sketch -> Include Library -> Manage Libraries... In the search field enter "arduinojson", then select and install the newest available version. Click Close when you are done.

Congratulations, your environment is now set up to program the ESP8266 within the Arduino IDE. You can begin writing sketches for the device.