/*********** Example of WebServer using Arduino board or BlackBoard + ESP8266 + Level Logic Converter Original code from: http://allaboutee.com/2014/12/30/esp8266-and-arduino-webserver/ Adapted by Vini from RoboCore Brazil ( http://www.robocore.net ) Change: - Arduino digital pin 4 <<---->>> ESP 8266 RESET Pin, in order to make it accept commands; After upload the code, open the Serial Monitor and wait for information. After the last info (server OK) connect to ESP8266 network (it creates by itself), open a browser and access http://192.168.4.1 You MUST have at least v.0.9.2.2 firmware on your ESP8266. Don't know how to update the firmware? Check: http://www.xess.com/blog/esp8266-reflash/ ***********/ #include #define DEBUG true SoftwareSerial esp8266(2,3); // make RX Arduino line is pin 2, make TX Arduino line is pin 3. // This means that you need to connect the TX line from the esp to the Arduino's pin 2 // and the RX line from the esp to the Arduino's pin 3 const int RST = 4; void setup() { Serial.begin(9600); esp8266.begin(9600); // your esp's baud rate might be different pinMode(RST, OUTPUT); digitalWrite(RST, LOW); delay(300); digitalWrite(RST, HIGH); sendData("AT+RST\r\n",2000,DEBUG); // reset module sendData("AT+CWMODE=2\r\n",1000,DEBUG); // configure as access point sendData("AT+CIFSR\r\n",1000,DEBUG); // get ip address sendData("AT+CIPMUX=1\r\n",1000,DEBUG); // configure for multiple connections sendData("AT+CIPSERVER=1,80\r\n",1000,DEBUG); // turn on server on port 80 } void loop() { if(esp8266.available()) // check if the esp is sending a message { /* while(esp8266.available()) { // The esp has data so display its output to the serial window char c = esp8266.read(); // read the next character. Serial.write(c); } */ if(esp8266.find("+IPD,")) { delay(1000); int connectionId = esp8266.read()-48; // subtract 48 because the read() function returns // the ASCII decimal value and 0 (the first decimal number) starts at 48 String webpage = "

Hello

World!

"; String cipSend = "AT+CIPSEND="; cipSend += connectionId; cipSend += ","; cipSend +=webpage.length(); cipSend +="\r\n"; sendData(cipSend,1000,DEBUG); sendData(webpage,1000,DEBUG); webpage=""; cipSend = "AT+CIPSEND="; cipSend += connectionId; cipSend += ","; cipSend +=webpage.length(); cipSend +="\r\n"; sendData(cipSend,1000,DEBUG); sendData(webpage,1000,DEBUG); String closeCommand = "AT+CIPCLOSE="; closeCommand+=connectionId; // append connection id closeCommand+="\r\n"; sendData(closeCommand,3000,DEBUG); } } } String sendData(String command, const int timeout, boolean debug) { String response = ""; esp8266.print(command); // send the read character to the esp8266 long int time = millis(); while( (time+timeout) > millis()) { while(esp8266.available()) { // The esp has data so display its output to the serial window char c = esp8266.read(); // read the next character. response+=c; } } if(debug) { Serial.print(response); } return response; }