I do know how to make the webserver page on the ESP that is not a problem. The problem is how to pass the data from the uno board to the ESP to display on the server page.
I did mange to find this.. I did try this and seems to work so far. Now I'm just trying figure out how to display the Sensor to the webpage.
// Code to use ESP as a basic web server
// must be connected to ESP IP to access the page (IP can be found in the serial monitor output)
// set up Serial with newline and carriage return ("NL & CR")
// Baud rate may differ, must be determined
// Try 9600, 115200, or 57600
#include <SoftwareSerial.h>
//used for debugging
//when true, the ESP will print info (such as IP) to serial monitor
#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
void setup()
{
Serial.begin(115200); //baud rate may differ
esp8266.begin(115200); // esp baud rate may differ
//check AT commands list for more detail on each of these
//sendData defined below, see for more detail
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
//sendData("AT+CWSAP=\"OSU_ESP\",\"open\",11,3",1000,DEBUG); //set SSID, password, channel, password protection type
}
void loop()
{
if(esp8266.available()) // check if the esp is sending a message
{
if(esp8266.find("+IPD,")) // if user is trying to access webpage
{
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 = "<h1>Hello</h1><h2>World!</h2><button>LED1</button>"; //html sent to ESP, displayed to user
//maximum of 64 bytes sent at a time due to Arduino limit
// CIPSEND AT command format: AT+CIPSEND=id, length
String cipSend = "AT+CIPSEND="; // all data sent to ESP must be prefaced with AT+CIPSEND=
cipSend += connectionId; //append connection id
cipSend += ","; //must separate with comma
cipSend +=webpage.length(); // CIPSEND requires data length as input
cipSend +="\r\n"; //all AT commands must end with newline and carriage return
sendData(cipSend,1000,DEBUG); //send AT command format
sendData(webpage,1000,DEBUG); //your html
webpage="<button>LED2</button>"; //extra HTML
//see above for more detail
cipSend = "AT+CIPSEND=";
cipSend += connectionId;
cipSend += ",";
cipSend +=webpage.length();
cipSend +="\r\n";
sendData(cipSend,1000,DEBUG);
sendData(webpage,1000,DEBUG);
//closes the connection
String closeCommand = "AT+CIPCLOSE=";
closeCommand+=connectionId; // append connection id
closeCommand+="\r\n";
sendData(closeCommand,3000,DEBUG);
}
}
}
//timeout is the window you expect a response within
//timeout can be shortened within the function definition or in individual arugments
//If timeout is too short, not all serial data will be displayed, but webpage will load faster
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;
}
It has a hello world text on there.
Hello
World!
So this is a start.