Amazon Alexa® (at least at the time of this writing) does not inherently support any direct integration with local/private network cameras running securely inside your network. Instead Alexa focuses on providing an infrastructure for third-party camera manufacturers to integrate their cameras. This is great for the few camera manufacturers that have implemented an Alexa skill; however, many camera manufacturers are not equipped to deliver such a service or its simply not a priority for them. Some manufacturers require a subscription to their own cloud products/offerings to enable this feature. To make matters worse, many users, that have multiple security cameras installed, have heterogeneous environments with a mixture of different camera models from different manufacturers.
Thus, Monocle was born. Monocle steps in to help address these problems and provide a solution for the numerous network cameras that either do not have any cloud connectivity or where owners purposefully disable cloud connectivity for privacy concerns. In essence, Monocle is an aggregator of camera feed information that implements the necessary backend integration and secure communication with the Amazon Alexa services.
Users can define their camera feeds via the Monocle web portal which integrates that information with the Monocle Smart Home Skill to provide Alexa the listing of camera feeds as smart home devices in the user's Alexa App. Anytime a request is made from a video-enabled Alexa powered device such as an Amazon Echo Show, Amazon Echo Spot and/or Amazon Fire TV, the Monocle servers receive the request from the Alexa gateway and returns all the necessary details on how to connect to the camera stream. The user's Alexa device then locally connects to the camera's video/audio stream on the private network and displays the content on screen.
With Monocle, users are now able to view any of their network cameras from any Amazon Echo video enabled device or from their TV using Amazon FireTV simply by asking, "Alexa, show me the {nursery} camera." Now that the cameras are visible, how can the user control them? Several of these cameras have PTZ (pan-tilt-zoom) capabilities. A custom Alexa skill using voice commands to control the cameras might would work well for recalling camera presets but would be incredibly cumbersome for fine adjustment or dynamic control. What the user really needs, is a physical/tactile solution capable of making fine adjustments and dynamically positioning the camera in near real time. The following software and hardware projects integrate with the Monocle platform to provide local PTZ controllers in a variety of form factors and control surfaces. These wireless PTZ controllers automatically control the last camera selected through Alexa and the Monocle Smart Home skill. Now the user can sit in front of the TV, ask Alexa on FireTV to show a specific camera feed, and then pick up the PTZ controller and move the camera around to any location or recall one of the camera's presets.
The following items are necessary to use this project.
> NETWORK/IP CAMERA
At least one network/IP camera capable of publishing a RTSP/RTP stream with H264 encoded video is required. At the time of this writing, Amazon hardware only supports RTSP/RTP with H264 for camera feeds.
In order to use Monocle to control the PTZ (pan-tilt-zoom) on the camera, it also must support the ONVIF protocol and standard. ONVIF is not required to view the camera feeds on the video-enabled Alexa devices its only required to control PTZ on them.
Note: The cameras do not need to be exposed via an Internet connection and do not require a public IP address. In fact, unless there are specific needs to make the cameras directly accessible across the Internet, users are strongly discouraged against exposing the camera through a router/firewall to the Internet.
> VIDEO CAPABLE ALEXA DEVICE
The user will also need an Alexa device that supports video display. This includes the Amazon Echo Show, Echo Spot and/or FireTV.
It's important to understand the different components of this project because its not a one-size-fits-all type of solution but rather more of an a-la-carte buffet of options the user can choose from depending on the desired features. For example, the user may only be interested in viewing camera feeds on the FireTV or Echo Show and have no interest in the other aspects of the project such as the PTZ controllers; however, having insight into the overall project architecture will will make it easier to understand where the dividing lines are and what components and/or steps are needed.
> MONOCLE PLATFORM / WEB PORTAL
All aspects of the project revolve around the Monocle (cloud) platform and web portal. The platform is comprised of a series of web services, web user interfaces and backend integrations that securely manage all the required communication requirements between individual network cameras and Alexa.
> MONOCLE (ALEXA) SMART HOME SKILL
The fully published Alexa Smart Home skill is listed in the skills store in the Alexa app. This skill provides all the backend integration to enable displaying network cameras on an Alexa video enabled device. Additional details and instructions on how to setup the Monocle Smart Home skill are listed below in the Monocle (Alexa) Smart Home Skill section of this article.
> MONOCLE GATEWAY
To control the network cameras using one of the PTZ controller projects listed in this article, the user will need to run a single instance of the Monocle Gateway inside their network. Additional details and instructions on how to setup the gateway are included below in the Monocle Gateway section of this article.
> MONOCLE ARDUINO LIBRARY
This is an open-source Arduino library project that enables communication and integration with the Monocle Gateway and cameras on the user's local network.
> MONOCLE PTZ CONTROLLERS
We have included a variety of sample projects that implement several different types of PTZ (pan-tilt-zoom) controllers including a 3-axis joystick controller, 2-axis joystick controllers and and IR remote controller. There are even examples on how to re-purpose old Commodore or Atari compatible joysticks to control the cameras.
To use the Monocle platform, the user will need to create an account with Monocle. This takes just under a minute to complete by visiting https://MonocleCam.com/ and clicking "Register Now".
A form will appear to enter contact information and setup an account password.
After completing the form, click "Create Account" and a new account will be created in the background.
Since the platform is new and there are parts still under construction, only BETA user accounts are currently available. The system is fully functional, but just remains in BETA testing as we continue to make improvements to enhance the user experience.
The user's account will be created in just a few seconds and will be ready to add the camera feeds to the account.
Newly registered accounts should already be signed in and on the dashboard page. If not, log into the Monocle account to access the dashboard page to add a camera source/feed to the account.
Click "Add Camera Feed" to add a new camera source.
A prompt will appear with a form to enter all the camera feed details including:
- Camera Feed Name (ie: Basement)
- Camera Feed Description (ie: Basement Camera)
- Camera Manufacturer
- Camera Model
- RTSP/RTP Camera Feed URL (ie: rtsp://192.168.1.101/live/0)
- Video Resolution (ie: 1280x720)
- Video Codec (only H264 is currently supported by Alexa at this time)
- Audio Codec (ie: G711, AAC, NONE)
The most difficult part may be finding the proper RTSP/RTP feed URL for the camera. If URL does not appear in the camera's user guide, a web search may provide the RTSP/RTP feed URL. Additionally, this camera database may be helpful: https://www.ispyconnect.com/sources.aspx
After the form is completed, click Save to finish adding the new camera source. The new camera source will be listed on the dashboard page along with a toolbar menu to edit or delete the camera feed as needed.
The user can add as many camera feeds as needed, but it may be beneficial to get one fully up and working with the Alexa devices before adding camera entries for the entire home. This verifies that the camera is compatible and a validates the RTSP URL. After adding at least one camera feed, enable and link the Monocle Smart Home Skill in the Alexa app as described in the next topic.
Monocle has a fully published Alexa Smart Home skill listed in the skills store in your Alexa app. Enabling the Monocle skill and link it to the existing Monocle user account is all that is required.
(STEP-BY-STEP) Add the Monocle Smart Home Skill in the Alexa® App
Open the Amazon Alexa app on a mobile device or open the Alexa portal in a web browser (https://alexa.amazon.com). Next, select the SKILLS option from the main menu.
In the Skills browser, search for "Monocle" and select the Monocle skill from the list of results as shown below.
On the Monocle skill page, select "ENABLE" to enable and link the skill with the Alexa account.
A Monocle login page will then appear. Enter the Monocle account credentials and press the "Sign In" button to continue.
After successfully signing into Monocle, your Monocle and Alexa accounts will be linked. Once the confirmation window is closed, Alexa will automatically prompt the user to "Discover Devices." Select the "Discover Devices" button to start the discovery.
If the discovery prompt is cancelled or there is a need to re-discover a newly added camera feed, the device discovery can be launched directly from the Smart Home page of the Alexa app by pressing the "Add Device Button"
After Alexa completes the discovery, the camera feeds should appear under the Smart Home Devices tab. Each device should have a camera icon as shown in the sample screen shot below.
Once the Monocle skill is enabled and the camera feeds are registered as Alexa Smart Home devices, the system is ready to start testing the camera feeds on an Alexa video-enabled device such as the Echo Show, Echo Spot or Fire TV.
Any of the following utterance patterns should work consistently. Please note there are other patterns that will work, but these are the Alexa sanctioned utterances for accessing camera video feeds.
The Monocle Gateway Service is a small service that installs and runs inside the user's network to facilitate communication between Monocle and the user's cameras. This service is required in order to implement one of the PTZ controllers in this project. The Monocle Gateway Service DOES NOT communicate ANY video or audio content to the Internet. The sole purpose is to provide camera control integration for PTZ cameras.
NOTE: The Monocle Gateway Service is not needed if the intent is simply use Monocle to view the camera feeds on Alexa video enabled devices.
The Monocle Gateway Service source code is open source and is available here in the GitHub repository: https://github.com/MonocleCam/MonocleGateway
The Monocle Gateway Service is a cross-platform application that requires installation of NodeJS on the computer or embedded device (such as a Raspberry Pi) that will run the service. (We are using the latest NodeJS version 9.6.1 at the tine of this writing.) NodeJS downloads and installation instructions for multiple platforms/OS are available here: https://nodejs.org/en/download/
> INSTALL THE MONOCLE GATEWAY
As mentioned in the Prerequisites section of this article, the user will need to have NodeJS installed on the system used as your Monocle Gateway. Monocle uses Node version 9.6.1 at this time. Monocle Gateway can be run on the main computer or, if preferred, can be run on a dedicated small device such as a Raspberry Pi. This article uses a Raspberry Pi 3B to demonstrate the installation and setup procedure, but these procedures should be nearly the same for any platform.
Installing with GIT is probably the easiest method but also requires that GIT is installed on the target system. Otherwise, the ZIP file of the project sources can be downloaded directly from GitHub.
The first step is to retrieve the Monocle Gateway project files to the local system in the working directory designated for install. (In many cases, the user's home directory is the simplest location.) The git clone
command below can be used to pull the latest source code from the Monocle Gateway GitHub repository to the local system.
git clone https://github.com/MonocleCam/MonocleGateway.git
Once the project has been cloned, the user will need to navigate into the new directory on the system.
cd MonocleGateway
Inside the MonocleGateway
project directory, use the NPM
INSTALL
command that is included with NodeJS to install all the project dependencies.
npm install
Please Note: This process may take some time depending on the system. On the Raspberry Pi 3B, it took about 3 minutes.
After the install process is finished, the next step is to compile the project. A "build" script is included that defines the steps to build the project and can be performed by simply running the following NPM command:
npm run build
When the build process is finished, it is time to configure the settings and then run the Monocle Gateway
> CONFIGURE THE MONOCLE GATEWAY
Before starting the Monocle Gateway, the user must create a configuration file that contains an API access token to Monocle and access credentials (username & password) to access the cameras locally.
Below is a sample configuration file template. Start by copying the template file config-example.json
to a new file named config.json.
cp config-example.json config.json
Next, open the new config.json
file with a text editor (VI, nano, etc).
nano config.json
The user must provide a single/common username and password for accessing the PTZ capabilities of each of the cameras. (Note: updates on the portal are currently in progress to allow configuration of access credentials separately for each camera.) Some cameras allow anonymous access to the PTZ functions while other limit access to only the "admin" account. Refer to the camera's manual to find the most appropriate user account and access permissions.
An API access token can be created from the user's Monocle account and is required to permit the Monocle Gateway remote access to the user's account and camera information. Sign in to the Monocle portal and navigate the top menu to the "User Account" page where an API access token can be created.
Safeguard this token as it provides access to the Monocle account. A copy and paste process to get the token added to the configuration file is most efficient as the token very long string of random characters.
After the configuration file is edited, user credentials are added to access the cameras and the Monocle API access token is added, the configuration file can be saved and closed. The Monocle Gateway can now be run and tested.
> RUN THE MONOCLE GATEWAY
After the config.json
file is added with the user preferences and API access token, the service can be tested by launching it with the following command:
npm start
The program start up appears and the service connects to Monocle. If the cameras are already setup with Alexa, the active camera may be listed here as well.
Next, build and install the PTZ controllers and boot them to attach to the Monocle Gateway.
Please take note of the IP address or hostname of the Monocle Gateway, as it will be added to the Arduino configuration located in the private.h
files of the PTZ controller projects.
> AUTO START THE MONOCLE GATEWAY
To automatically start the Monocle Gateway each time the system boots, it should be included in the system startup scripts which vary depending on the operating system. The other option is using a NodeJS process manager like PM2.
If building one of the PTZ controller projects, download and install the Monocle Arduino Library in the Arduino IDE. This library contains all the common and reusable logic blocks that are used across the various PTZ controller projects.
> DOWNLOAD THE MONOCLE ARDUINO LIBRARY
Open a web browser to the Monocle Arduino Library GitHub Repository: https://github.com/MonocleCam/MonocleArduino
Select the Clone or Download button on the right side of the page and then select the Download ZIP option.
> INSTALL THE MONOCLE ARDUINO LIBRARY
Open the Arduino IDE and select the Sketch menu, Include Library sub-menu and Add .ZIP Library option.
A dialog prompt will be displayed to navigate and select the downloaded ZIP file. Select Choose after selecting the ZIP file.
That's it! The Monocle Arduino Library is now installed. Verify the successful installation by selecting the Sketch menu, Include Library sub-menu and Manage Libraries option.
This will open the Arduino IDE's Library Manager window. By typing "monocle
" in the search input field, the Monocle IP Camera Library should be listed below in the results window.
> INSTALL DEPENDENCY LIBRARIES
The Monocle Arduino Library and various PTZ Controller projects depend on additional third-party libraries that need to be installed. Fortunately, all these third-party libraries are available and directly installable via the Library Manager in the Arduino IDE.
- ArduinoHttpClient (https://github.com/arduino-libraries/ArduinoHttpClient) Required for: All PTZ Controllers
- ArduinoJson (https://arduinojson.org/) Required for: All PTZ Controllers
- Bounce2 (https://github.com/thomasfredericks/Bounce2) Required for: Deluxe PTZ Controller, Basic PTZ Controller, Retro PTZ Controller
- MenuSystem (https://github.com/jonblack/arduino-menusystem) Required for: Deluxe PTZ Controller, Basic PTZ Controller
- Adafruit_GFX (https://github.com/adafruit/Adafruit-GFX-Library) Required for: Deluxe PTZ Controller, Basic PTZ Controller
- Adafruit_SSD1306 (https://github.com/adafruit/Adafruit_SSD1306) Required for: Deluxe PTZ Controller, Basic PTZ Controller
- IRremote (https://github.com/z3t0/Arduino-IRremote) Required for: IR Remote PTZ Controller
Time to break out the soldering irons!
In this the part of the project, a PTZ controller interface may be built and customized to suit individual user needs. Provided below are multiple examples all based on using the Arduino IDE and Monocle Arduino Library.
There are four primary variations of the PTZ controller, some with different implementations for a variety of micro-controllers.
- Deluxe Joystick PTZ Controller
- Basic Joystick PTZ Controller
- Retro Joystick PTZ Controller
- IR Remote PTZ Controller
This project implements a 3-axis joystick controller with an Arduino MKR1000 to provide the most sophisticated and feature rich controller of all the project samples provided. This project implements a small OLED module (128x64 pixels) to serve as a user interface for menu navigation. The third axis on this joystick is a rotational axis and used for zoom control. Each axis on this joystick provides positional feedback (potentiometers) and this information is used to ramp PTZ movement speed proportionally with the position of the joystick relative to its center.
> BILL OF MATERIALS
This project is built using the following components:
REQUIRED COMPONENTS:
- 1 @ Arduino MKR1000 (WiFI) https://store.arduino.cc/usa/arduino-mkr1000
- 1 @ Diymall 0.96" Inch Yellow Blue I2C Oled 128x64 for Arduino (128x64) http://amzn.to/2CvIJG8
- 1 @ Uxcell 10K Momentary Pushbutton Switch Joystick Potentiometer http://amzn.to/2BBTWrU
- 1 @ Hammond 1591TSBK Plastic Enclosure (Black) http://amzn.to/2CA4812
OPTIONAL COMPONENTS:
- 1 @ Adafruit Lithium Ion Polymer Battery 3.7V 1200mAh http://amzn.to/2EDDZV2
- 1 @ 10-wire Ribbon Cable (Hook up wire) http://amzn.to/2ECzv0N
- 1 @ Micro USB Regulated Power Supply (5VDC 1A) http://amzn.to/2HqFFyT
> HARDWARE
The hardware assembly for this project is relatively simple but special care must be given to the joystick wires as the wire coloring scheme is not intuitive. Use the wiring diagram below to wire up the OLED module and 3-axis joystick to the Arduino MKR1000 board.
The OLED module uses the I2C bus to communicate between the module and the micro-controller. 4 wires need to be connected between the MKR100 and the OLED module. The photos below depict the wires/colors used in this example.
- GREEN - GROUND
- BLUE - VCC (3.3VDC)
- PURPLE - SCL (clock)
- GRAY - SDA (data)
The next step is connecting the 3-axis joystick. The joystick consists of 3 potentiometers (1 for each axis) and 1 momentary switch. First, connect the common VCC and GROUND to each of the 3 potentiometers. The X and Y axis potentiometers have bare terminals exposed and are wired as follows:
- LEFT PIN: GROUND
- CENTER PIN: WIPER (signal)
- RIGHT PIN: VCC (3.3VDC)
The Z-axis potentiometer is encapsulated inside the unit and has lead wires coming out from the internals with an odd (unconventional) colored wiring scheme as follows:
- RED: GROUND
- WHITE: VCC (3.3VDC)
- BLACK: WIPER (signal)
- 2 @ YELLOW: contact closure for the momentary button
In addition to the potentiometer leads, also connect one of the yellow leads to GROUND.
There are 5 wires that travel from the joystick to the micro-controller board (MKR1000). These are as follows (per the images below):
- GREEN - GROUND
- BLUE - VCC (3.3VDC)
- BUTTON SWITCH > YELLOW > GPIO 0 (digital input)
- Z-AXIS WIPER > BLACK > A4 (analog input)
- Y-AXIS WIPER > GRAY > A6 (analog input)
- X-AXIS WIPER > PURPLE > A5 (analog input)
These connections should result in a fully assembled prototype ready for installation of the Monocle PTZ software on the Arduino board. NOTE: A Lithium ION battery back may be added for a completely wireless solution. The battery specified in the bill of materials is compatible and supported by the charging circuit built into the MKR1000 hardware.
> SOFTWARE/FIRMWARE
The source code for this project can be found here: https://github.com/MonocleCam/MonocleArduino/tree/master/examples/Monocle_PTZController_Deluxe_MKR1000
However, if the Monocle Arduino Library is installed in the Arduino IDE, simply open the Monocle_PTZController_Deluxe_MKR1000
project from the File > Examples > Monocle IP Camera Library
menu as show below.
The Arduino IDE will open the example project which can then be saved to a new location/path for user customizations. Edit the "private.h" file and add the configuration details such as the wireless network credentials and address of the Monocle gateway.
/**
* YOUR WIRELESS NETWORK ACCESS POINT SSID AND PASSWORD
*/
#define WIFI_SSID "your_wifi_ssid_goes_here"
#define WIFI_PASS "your_wifi_password_goes_here"
/*
* YOUR MONOCOLE GATEWAY LOCAL IP ADDRESS/HOSTNAME
*/
#define MONOCLE_GATEWAY_ADDRESS "10.1.1.20"
#define MONOCLE_GATEWAY_PORT 8080
In the main program, look in the constants section to see if there are any adjustments required for user specific environment/preferences.
/* JOYSTICK CONTROLLER PINS */
#define PIN_PAN A5 // analog input pin 5 (PAN) <X-AXIS>
#define PIN_TILT A6 // analog input pin 6 (TILT) <Y-AXIS>
#define PIN_ZOOM A4 // analog input pin 4 (ZOOM) <Z-AXIS>
#define PIN_BUTTON 0 // joystick center (select) button
/* IF YOUR PTZ JOYSTICK IS WORKING BACKWARDS, YOU CAN INVERT EACH AXIS HERE */
#define INVERT_PAN_AXIS true
#define INVERT_TILT_AXIS false
#define INVERT_ZOOM_AXIS true
/* CONFIGURE THE THRESHOLD FOR EACH AXIS STATE: LOW, MED, and HIGH */
#define JOYSTICK_THRESHOLD_LOW 500
#define JOYSTICK_THRESHOLD_MED 1300
#define JOYSTICK_THRESHOLD_HIGH 1900
/* DEFINE THE ADC RESOLUTION FOR JOYSTICK ANALOG PINS */
#define ADC_RESOLUTION 12
/* DEFINE THE DEBOUNCE INTERVAL FOR THE JOYSTICK BUTTON */
#define BUTTON_DEBOUNCE_INTERVAL 5 // milliseconds
/* DEFINE THE OLED MODULE SIZE (128x32 and 128x64 are supported) */
#define OLED_WIDTH 128
#define OLED_HEIGHT 64
There is one potentially ugly detail related to this #error definition.
/* VERIFY THAT THE UNDERLYING ADAFRUIT SSD1306 LIBRARY IS CONFIGURED PROPERLY FOR A 128x64 OLED DISPLAY */
#if (SSD1306_LCDHEIGHT != OLED_HEIGHT)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif
If this error appears, the "Adafruit_SSD1306.h
" file in the Adafruit_SSD1306
library should be opened and the following block edited to include the specific OLED module size in use.
/*=========================================================================
SSD1306 Displays
-----------------------------------------------------------------------
The driver is used in multiple displays (128x64, 128x32, etc.).
Select the appropriate display below to create an appropriately
sized framebuffer, etc.
SSD1306_128_64 128x64 pixel display
SSD1306_128_32 128x32 pixel display
SSD1306_96_16
-----------------------------------------------------------------------*/
#define SSD1306_128_64
// #define SSD1306_128_32
// #define SSD1306_96_16
/*=========================================================================*/
At this point, the project can be successfully compiled and uploaded to the connected Arduino MKR1000.
> ENCLOSURE / CASE
A fully working unit may be mounted in an enclosure. Here are a few photos taken while mounting the components into a plexiglass surface. Clear plexiglass, rather than the included case lid, was used for demonstration purposes and to under-mount the OLED without losing visualization of the user interface.
Below are a few photos of the finished project. The unit should feel solid and robust.
NOTE: Please see the video at the top of this section for more details on the runtime operation of this controller.
This project implements a small 2-axis joystick controller with an Arduino MKR1000 to provide virtually the same features as the Deluxe version of this project but with a more compact form factor and without a direct means of zoom control. The project does support zoom, but is accessed via the menu system. (Note: zoom and tilt functions cannot operate simultaneously as they can with the Deluxe controller). This project implements a tiny OLED module (128x32 pixels) to serve as a user interface for menu navigation.
> BILL OF MATERIALS
This project is built using the following components:
REQUIRED COMPONENTS:
- 1 @ Arduino MKR1000 (WiFI) https://store.arduino.cc/usa/arduino-mkr1000
- 1 @ MakerFocus 2pcs I2C OLED Display Module 0.91 inch (128x32) http://amzn.to/2BBvqXX
- 1 @ Adafruit Analog 2-axis Thumb Joystick with Select Button http://amzn.to/2HoXlea
- 1 @ Serpac A21 ABS Plastic Enclosure, Black http://amzn.to/2CalAxe
OPTIONAL COMPONENTS:
- 1 @ Adafruit Lithium Ion Polymer Battery 3.7V 1200mAh http://amzn.to/2EDDZV2
- 1 @ 10-wire Ribbon Cable (Hook up wire) http://amzn.to/2ECzv0N
- 1 @ Micro USB Regulated Power Supply (5VDC 1A) http://amzn.to/2HqFFyT
> HARDWARE
The hardware assembly for this project is very simple, as shown in the wiring diagram below.
The OLED module uses the I2C bus to communicate between the module and the micro-controller. This requires connection of 4 wires between the MKR100 and the OLED module. The photos below depict the wires/colors used in this example.
- GREEN - GROUND
- BLUE - VCC (3.3VDC)
- PURPLE - SCL (clock)
- GRAY - SDA (data)
Next, connect the 2-axis joystick. The joystick consists of 2 potentiometers (1 for each axis) and 1 momentary switch. The breakout board that this joystick comes with makes connecting it very simple.
- VCC > RED > VCC (3.3VDC)
- X-OUT (WIPER) > ORANGE > A5 (analog input)
- Y-OUT (WIPER) > YELLOW > A6 (analog input)
- SEL (momentary button) > GREEN > GPIO 0 (digital input)
- GND > BROWN > GROUND
At this point, the fully assembled prototype is ready for installation of the Monocle PTZ software on the Arduino board. NOTE: A Lithium ION battery back may be added for a completely wireless solution. The battery specified in the bill of materials is compatible and supported by the charging circuit built into the MKR1000 hardware.
> SOFTWARE/FIRMWARE
The source code for this project can be found here: https://github.com/MonocleCam/MonocleArduino/tree/master/examples/Monocle_PTZController_Basic_MKR1000
However, if the Monocle Arduino Library is installed in the Arduino IDE, simply open the Monocle_PTZController_Basic_MKR1000
project from the File > Examples > Monocle IP Camera Library
menu as show below.
The Arduino IDE will open the example project which can then be saved to a new location/path for user customizations. Edit the "private.h" file and add the configuration details such as the wireless network credentials and address of the Monocle gateway.
/**
* YOUR WIRELESS NETWORK ACCESS POINT SSID AND PASSWORD
*/
#define WIFI_SSID "your_wifi_ssid_goes_here"
#define WIFI_PASS "your_wifi_password_goes_here"
/*
* YOUR MONOCOLE GATEWAY LOCAL IP ADDRESS/HOSTNAME
*/
#define MONOCLE_GATEWAY_ADDRESS "10.1.1.20"
#define MONOCLE_GATEWAY_PORT 8080
In the main program, look in the constants section to see if there are any adjustments required for user specific environment/preferences.
/* JOYSTICK CONTROLLER PINS */
#define PIN_PAN A5 // analog input pin 5 (PAN) <X-AXIS>
#define PIN_TILT A6 // analog input pin 6 (TILT) <Y-AXIS>
#define PIN_BUTTON 0 // joystick center (select) button
/* IF YOUR PTZ JOYSTICK IS WORKING BACKWARDS, YOU CAN INVERT EACH AXIS HERE */
#define INVERT_PAN_AXIS false
#define INVERT_TILT_AXIS false
/* CONFIGURE THE THRESHOLD FOR EACH AXIS STATE: LOW, MED, and HIGH */
#define JOYSTICK_THRESHOLD_LOW 500
/* DEFINE THE ADC RESOLUTION FOR JOYSTICK ANALOG PINS */
#define ADC_RESOLUTION 12
/* DEFINE THE DEBOUNCE INTERVAL FOR THE JOYSTICK BUTTON */
#define BUTTON_DEBOUNCE_INTERVAL 5 // milliseconds
/* DEFINE THE OLED MODULE SIZE (128x32 and 128x64 are supported) */
#define OLED_WIDTH 128
#define OLED_HEIGHT 32
There is one potentially ugly detail related to this #error definition.
/* VERIFY THAT THE UNDERLYING ADAFRUIT SSD1306 LIBRARY IS CONFIGURED PROPERLY FOR A 128x64 OLED DISPLAY */
#if (SSD1306_LCDHEIGHT != OLED_HEIGHT)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif
If this error appears, the "Adafruit_SSD1306.h
" file in the Adafruit_SSD1306
library should be opened and the following block edited to include the specific OLED module size in use.
/*=========================================================================
SSD1306 Displays
-----------------------------------------------------------------------
The driver is used in multiple displays (128x64, 128x32, etc.).
Select the appropriate display below to create an appropriately
sized framebuffer, etc.
SSD1306_128_64 128x64 pixel display
SSD1306_128_32 128x32 pixel display
SSD1306_96_16
-----------------------------------------------------------------------*/
// #define SSD1306_128_64
#define SSD1306_128_32
// #define SSD1306_96_16
/*=========================================================================*/
At this point the project can be successfully compiled and uploaded to the connected Arduino MKR1000.
> ENCLOSURE / CASE
A fully working unit may be mounted in an enclosure. This example was mounted on a plexiglass sub-straight for display and prototyping purposes, but an enclosure to protect the micro-controller board would be more practical. This one should work nicely: http://amzn.to/2EUcAgR
NOTE: Please see the video at the top of this section for more details on the runtime operation of this controller.
Retro gaming and computing holds a special place in the hearts of many, and a few people, including those at Monocle, actually still have some of these joysticks around the house! This project builds a PTZ controller for the camera based on a retro gaming joystick, using an Atari / Commodore compatible joystick in this particular example. This project is straightforward to build and understand. It makes use of simple digital inputs and the build can easily be housed in a small plastic enclosure for a very clean and simple finished product.
This controller implementation is basic with no user interface, but still supports the essential PTZ functions as follows:
- Joystick Up > Tilt Camera Up
- Joystick Down > Tilt Camera Down
- Joystick Left > Pan Camera Left
- Joystick Right > Pan Camera Right
- Joystick Up + Button Pressed > Zoom Camera In
- Joystick Down + Button Pressed > Zoom Camera Out
- Button Double Click > Restore Camera to Home Position
A number of examples of this project are provided for various micro-controller board including the Arduino MKR1000 board, an ESP8266 and ESP32 board. All of the variations of this sample are included with the Monocle Arduino Library and also available in Monocle's GitHub repository.
This article will focus on the ESP8266 variant due to its low cost and wide availability.
> BILL OF MATERIALS
This project is built using the following components:
REQUIRED COMPONENTS:
- 1 @ Makerfocus D1 Mini NodeMcu 4M ESP8266 ESP-12F http://amzn.to/2FfOsDd
- 1 @ DB9 Male Solder D-SUB Connector with Plastic Shell http://amzn.to/2FeytF7
- 1 @ CirKa "A77" Premium Joystick Controller for Atari 2600 (or any Atari/Commodore compatible joystick) http://amzn.to/2CvvN3j
- 1 @ 2.2"x1.4"x 0.6" Plastic Electric Project Case http://amzn.to/2GxxyiS
ALTERNATE COMPONENTS:
If screw terminals are preferred over soldering the DB9 connector, one of the following may be more suitable:
- 1 @ DB9 RS232 D-SUB Male Adapter 9-pin Port Adapter to Terminal Connector Signal Module With case http://amzn.to/2sEgDJd
- 1 @ DB9 D-SUB 9 Pin Male Adapter RS232 to Terminal Connector Signal Module http://amzn.to/2ENA8E7
OPTIONAL COMPONENTS:
- 1 @ Micro USB Regulated Power Supply (5VDC 1A) http://amzn.to/2HqFFyT
- 1 @ Makerfocus Breadboard Kit Breadboard Jumper wires USB cable Hookup for Arduino http://amzn.to/2C6ZprU
> HARDWARE
The hardware assembly for this project is extremely simple as shown in the wiring diagram below.
6 wires are required for the connection between the micro-controller board and the DB9 male connector. First, solder these wires into the DB9 connector as below.
- PIN 1 (up) - BLUE
- PIN 2 (down) - GREEN
- PIN 3 (left) - YELLOW
- PIN 4 (right) - ORANGE
- PIN 6 (button) - RED
- PIN 9 (ground) - BROWN
Next, attach the 6 wires to the ESP8266 micro-controller board.
- D5 (up) - BLUE
- D1 (down) - GREEN
- D2 (left) - YELLOW
- D3 (right) - ORANGE
- D4 (button) - RED
- GROUND (ground) - BROWN
At this point, the prototype is complete and ready for installation of the Monocle software on the ESP8266 board.
> SOFTWARE/FIRMWARE
The source code for this project can be found here:
- ARDUINO MKR1000 : https://github.com/MonocleCam/MonocleArduino/tree/master/examples/Monocle_PTZController_AtariJoystick_MKR1000
However, if the Monocle Arduino Library is installed in the Arduino IDE, simply open the Monocle_PTZController_AtariJoystick_ESP8266
project from the File > Examples > Monocle IP Camera Library
menu as show below.
The Arduino IDE will open the example project which can then be saved to a new location/path for user customizations. Edit the "private.h" file and add the configuration details such as the wireless network credentials and address of the Monocle gateway.
/**
* YOUR WIRELESS NETWORK ACCESS POINT SSID AND PASSWORD
*/
#define WIFI_SSID "your_wifi_ssid_goes_here"
#define WIFI_PASS "your_wifi_password_goes_here"
/*
* YOUR MONOCOLE GATEWAY LOCAL IP ADDRESS/HOSTNAME
*/
#define MONOCLE_GATEWAY_ADDRESS "10.1.1.20"
#define MONOCLE_GATEWAY_PORT 8080
In the main program, look in the constants section of the program to see if there are any adjustments required for user specific environment/preferences.
/* DEFINE PAN, TILT, ZOOM SPEEDS */
#define PAN_SPEED 2 // 1=low, 2=medium; 3=high
#define TILT_SPEED 2 // 1=low, 2=medium; 3=high
#define ZOOM_SPEED 2 // 1=low, 2=medium; 3=high
/* BELOW IS THE PINOUT FOR A ATARI/COMMODORE JOYSTICK DB9 CONNECTOR */
// Pin 1 : Up
// Pin 2 : Down
// Pin 3 : Left
// Pin 4 : Right
// Pin 5 : <not used>
// Pin 6 : Trigger/Fire
// Pin 7 : <not used>
// Pin 8 : Ground
// Pin 9 : <not used>
/* DEFINE JOYSTICK DIGITAL INPUT PINS */
#define JOYSTICK_PIN_UP 14 // <digital input pin>
#define JOYSTICK_PIN_DOWN 12 // <digital input pin>
#define JOYSTICK_PIN_LEFT 13 // <digital input pin>
#define JOYSTICK_PIN_RIGHT 15 // <digital input pin>
#define JOYSTICK_PIN_FIRE 5 // <digital input pin>
At this point, the project can be successfully compiled and uploaded to the connected ESP8266.
> ENCLOSURE / CASE
With a fully working unit, install the D-Sub shroud and place the micro-controller into a plastic enclosure as shown in the photos below. The enclosures included in the bill of materials above have just enough room for the Wemos D1 Mini ESP8266 module and already have holes predrilled on each end., but extra plastic may need to be removed on the end where the micro USB connector attaches.
NOTE: Please see the video at the top of this section for more details on the runtime operation of this controller.
Some users will prefer a more discrete form of PTZ control without a joystick sitting on the coffee table or nightstand. This project implements the PTZ controller in the form of a very compact infrared remote control. This project is among the simplest PTZ controllers in our sample projects. In fact, it is probably the easiest one to build, only requiring three pins connected from a tiny IR receiver to the micro-controller. It can easily be housed in a small plastic enclosure and kept in a discrete location.
The remote control implementation is basic with no user interface, but it supports all of the same PTZ functions as the deluxe controller project. The remote control functions as follows:
- [ LEFT ] - PAN LEFT (continuous while held down)
- [ RIGHT ] - PAN RIGHT (continuous while held down)
- [ UP ] - TILT UP (continuous while held down)
- [ DOWN ] - TILT DOWN (continuous while held down)
- [ * ] - ZOOM IN (continuous while held down)
- [ # ] - ZOOM OUT (continuous while held down)
- [ 0 ] - GOTO HOME POSITION
- [ 1 ] - RECALL PRESET 1
- [ 2 ] - RECALL PRESET 2
- [ 3 ] - RECALL PRESET 3
- [ 4 ] - RECALL PRESET 4
- [ 5 ] - RECALL PRESET 5
- [ 6 ] - RECALL PRESET 6
- [ 7 ] - RECALL PRESET 7
- [ 8 ] - RECALL PRESET 8
- [ 9 ] - RECALL PRESET 9
Examples are provided using the Arduino MKR1000 board and the ESP32 board. All of the variations of this sample are included with the Monocle Arduino Library and are also available in Monocle's GitHub repository.
This article will focus on the ESP32 variant due to its small form factor and ability to be placed in a small plastic enclosure.
> BILL OF MATERIALS
This project was built using the following components:
REQUIRED COMPONENTS:
- 1 @ Makerfocus ESP32 Development Board Wemos Lolin for Arduino http://amzn.to/2EBFYsF
- 1 @ WINGONEER IR Wireless Remote Control Sensor Module Kit for Arduino http://amzn.to/2sDvXWv
- 1 @ 2.2"x1.4"x 0.6" Plastic Electric Project Case http://amzn.to/2GxxyiS
OPTIONAL COMPONENTS:
- 1 @ AIRSUNNY 5 pairs Infrared Diode LED 38KHz IR Emission and Receiver http://amzn.to/2BBQ5v6
- 1 @ Micro USB Regulated Power Supply (5VDC 1A) http://amzn.to/2HqFFyT
- 1 @ Makerfocus Breadboard Kit Breadboard Jumper wires USB cable Hookup for Arduino http://amzn.to/2C6ZprU
> HARDWARE
The hardware assembly for this project is extremely simple as shown in the wiring diagram below.
The IR remote control kit in this example initially included an IR receiver mounted on a small breadboard. Since a compact design was desired, individual 38KHz IR receiver units were used and mounted directly to the WeMo Lolin ESP32 board as depicted in the photos below. The IR receiver just needs to be connected to GROUND, VCC (3.3VDC) and its DATA pin needs to be connected to a digital input pin on the micro-controller. A small jumper wire was used to connect the data pin from the IR receiver to GPIO digital input 4 on the ESP32 board.
- LEFT PIN (DATA) > GPIO 4
- CENTER PIN (GROUND) > GND
- RIGHT PIN (VSS) > 3V
At this point, the Monocle PTZ Controller software can be installed on the ESP32 module.
> SOFTWARE/FIRMWARE
The source code for this project can be found here:
- ARDUINO MKR1000 : https://github.com/MonocleCam/MonocleArduino/tree/master/examples/Monocle_PTZController_IRRemote_MKR1000
However, if the Monocle Arduino Library is installed in the Arduino IDE, simply open the Monocle_PTZController_IRRemote_ESP32
project from the File > Examples > Monocle IP Camera Library
menu as show below.
The Arduino IDE will open the example project which can then be saved to a new location/path for user customizations. Edit the "private.h" file and add the configuration details such as the wireless network credentials and address of the Monocle gateway.
/**
* YOUR WIRELESS NETWORK ACCESS POINT SSID AND PASSWORD
*/
#define WIFI_SSID "your_wifi_ssid_goes_here"
#define WIFI_PASS "your_wifi_password_goes_here"
/*
* YOUR MONOCOLE GATEWAY LOCAL IP ADDRESS/HOSTNAME
*/
#define MONOCLE_GATEWAY_ADDRESS "10.1.1.20"
#define MONOCLE_GATEWAY_PORT 8080
In the main program, look in the constants section of the program to see if there are any adjustments required for user specific environment/preferences.
/* DEFINE THE PIN NUMBER USED TO CONNECT THE DATA INPUT FROM IR RECEIVER */
#define IR_REMOTE_RECEIVE_DATA_PIN 4
/* DEFINE IR CODES FOR YOUR REMOTE CONTROL HERE */
#define REMOTE_OK_BUTTON 0xFF38C7 // (STOP)
#define REMOTE_UP_BUTTON 0xFF18E7 // (TILT UP)
#define REMOTE_DOWN_BUTTON 0xFF4AB5 // (TILT DOWN)
#define REMOTE_LEFT_BUTTON 0xFF10EF // (PAN LEFT)
#define REMOTE_RIGHT_BUTTON 0xFF5AA5 // (PAN RIGHT)
#define REMOTE_STAR_BUTTON 0xFF6897 // (*)
#define REMOTE_HASH_BUTTON 0xFFB04F // (#)
#define REMOTE_0_BUTTON 0xFF9867 // (HOME PRESET)
#define REMOTE_1_BUTTON 0xFFA25D // (PRESET 1)
#define REMOTE_2_BUTTON 0xFF629D // (PRESET 2)
#define REMOTE_3_BUTTON 0xFFE21D // (PRESET 3)
#define REMOTE_4_BUTTON 0xFF22DD // (PRESET 4)
#define REMOTE_5_BUTTON 0xFF02FD // (PRESET 5)
#define REMOTE_6_BUTTON 0xFFC23D // (PRESET 6)
#define REMOTE_7_BUTTON 0xFFE01F // (PRESET 7)
#define REMOTE_8_BUTTON 0xFFA857 // (PRESET 8)
#define REMOTE_9_BUTTON 0xFF906F // (PRESET 9)
// when a button on this remote is held, this code is continually emitted
#define REMOTE_REPEAT 0xFFFFFFFF
// define the PAN, TILT, ZOOM speeds to use when pressing the remote buttons
#define PAN_SPEED 2 // 1=low, 2=medium; 3=high
#define TILT_SPEED 2 // 1=low, 2=medium; 3=high
#define ZOOM_SPEED 2 // 1=low, 2=medium; 3=high
At this point, the project can be successfully complied and uploaded to the connected ESP32.
If the IR remote does not register any activity, the decoded IR signals may need to be debugged via the serial output of the ESP32 board. There is a section of code in the main program loop that is commented out but can be uncommented to see the raw decoded IR values printed in a terminal window.
// display the IR code to the user
// DEBUG - enable this if you need to see the raw decoded IR button values
Serial.print("<< IR BUTTON RX: ");
Serial.print(results.value, HEX);
Serial.println(" >>");
Different remote controls may require remapping of the IR codes defined in the constants section of the code for the specific remote control.
> ENCLOSURE / CASE
After testing the unit, it may be mounted in a small plastic enclosure as shown in the photos below. The enclosures included in the bill of materials above have just enough room for the Wemos Lolin ESP32 module and already have holes predrilled on each end. However, fitting the micro USB power port required a pair of nippers to cut away a slot in the sidewall of the enclosure to allow the micro USB cable to attach.
The enclosure with the IR receiver can now sit on a shelf or in your entertainment center in a discrete location and the cameras can be controlled from across the room with the IR remote control.
NOTE: Please see the video at the top of this section for more details on the runtime operation of this controller.
With the hard deadline of the Hackster.io contest "The Alexa and Arduino Smart Home Challenge," even working at a feverish pace, I was not able to have all the planned features functional by the deadline of this project. Plans are in place for improvement and enhancement of the current features as well as release of new features. Please comment about any desires for these future enhancements so I can prioritize which may be the most beneficial.
> Monocle Configuration App
I would like to provide a desktop and/or mobile app to assist users with getting their camera configuration defined and uploaded to Monocle. The ONVIF protocol supports device discovery, and a Monocle app could help discover the cameras available on the users network and more accurately obtain the unique RTSP feed URL required for each camera.
> Monocle Cloud Control
I also plan to support recalling camera presets and providing PTZ control directly from the Monocle Web Portal. This is also in preparation for Monocle integration with other cloud services such as IFTTT and smart hubs such as SmartThings and OpenHAB.
> Change Selected Camera on PTZ Controller
Another future enhancement will allow the user to directly change the active camera they are controlling on the PTZ controller. Currently the PTZ controller controls the last camera Alexa was asked to view. However, situations arise where the user may want to change the active camera they are controlling without going through Alexa. With the BASIC and DELUXE PTZ controller projects, the OLED screen provides menu navigation. On these devices, a future menu option could allow the user to change the active camera and navigate to the named camera they wish to control.
> Save Presets from the PTZ Controller
I am currently working on support to save camera presets directly from the PTZ controllers.
> Low Power PTZ Controller
Functionality, usability and built simplicity were my initial priorities. However, I have plans to develop a more power efficient solution for long term battery operation, likely in the form of a dedicated micro-controller chip focusing on sleep timers and low power modes. For ultra low power, a different wireless communication technology rather than WiFi may be considered such as a BLE (Bluetooth Low Energy). An Adafruit nRF52832 Feather board with a built in LIPO charger may be an ideal candidate for a low power consumption controller while maintaining relative ease for DIY builds.
> Alexa Custom Skill
I would like to implement the ability to recall presets using voice commands via the Alexa Skill. However, at this time Amazon does not support natively camera presets in their Smart Home Skills API. I would love the opportunity to partner with the Amazon Alexa Team to create an extension to the existing Alexa.CameraStreamController
interface to add support for camera presets.
> Monocle Viewer App
I also have plans to develop a Monocle desktop and/or mobile app allowing the user to easily view and control the cameras. With the app connected to Monocle, duplication of camera feed configuration inside each app could be avoided.
Monocle has a long way to go to before reaching the ultimate goal of ubiquitous centralized camera access and control. I welcome you along the journey with me to reach these goals and improve the landscape for a modern surveillance/security camera experience.
If you have found this project moderately useful, mildly entertaining or even mind-blowingly invaluable, please take a moment to Respect (Like) and Share this project here on Hackster.io
You can also help me by reviewing the Monocle Smart Home skill in your Alexa app or via this link: http://amzn.to/2CAutMr
I would love to hear your opinion on this project and the future plans/ enhancements. Please feel free to comment on this article and I will do my best to keep up and respond.
You can also reach out to me using the contact form on the website: https://monoclecam.com/contact
I would like to thank Hackster.io, Arduino and Amazon for sponsoring the "The Alexa and Arduino Smart Home Challenge". The challenge provided motivation to focus on building and delivering a voice controlled camera solution for the public. It may be quick and easy to build a self serving hack/solution that solves an individual's needs, but building out the infrastructure, websites, documentation, support channels and publishing an Alexa skill for public consumption is a different story and a notable endeavor. I am grateful for the lessons learned and experience gained during this effort.
I would like to thank the BETA users who have jumped in to help test the Monocle platform and Monocle Alexa Smart Home skill in their home environments. Your contributions have helped me improve the system and prepare a path for more users to join.
On a personal note, I would like to thank my wonderfully understanding and patient wife who also provided the encouragement and self sacrifice for me to take on this challenge and commitment of time. I only learned about this contest in mid-January so its been just over a month of time entirely focused on this project.
And finally, thank you to the readers and supporters of this project. Your support affirms my belief in the mantra "If you build it ... they will come ..".
Thank You!
Comments