Hello,
I need help. I wrote a program for controlling the TV with the help of Arduino and web interface. I have attached IR LED 3 and IR receivers on the 5th
Originally I thought html code, save to SD. After about 10 rewrite the program I was looking for a bug that is also reflected in the simplified code. Following the adoption of the headers from the browser to store the first row to the variable (lineone) then sends the HTML browser. Transformations subsequently evaluate. The problem comes when you add additional html code. This transformation is not empty and what to evaluate.
I attach the code. Pro Setup Error simply uncomment another html code.
I've already thought of it and bad arduino.
Can you please help?
#include <SPI.h>
#include <Ethernet.h>
#include <IRremote.h>
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {0x22, 0x11, 0x1A, 0x0B, 0x41, 0x56 };
IPAddress ip(10,0,0, 150); // IP address, may need to change depending on network
// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);
String lineone = "";
IRsend irsend;
unsigned int raw1[] = {16340,8950,4350,600,500,600,500,600,1650,600,500,600,500,600,500,600,500,600,500,600,1600,600,1650,550,550,550,1650,600,1600,600,1650,600,1600,600,1650,600,500,600,1600,600,500,600,500,600,500,600,500,600,500,600,500,600,1650,600,500,600,1600,600,1650,600,1600,600,1650,600,1600,600,1650,600};
String baf = "";
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
server.begin();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
// disable the SD card by switching pin 4 high
// not using the SD card in this program, but if an SD card is left in the socket,
// it may cause a problem with accessing the Ethernet chip, unless disabled
pinMode(4, OUTPUT);
digitalWrite(4, HIGH);
}
void loop() {
// listen for incoming clients
EthernetClient client = server.available();
if (client) {
Serial.println("new client");
// an http request ends with a blank line
// lineone = "";
boolean currentLineIsBlank = true;
baf = "";
baf.reserve(58);
byte radek = 0;
while (client.connected()) {
if (client.available()) {
char c = client.read();
baf += c;
//Serial.println(baf);
Serial.write(c);
// if you've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
if (c == '\n' && currentLineIsBlank) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close"); // the connection will be closed after completion of the response
//client.println("Refresh: 5"); // refresh the page automatically every 5 sec
client.println();
client.println("<!DOCTYPE HTML>");
client.println("<html>");
client.println("<head>");
//client.println("<meta name='viewport' content='initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,width=device-width,height=device-height,target-densitydpi=device-dpi,user-scalable=yes' />");
client.println("<meta name='viewport' content='width=device-width, user-scalable=no'>");
client.println("<title>Arduinio Server - REMOTE control</title>");
client.println("</head>");
client.println("<body>");
// output the value of each analog input pin
client.println("<a href='?but01=101'><button style='background:red;width:49%;height:40px'>POWER</button></a>");
client.println("<a href='http://10.0.0.150?but01=201'><button style='background:green;width:49%;height:40px'>MUTE</button></a>
");
client.println("<a href='?but01=103'><button style='background:green;width:49%;height:40px'>VOL+</button></a>");
client.println("<a href='?but01=104'><button style='background:green;width:49%;height:40px'>PROG+</button></a>
");
client.println("<a href='?but01=105'><button style='background:green;width:49%;height:40px'>VOL-</button></a>");
client.println("<a href='?but01=201'><button style='background:green;width:49%;height:40px'>PROG-</button></a>
");
/**
client.println("<center><a href='?but01=105'><button style='background:green;width:49%;height:40px'>UP</button></a></center>
");
client.println("<a href='?but01=105'><button style='background:green;width:49%;height:40px'>LEFT</button></a>");
**/
/**
client.println("<a href='?but01=201'><button style='background:green;width:49%;height:40px'>RIGHT</button></a>
");
client.println("<center><a href='?but01=105'><button style='background:green;width:49%;height:40px'>DOWN</button></a></center>
");
**/
client.println("</body>");
client.println("</html>");
Serial.println(lineone);
break;
}
if (c == '\n') {
// you're starting a new line
radek ++;
//Serial.println(radek);
if (radek == 1) {
baf.trim();
//Serial.print(">>>");
//Serial.println(baf);
lineone.reserve(58);
lineone = baf;
baf = "";
}
currentLineIsBlank = true;
}
else if (c != '\r') {
// you've gotten a character on the current line
currentLineIsBlank = false;
}
}
}
// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();
Serial.println("client disonnected");
Serial.println(lineone.length());
if (lineone.length()>14) {
String temp;
int indexbut = lineone.indexOf("but"); //najde but v prvnim radku
if (indexbut != -1) { //pokud BUT existuje alespon jednou sloz nazev souboru
temp = lineone.substring(indexbut+6,indexbut+9); //vyrizne jmeno souboru
} else { temp = "nic"; }
Serial.println(temp);
//Serial.println(lineone);
if (temp=="103") {
for (int i = 0; i < 4; i++) {
irsend.sendNEC(0x20DF40BF, 32);
delay(100);
}
}
if (temp=="105") {
for (int i = 0; i < 4; i++) {
irsend.sendNEC(0x20DFC03F, 32);
delay(100);
}
}
if (temp=="101") {
for (int i = 0; i < 2; i++) {
irsend.sendNEC(0x20DF10EF, 32);
delay(40);
}
}
if (temp=="201") {
for (int i = 0; i < 2; i++) {
irsend.sendRaw(raw1, 68, 38);
delay(40);
}
}
}
}
}