So you're a Noob? Post your questions here until you graduate! Don't be shy.

User avatar
By Panseptos
#61292 Dear all

I just received my ESPS8266 module and I`m trying to understand how it works. After installing the module and making sure that it works, I compiled a code from The instructables website that tries to control the module from a php server. After adjusting the code to my needs I keep receive busy, busx p... messages and ERROR messages on the serial monitor and of course no communication takes place between the Arduino and the PhP webpage:

AT+CWJAP=#Athins","4102703241"

AT+CIPSTART<"TCP","test.000webhostapp.com",80

busx p...

OK
AT+CIPSQ�T²�j

EYROR

GET /index.html HTTP/1.1

ESROR
Host: test000webhostapp.com:80

ERROR

ERROR

Besides the errors I keep on getting incorrect characters on the serial port like l instead of m �T²�j
and other. Is that normal?


This is the code that I have compiled:

#include <SoftwareSerial.h>
#define DEBUG true
#define RELAY4 6

SoftwareSerial esp8266(4, 5); // RX, TX

void setup() {
pinMode(RELAY4, OUTPUT);
Serial.println("Relay High");
digitalWrite(RELAY4, HIGH);

Serial.begin(9600);
esp8266.begin(115200);

while(!Serial); // Wait for the serial port to be ready.
sendData("AT+RST\r\n",3000,DEBUG); // reset module
sendData("AT+CWMODE=1\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+CWJAP=\"Athins\",\"4112703241\"\r\n",5000,DEBUG);


sendData("AT+CIPSTART=\"TCP\",\"test.000webhostapp.com\",80\r\n",3000,DEBUG);
sendData("AT+CIPSEND=63\r\n",1000,DEBUG);
sendData("GET /index.html HTTP/1.1\r\n",1000,DEBUG);
sendData("Host: test.000webhostapp.com:80\r\n\r\n",1000,DEBUG);
sendData("\r\n\r\n\r\n\r\n",1000,DEBUG);delay (5000);
}

void loop()
{ sendData("AT+CIPSTART=\"TCP\",\"test.000webhostapp.com\",80\r\n",500,DEBUG);
sendData("AT+CIPSEND=63\r\n",500,DEBUG);
sendData("GET /index.html HTTP/1.1\r\n",500,DEBUG);
sendData("Host: test.000webhostapp.com:80\r\n\r\n",500,DEBUG);
sendData("\r\n\r\n\r\n\r\n",500,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.
if (c=='_'){Serial.print("on");digitalWrite(RELAY4, HIGH);}
if (c=='&'){Serial.print("off");digitalWrite(RELAY4, LOW);}
response+=c;
}
}

if(debug)
{
Serial.print(response);
}

return response;
}

And this is the index.php used on my PHP server:


<form action="#" method="post">
<input type="radio" name="LEDON" value="ON">ON<br>
<input type="radio" name="LEDOFF" value="OFF">OFF


<br>
<input type="submit" value="Submit">
</form>
<?php echo "Off"; ?>
<?php if(isset($_POST['LEDON'])){ echo "ON";

$myfile = fopen("index.html", "w") or die("Unable to open file!");
$txt = "______________________________________________";

fwrite($myfile, $txt);
fclose($myfile);}

if(isset($_POST['LEDOFF'])){echo "OFF";

$myfile2 = fopen("index.html", "w") or die("Unable to open file!");
$txt2 = "&&&&&&&&&&&&&&&&";

fwrite($myfile2, $txt2);
fclose($myfile2);}

?>

Sorry for the really long post! Am I doing something wrong? Any help....will help!!! :)