© 2013 Sam Pottinger
Released under the GNU GPL v3 license.
Done for CU Engineering Honors Program
While some libraries exist that allow developers to control Arduino units
remotely, the constraints of the honor’s program’s orrery project exceed
the needs of free solutions but remain outside the realm of more expensive
platforms. To accomodate this niche, a simple HTTP-based web control system
allows the system to report its status while accepting user configuration
values.
This repository contains an Arduino library that simplifies communication with
the orrery’s web-based control service. By abstracting request, network, and
response operations, this library helps maintain loose coupling between
software components supporting the orrery project.
This solution offers local unit testing outside of the Arduino environment using
some custom dependency injection constructs. To run:
- Ensure the TESTING macro in OrreryWebControl.h is set to 1
- $ make OrreryWebControl_test
- ./OrreryWebControl_test
Arduino sketches only immediately require the OrreryWebControl.cpp and
OrreryWebControl.h files. However, the HTTPClient library will also need to be
installed (see https://github.com/interactive-matter/HTTPClient).
Assuming HTTPClient is installed,
- Locate the libraries directory in your Arduino sketches folder.
- Create a directory called “OrreryWebControl” in that libraries folder.
- Move OrreryWebControl.cpp and OrreryWebControl.h into that new directory.
- Ensure the TESTING macro in OrreryWebControl.h is set to 0
Following convention on the Arduino platform, the OrreryWebControl Arduino
Client library asks that its dependency (HTTPClient) be included explicitly
in the sketch before itself. This, in turn, requires the Ethernet library to be
linked before HTTPClient and the SPI library for that. The resulting set of
includes looks like:
#include <SPI.h>
#include <Dhcp.h>
#include <Dns.h>
#include <Ethernet.h>
#include <EthernetClient.h>
#include <EthernetServer.h>
#include <EthernetUdp.h>
#include <util.h>
#include <HTTPClient.h>
#include <OrreryWebControl.h>
#include <SPI.h>
#include <Dhcp.h>
#include <Dns.h>
#include <Ethernet.h>
#include <EthernetClient.h>
#include <EthernetServer.h>
#include <EthernetUdp.h>
#include <util.h>
#include <HTTPClient.h>
#include <OrreryWebControl.h>
// MAC address for the ethernet controller.
byte macAddr[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
OrreryWebControl webController;
int motorSpeed = 100;
int motorDraw = 200;
int rotations = 300;
void setup()
{
Ethernet.begin(macAddr);
}
void loop()
{
OrreryWebConfig latestWebConfig;
// ... other logic including something to maybe wait 3 seconds
webController.checkIn(&latestWebConfig, motorSpeed, motorDraw, rotations);
// ... other logic
}
The OrreryWebConfig struct has the following values:
- bool connectedSuccesfully: Indicates if a connection to the server was made.
- bool resultOK: Indicates if the server returned a result successfully.
- int statusCode: HTTP status code of the server response.
- bool successParse: Indicates if the response from the server was correctly parsed.
- float motorSpeed: The desired motor speed from the server’s user configuration record.
- bool relayEnabled: The desired relay state from the server’s user configuration record.
In practice, all of the following should be checked to see if they are true
after a request:
- connectedSuccesfully
- resultOK
- successParse
- HTTPClient (https://github.com/interactive-matter/HTTPClient) under the GNU GPL v3
- minunit (https://github.com/siu/minunit) under the MIT License