The use of the ESP8266 in the world of IoT

User avatar
By lozi_dani
#46968 Hi everyone!
Someone knows if it is possible to insert html code into the code of my ESP01?
I am controlling some motors via web with this module, but I have to send the instructions through the url, like 192.xxx.x.x/ledOn

What I want is to have some buttons in this webpage to control the motors more easily, without change the url each time I want to change the movement of the motors.

Also, if someone knows, it is possible to insert the code of the ESP-01 in the same way people do with ESP12?

Now I load the code in my arduino nano, and I have connected the ESP-01 to the arduino.

It is possible to do that?

Thanks to everyone!
User avatar
By martinayotte
#46980 Your question is pretty vague !
The ESP01 and ESP12 are both using the same ESP8266 chip, therefore you can upload the same code.
Many people created Web pages for ESPs, so Yes html code can be inserted into the code.
Google is your friend here for such question :
https://www.google.ca/#q=esp8266+web+page+led+control
User avatar
By lozi_dani
#47040 I' sorry, you are right, my question has not too much info. I will try to explain me better.

I have tried to follow this example:
http://diymakers.es/crear-servidor-web-con-arduino/

In this page, the code seems that try to insert HTML code using the sketch that loads in the Arduino. They do this:
********************************************
//Página web en formato HTML
client.println("<html>");
client.println("<head>");
client.println("</head>");
client.println("<body>");
client.println("<h1 align='center'>DIYMakers</h1><h3 align='center'>LED controlado por Servidor Web con Arduino</h3>");
//Creamos los botones. Para enviar parametres a través de HTML se utiliza el metodo URL encode. Los parámetros se envian a través del símbolo '?'
client.println("<div style='text-align:center;'>");
client.println("<button onClick=location.href='./?LED=ON\' style='margin:auto;background-color: #84B1FF;color: snow;padding: 10px;border: 1px solid #3F7CFF;width:65px;'>");
client.println("ON");
client.println("</button>");
client.println("<button onClick=location.href='./?LED=OFF\' style='margin:auto;background-color: #84B1FF;color: snow;padding: 10px;border: 1px solid #3F7CFF;width:65px;'>");
client.println("OFF");
client.println("</button>");
client.println("<br /><br />");
client.println("<b>LED = ");
client.print(estado);
client.println("</b><br />");
client.println("</b></body>");
client.println("</html>");
****************************************************************

So, when they put the IP address of the ESP01 using the browser, they can see the image shown in their web, where they have two buttons to choose if the led is ON or OFF.

I have seen a lot of examples where people creates an HTML code independently of the ESP01, like led_on.html, and from the ESP01 send the info to that page. I was not able to do that. When I saw the example of the link above, I've seen that putting in the browser 192.xxx.x.x the are able to see some buttons with that code they put in the Arduino.

I want to try something like that, but when I try this example, it seems that the module doesn't try to connect with my WiFi. I can see this when I connect the Arduino via USB with my PC and doesn't put anything in the serial monitor.

What I have achieved is to do the same, but I have to put in the browser the command, like 192.xxx.x.x/ledOn, to put the led ON.

Maybe you know why with my code is able to do the connections as the setup() says, and with the code of the link not?

I put my code here:

**********************************************
#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()) // Lo que entra por WIFI - Serial
{ w = BT1.read() ;
Serial.print(w); // Vamos montando un String con lo que entra
W = W + w ;
}
if (Serial.available()) // Lo que entra por Serial - WIFI
{ char s = Serial.read();
BT1.print(s);
}
if ( w == '\n') // Sin han pulsado intro
{ if ( W.indexOf("P13") > 0 ) // Si P13 esta incluido en el string
{ digitalWrite( 13, !digitalRead(13)) ;
Serial.println("Invirtiendo pin 13");
}
if ( W.indexOf("P12") > 0 ) // Si P13 esta incluido en el string
{ digitalWrite( 12, !digitalRead(12)) ;
Serial.println("Invirtiendo pin 12");
}
if ( W.indexOf("P11") > 0 ) // Si P13 esta incluido en el string
{ digitalWrite( 11, !digitalRead(11)) ;
Serial.println("Invirtiendo pin 11");
}

W = "" ; w = ' ' ;
}

}
****************************************************

Thanks for your reply! And I didn't know that ESP01 and ESP12 use the same chip, I thought that maybe use a different version or something like that.
User avatar
By martinayotte
#47044 First, a small suggestion : you should avoid sending tons of client.println() to build the Web page, it is really not efficient. You are better using a string and concatenate all your html code in it, and then doing a single call to client.println(str).

Second, about WiFi connection : I don't see any places in your code where you actually do/prepare such connection.

Third, do you really wish to use an Arduino UNO attached with an ESP ? A single ESP can do the same job without any UNO, it is much more simplier ...