In this case, the protocol name is SAMSUNG, the length of the command code
is 32 bits, and the command code is E0E040BF (the hexadecimal number we
grabbed in Grabbing Remote Control Codes, on page 203).
We already used the Arduino as a web client in Chapter 10, Networking with
Arduino, on page 163, but now we need to turn it into a web server. The server
waits for new HTTP requests like the one shown previously, parses the URL,
and emits the corresponding infrared signal.
We’ll hide all of these details in a class named
InfraredProxy
, and to keep things
as easy and as concise as possible, we’ll make use of both the Ethernet and
the IRremote library. The
InfraredProxy
class is still one of the book’s most
sophisticated examples of Arduino code. Here’s its interface:
RemoteControl/InfraredProxy/infrared_proxy.h
#include <SPI.h>
#include <Ethernet.h>
#include <IRremote.h>
class InfraredProxy {
private:
IRsend _infrared_sender;
void read_line(EthernetClient& client, char* buffer, const int buffer_length);
bool send_ir_data(const char* protocol, const int bits, const long value);
bool handle_command(char* line);
public:
void receive_from_server(EthernetServer server);
};
After including all libraries needed, we declare the
InfraredProxy
class. We define
a member variable named
_infrared_sender
that stores an
IRsend
object we need
to emit infrared control codes. Then we declare three private helper methods
and the
receive_from_server
method, which is the only public method of the
InfraredProxy
class.
Let’s have a look at the implementation of all methods. We’ll start with
read_line
:
report erratum • discuss
Building an Infrared Proxy • 217
www.it-ebooks.info