Hi all.
I have a sketch , that for the most part is working, the only part that is not is the data display on the web page.
The code is an example that i found that turns a LED on and off from the web page and is supposed to display a message when a hardware button is pressed on the UNO.
The LED works fine, I can go and type in 192.1**../ON and turn the LED on (OFF for off) and I have thoroughly tested the ESP8266 AT codes successfully.
#include <SoftwareSerial.h>
#define TIMEOUT 5000 // mS
#define LED 5
SoftwareSerial mySerial(7, 6); // RX, TX
const int button = 11;
int button_state = 0;
void setup()
{
pinMode(LED,OUTPUT);
pinMode(button,INPUT);
Serial.begin(9600);
mySerial.begin(9600);
SendCommand("AT+RST", "Ready");
delay(5000);
SendCommand("AT+CWMODE=1","OK");
SendCommand("AT+CIFSR", "OK");
SendCommand("AT+CIPMUX=1","OK");
SendCommand("AT+CIPSERVER=1,80","OK");
}
void loop(){
button_state = digitalRead(button);
if(button_state == HIGH){
mySerial.println("AT+CIPSEND=0,28");
mySerial.println("<h1>Button was pressed!</h1>");
delay(1000);
SendCommand("AT+CIPCLOSE=0","OK");
}
String IncomingString="";
boolean StringReady = false;
while (mySerial.available()){
IncomingString=mySerial.readString();
StringReady= true;
}
if (StringReady){
Serial.println("Received String: " + IncomingString);
if (IncomingString.indexOf("LED=ON") != -1) {
digitalWrite(LED,HIGH);
}
if (IncomingString.indexOf("LED=OFF") != -1) {
digitalWrite(LED,LOW);
}
}
}
boolean SendCommand(String cmd, String ack){
mySerial.println(cmd); // Send "AT+" command to module
if (!echoFind(ack)) // timed out waiting for ack string
return true; // ack blank or ack found
}
boolean echoFind(String keyword){
byte current_char = 0;
byte keyword_length = keyword.length();
long deadline = millis() + TIMEOUT;
while(millis() < deadline){
if (mySerial.available()){
char ch = mySerial.read();
Serial.write(ch);
if (ch == keyword[current_char])
if (++current_char == keyword_length){
Serial.println();
return true;
}
}
}
return false; // Timed out
}
This is the area that contains the message to be sent when the button is pressed:-
if(button_state == HIGH){
mySerial.println("AT+CIPSEND=0,28");
mySerial.println("
Button was pressed!
"); //this is apparently Header format..new to medelay(1000);
SendCommand("AT+CIPCLOSE=0","OK");
The message is displayed in the Serial Monitor but fails to appear on the web page.
The example site shows a successful "send" picture with the message text in place on the web screen.
I am new to this side of things...is there code missing or something else?
Thanks
Doug