/*
* ir_sender
*
* Date: 2012-08-05 23:55:00 +0900 (Sun, 05 Aug 2012)
* Author: diabah( http://cubic9.com/ )
* Original: Arduino Ofiicial ( http://arduino.cc/en/Tutorial/WebServer )
*/#include <SPI.h>
#include <Ethernet.h>
#define BEGINNING_OF_LINE 0
#define PREFIX_LENGTH 4
#define DELIMITER "."// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
IPAddress ip(192, 168, 0, 40);
// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(3000);
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(19200);
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
server.begin();
}
void loop() {
char ir_code[255];
int cusror = 0;
int ir_cnt = 0;
// listen for incoming clients
EthernetClient client = server.available();
if (client) {
// an http request ends with a blank line
boolean beginflag = false;
while (client.connected()) {
if (client.available()) {
char c = client.read();
//Serial.write(c);
if (cusror == BEGINNING_OF_LINE && c == 'G') {
// if beginning of line is start with "GET"
beginflag = true;
} elseif (cusror == PREFIX_LENGTH + 1 && c == 'f') {
// if GET request is getting favicon
beginflag = false;
} elseif (cusror == BEGINNING_OF_LINE && c == '\r') {
// if beggining of line is CR
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connnection: close");
client.println();
client.println("<html>");
client.println("<body>");
client.println(ir_code);
client.println("</body>");
client.println("</html>");
char *part;
for(part = strtok(ir_code, DELIMITER); part; part = strtok(NULL, DELIMITER)) {
Serial.write(byte(atoi(part)));
}
break;
} elseif (beginflag == true) {
if (cusror == PREFIX_LENGTH) {
ir_cnt = -1;
} elseif (cusror > PREFIX_LENGTH){
if (c == ' ') {
// if current character is the space before "HTTP/1.1"
ir_code[ir_cnt] = '\0';
beginflag = false;
} else {
ir_code[ir_cnt] = c;
}
}
ir_cnt++;
}
cusror++;
if (c == '\n') {
cusror = BEGINNING_OF_LINE;
}
}
}
// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();
}
}
--- ir_sender.ino Sun Sep 22 00:50:32 2013
+++ ir_sender_apr9600.ino Sun Sep 22 00:52:44 2013
@@ -13,6 +13,8 @@
#define PREFIX_LENGTH 4
#define DELIMITER "."
+#define APR9600 2
+
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
@@ -24,7 +26,12 @@
EthernetServer server(3000);
void setup() {
- // Open serial communications and wait for port to open:
+ // initialize the digital pin as an output.
+ pinMode(APR9600, OUTPUT);
+ // reset digital pin connected to APR9600:
+ digitalWrite(APR9600, HIGH);
+
+ // Open serial communications and wait for port to open:
Serial.begin(19200);
@@ -55,6 +62,23 @@
// if GET request is getting favicon
beginflag = false;
} else
+ if (cusror == PREFIX_LENGTH + 1 && c == 's') {
+ // if GET request is requsting sound
+ beginflag = false;
+ digitalWrite(APR9600, LOW);
+ delay(500);
+ digitalWrite(APR9600, HIGH);
+ client.println("HTTP/1.1 200 OK");
+ client.println("Content-Type: text/html");
+ client.println("Connnection: close");
+ client.println();
+ client.println("<html>");
+ client.println("<body>");
+ client.println("sound");
+ client.println("</body>");
+ client.println("</html>");
+ break;
+ } elseif (cusror == BEGINNING_OF_LINE && c == '\r') {
// if beggining of line is CR
client.println("HTTP/1.1 200 OK");