EasyManuals Logo

Arduino uno User Manual

Arduino uno
311 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #236 background imageLoading...
Page #236 background image
In line 3, we read the next separated string, which contains the actual path.
If you were to pass the request
GET http://192.168.2.42/SAMSUNG/32/E0E040BF HTTP/1.1
to
handle_command
,
path
would contain
/SAMSUNG/32/E0E040BF
now.
At this stage, we have a string consisting of three strings separated by a slash
character (/). Its time to use
strsep
again, and if you understand what happens
in lines 6 to 9, then you can call yourself familiar with both C and the
strsep
function. In the end, the array
args
contains all three path elements. We can
pass the protocol name directly to
send_ir_data
, but we have to turn the bit
length and the value of the code into
int
and
long
values before. For the conver-
sion, we use the
atoi
and
strtoul
functions. We use the latter one to convert a
hexadecimal value to a decimal value.
Now we have defined all helper methods we need, and we only have to
implement the only public method of the
InfraredProxy
class:
RemoteControl/InfraredProxy/infrared_proxy.cpp
void InfraredProxy::receive_from_server(EthernetServer server) {
Line 1
const int MAX_LINE = 256;
-
char line[MAX_LINE];
-
EthernetClient client = server.available();
-
if (client) {
5
while (client.connected()) {
-
if (client.available()) {
-
read_line(client, line, MAX_LINE);
-
Serial.println(line);
-
if (line[0] == 'G' && line[1] == 'E' && line[2] == 'T')
10
handle_command(line);
-
if (!strcmp(line, "")) {
-
client.println("HTTP/1.1 200 OK\n");
-
break;
-
}
15
}
-
}
-
delay(1);
-
client.stop();
-
}
20
}
-
The
receive_from_server
method finally implements the core logic of our
InfraredProxy
class. It expects an instance of the
EthernetServer
class that is defined in the
Ethernet library. It waits for a client to connect using
EthernetServer
s
available
method in line 4. Whenever the server is connected to a client, it checks
whether the client has new data using
EthernetClient
s
available
method in line 7.
receive_from_server
reads the data sent by the client line by line, calling
read_line
.
It prints each line to the serial port for debugging purposes, and for every line
Chapter 12. Creating Your Own Universal Remote Control 220
report erratum discuss
www.it-ebooks.info

Table of Contents

Other manuals for Arduino uno

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the Arduino uno and is the answer not in the manual?

Arduino uno Specifications

General IconGeneral
Form factorArduino
CertificationRoHS, FC, CE
Processor model-
Processor frequency- MHz
Microcontroller modelATmega328
Microcontroller frequency16 MHz
DC input voltage7-12 V
Operating voltage5 V
DC current per I/O pin40 mA
Flash memory0.032 MB
Maximum internal memory- GB
SRAM (Static Random Access Memory)2 KB
EEPROM (Electrically Erasable Programmable Read-Only Memory)1 KB
Wi-FiNo
Number of analog I/O pins6
Number of digital I/O pins14
Weight and Dimensions IconWeight and Dimensions
Board dimensions53.4 x 68.6 mm

Related product manuals