ESP8266 AS WEBSERVER
Posted: Tue Mar 01, 2016 6:43 am
HELP!
Why run my loop only once , I suspect that my connection is not closed.
thanks in advance
String sendData(String command, const int timeout) {
String response = "";
Serial.print(command);
long int time = millis();
while ((time + timeout) > millis()) {
while (Serial.available()) {
char c = Serial.read();
response += c;
}
}
return response;
}
void setup(){
Serial.begin(115200);
pinMode(11, OUTPUT);
digitalWrite(11, LOW);
pinMode(12, OUTPUT);
digitalWrite(12, LOW);
pinMode(13, OUTPUT);
digitalWrite(13, HIGH);
sendData("AT+RST\r\n", 2000); // reset module
sendData("AT+CWMODE=1\r\n", 1000); // configure as STA point
sendData("AT+CWJAP=\"BrixHomeNetWork\",\"Brix0076\"\r\n", 4000);
sendData("AT+CIPMUX=1\r\n", 1000); // configure for multiple connections OBS FRA 1 TIL 0
sendData("AT+CIPSERVER=1,80\r\n", 1000); // turn on server on port 80
}
void loop(){
String test = "";
if (Serial.available()){
if (Serial.find("+IPD,")){
delay(1000);
int connectionId = Serial.read() - 48;
Serial.find("pin=");
int pinNumber = (Serial.read() - 48) * 10;
pinNumber += (Serial.read() - 48);
digitalWrite(pinNumber, !digitalRead(pinNumber));
String closeCommand = "AT+CIPCLOSE=";
closeCommand += connectionId;
closeCommand += "\r\n";
sendData(closeCommand, 1000);
}
}
}
Why run my loop only once , I suspect that my connection is not closed.
thanks in advance
String sendData(String command, const int timeout) {
String response = "";
Serial.print(command);
long int time = millis();
while ((time + timeout) > millis()) {
while (Serial.available()) {
char c = Serial.read();
response += c;
}
}
return response;
}
void setup(){
Serial.begin(115200);
pinMode(11, OUTPUT);
digitalWrite(11, LOW);
pinMode(12, OUTPUT);
digitalWrite(12, LOW);
pinMode(13, OUTPUT);
digitalWrite(13, HIGH);
sendData("AT+RST\r\n", 2000); // reset module
sendData("AT+CWMODE=1\r\n", 1000); // configure as STA point
sendData("AT+CWJAP=\"BrixHomeNetWork\",\"Brix0076\"\r\n", 4000);
sendData("AT+CIPMUX=1\r\n", 1000); // configure for multiple connections OBS FRA 1 TIL 0
sendData("AT+CIPSERVER=1,80\r\n", 1000); // turn on server on port 80
}
void loop(){
String test = "";
if (Serial.available()){
if (Serial.find("+IPD,")){
delay(1000);
int connectionId = Serial.read() - 48;
Serial.find("pin=");
int pinNumber = (Serial.read() - 48) * 10;
pinNumber += (Serial.read() - 48);
digitalWrite(pinNumber, !digitalRead(pinNumber));
String closeCommand = "AT+CIPCLOSE=";
closeCommand += connectionId;
closeCommand += "\r\n";
sendData(closeCommand, 1000);
}
}
}