Ok,
I'm just probably burned out on this but for some reason I'm getting Raw HTML code, rather than the page being displayed in HTML as web pages should be.
The code is below.
Note that I'm using statip IP's and the I think the author set this up for use as DHCP so his IDP line might have something to do with it?
if(wifi_module.find("+IPD,"))
Or...this line maybe?
int connectionId = wifi_module.read()-48;
Here's the full code for the sketch (using an Arduino UNO and an MQ-2 Sensor)
#include <SoftwareSerial.h>
#define DEBUG true
SoftwareSerial wifi_module(2,3); // Connect TX pin of esp to the pin 2 of Arduino and RX pin of esp to the pin 3 of Arduino
int red_led_pin = 9;
int green_led_pin = 8;
int buzzer_pin = 10;
int smoke_sensor_pin = A0;
void setup()
{
Serial.begin(115200);
wifi_module.begin(115200); // Set the baudrate according to your esp8266
pinMode(red_led_pin, OUTPUT);
pinMode(green_led_pin, OUTPUT);
pinMode(buzzer_pin, OUTPUT);
pinMode(smoke_sensor_pin, INPUT);
esp8266_command("AT+RST\r\n",2000,DEBUG); // reset module
esp8266_command("AT+CWMODE=3\r\n",1000,DEBUG); // configure as access point
esp8266_command("AT+CIPSTA=\"192.168.003.58\",\"192.168.003.001\",\"255.255.255.000\"\r\n",10000,DEBUG);
esp8266_command("AT+CWJAP_CUR=\"MySSID\",\"password\"\r\n",10000,DEBUG);
esp8266_command("AT+CIFSR\r\n",1000,DEBUG); // get ip address
esp8266_command("AT+CIPMUX=1\r\n",1000,DEBUG); // configure for multiple connections
esp8266_command("AT+CIPSERVER=1,37731\r\n",1000,DEBUG); // turn on server on port
}
void loop()
{
int analogSensor = analogRead(smoke_sensor_pin);
if (analogSensor > 300)
{
Serial.println(analogSensor);
digitalWrite(red_led_pin, HIGH);
digitalWrite(green_led_pin, LOW);
tone(buzzer_pin, 1000, 200);
}
else
{
digitalWrite(red_led_pin, LOW);
digitalWrite(green_led_pin, HIGH);
noTone(buzzer_pin);
}
if(wifi_module.available())
{
if(wifi_module.find("+IPD,"))
{
int connectionId = wifi_module.read()-48;
Serial.print("ConnectionID = ");
Serial.println(connectionId);
String webpage = "Content-Type: text/html\r\n\r\n";
webpage +="HTTP/1.1 200 OK\r\n";
webpage += "<h1>IOT Smoke Detection System</h1>";
webpage +="<p>Smoke Value is ";
webpage += analogSensor;
webpage +="</p>";
// String webpage = "<h1>IOT Smoke Detection System</h1>";
// webpage +="<p>Smoke Value is ";
// webpage += analogSensor;
// webpage +="</p>";
if (analogSensor > 300)
{
webpage +="<h5>DANGER! Move Somewhere Else</h5>";
}
else
{
webpage +="<h4>Everything Normal</h4>";
}
String cipSend = "AT+CIPSEND=";
cipSend += connectionId;
cipSend += ",";
cipSend +=webpage.length();
cipSend +="\r\n";
esp8266_command(cipSend,1000,DEBUG);
esp8266_command(webpage,1000,DEBUG);
String closeCommand = "AT+CIPCLOSE=";
closeCommand+=connectionId; // append connection id
closeCommand+="\r\n";
esp8266_command(closeCommand,3000,DEBUG);
}
}
}
String esp8266_command(String command, const int timeout, boolean debug)
{
String response = "";
wifi_module.print(command);
long int time = millis();
while( (time+timeout) > millis())
{
while(wifi_module.available())
{
char c = wifi_module.read();
response+=c;
}
}
if(debug)
{
Serial.print(response);
}
return response;
And here is what I see when I open the web page.....(This is not code, this is rendered on the web page exactly as I entered it below)
Content-Type: text/html
HTTP/1.1 200 OK
IOT Smoke Detection System
Smoke Value is 140
<h4Everything is normalI'm sure one of you guys will spot the problem instantly....so thanks in advance.