- Sun May 08, 2016 5:06 am
#47102
I am trying this right now:
[lis]
#include <SoftwareSerial.h>
SoftwareSerial BT1(3, 2); // RX | TX
String W =" ";
char w ;
void setup()
{
Serial.begin(9600);
BT1.begin(9600);
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
pinMode(11, OUTPUT);
BT1.write("AT+CWMODE=3\r\n");
delay(1000);
BT1.write("AT+CIPMUX=1\r\n");
delay(1000);
BT1.write("AT+CIPSERVER=1,80\r\n");
delay(1000);
}
void loop()
{
if (BT1.available()) // WIFI - Serial
{ w = BT1.read() ;
Serial.print(w);
W = W + w ;
}
if (Serial.available()) // Serial - WIFI
{ char s = Serial.read();
BT1.print(s);
}
if ( w == '\n'){ // If ENTER
if ( W.indexOf("P13") > 0 )
{ digitalWrite( 13, !digitalRead(13)) ;
Serial.println("Invirtiendo pin 13");
}
if ( W.indexOf("P12") > 0 )
{ digitalWrite( 12, !digitalRead(12)) ;
Serial.println("Invirtiendo pin 12");
}
if ( W.indexOf("P11") > 0 )
{ digitalWrite( 11, !digitalRead(11)) ;
Serial.println("Invirtiendo pin 11");
}
W = "" ; w = ' ' ;
}
if ( w == '\n'){
String str = String("<html>");
str += "<head>";
str += "</head>";
str += "<body>";
str += "<h1 align='center'>Project</h1><h3 align='center'>Motores controlados por Web</h3>";
str += "<div style='text-align:center;'>";
str += "<button onClick=location.href='./?P11\' style='margin:auto;background-color: #84B1FF;color: snow;padding: 10px;border: 1px solid #3F7CFF;width:65px;'>";
str += "AUTO-MAN";
str += "</button>";
str += "<button onClick=location.href='./?P12\' style='margin:auto;background-color: #84B1FF;color: snow;padding: 10px;border: 1px solid #3F7CFF;width:65px;'>";
str += "DERECHA";
str += "</button>";
str += "<button onClick=location.href='./?P13\' style='margin:auto;background-color: #84B1FF;color: snow;padding: 10px;border: 1px solid #3F7CFF;width:65px;'>";
str += "IZQUIERDA";
str += "</button>";
str += "<br /><br />";
// more html code here ...
str += "</body>";
str += "</html>";
BT1.println(str);
}
}
[/lis]
And it doesn't works. I think I'm doing it well, but I don't know where it breaks. The program compile right, but when I start the serial monitor or try to connect with its IP using the browser, nothing.
But if I avoid the HTML code, I have no problem putting in the browser the IP with the command like IP/command. Why could be this happening if I only added a string to display it in the browser?
This is the code that works fine:
[lis]
#include <SoftwareSerial.h>
SoftwareSerial BT1(3, 2); // RX | TX
String W =" ";
char w ;
void setup()
{
Serial.begin(9600);
BT1.begin(9600);
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
pinMode(11, OUTPUT);
BT1.write("AT+CWMODE=3\r\n");
delay(1000);
BT1.write("AT+CIPMUX=1\r\n");
delay(1000);
BT1.write("AT+CIPSERVER=1,80\r\n");
delay(1000);
}
void loop()
{
if (BT1.available()) // WIFI - Serial
{ w = BT1.read() ;
Serial.print(w);
W = W + w ;
}
if (Serial.available()) // Serial - WIFI
{ char s = Serial.read();
BT1.print(s);
}
if ( w == '\n'){ //If ENTER
if ( W.indexOf("P13") > 0 )
{ digitalWrite( 13, !digitalRead(13)) ;
Serial.println("Invirtiendo pin 13");
}
if ( W.indexOf("P12") > 0 )
{ digitalWrite( 12, !digitalRead(12)) ;
Serial.println("Invirtiendo pin 12");
}
if ( W.indexOf("P11") > 0 )
{ digitalWrite( 11, !digitalRead(11)) ;
Serial.println("Invirtiendo pin 11");
}
W = "" ; w = ' ' ;
}
}
[/lis]
I have seen that I don't need to inicialize any client or server to do this (the code that works), So I think that is the same for the code where I add the HTML. Anyway, I am not able to compile programs with the ESP libraries because this libraries says that I need to run it in an ESP board, an my Arduino is _AVR_.
Even so I think I don't need this libraries because the code runs well (without the HTmL code of course). So maybe you could see what could be wrong in the code with the HTML that I am not able to see?