Skip to main content
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Fixed syntax highlighting, added tags.
Source Link
VE7JRO
  • 2.5k
  • 19
  • 26
  • 29

Problem of fetching data from web page using Arduino unoUno and ESP8266

Project goal is to control a relay over web. I made a php page that receives the post data from Arduino then store the values sent into a mysql database (which is the relay status now). Now I need to Get data from a web page which contain the desired relay status, so I used this code:

#include <SoftwareSerial.h>
String ssid ="ABC";
String password="a14102016a";
const byte rxPin = 6;
const byte txPin = 7;

SoftwareSerial ESP8266 (rxPin, txPin);

unsigned long lastTimeMillis = 0;

void setup() {
  Serial.begin(115200);   
  ESP8266.begin(115200);
  reset();
  connectWifi();
  delay(2000);
}


//reset the esp8266 module

void reset() {

ESP8266.println("AT+RST");

delay(1000);

if(ESP8266.find("OK") ) Serial.println("Module Reset");

}


//connect to your wifi network
void connectWifi() {

String cmd = "AT+CWJAP=\"" +ssid+"\",\"" +password+ "\"";
ESP8266.println(cmd);

delay(4000);

if(ESP8266.find("OK")) {

Serial.println("Connected!");

}

else {

connectWifi();

Serial.println("Cannot connect to wifi"); }

}

void printResponse() {
  while (ESP8266.available()) {
    Serial.println(ESP8266.readStringUntil('\n')); 
  }
}

void loop() {

  if (millis() - lastTimeMillis > 30000) {
    lastTimeMillis = millis();

    ESP8266.println("AT+CIPMUX=1");
    delay(1000);
    printResponse();

    ESP8266.println("AT+CIPSTART=4,\"TCP\",\"192.168.1.161\",80");
    delay(1000);
    printResponse();

    String cmd = "GET /ard/sensor.html HTTP/1.1";
    ESP8266.println("AT+CIPSEND=4," + String(cmd.length() +4));
    delay(1000);

    ESP8266.println(cmd);
    delay(1000);
    ESP8266.println(""); 
  }

  if (ESP8266.available()) {
    Serial.write(ESP8266.read());
  }

}
#include <SoftwareSerial.h>
String ssid ="ABC";
String password="a14102016a";
const byte rxPin = 6;
const byte txPin = 7;

SoftwareSerial ESP8266 (rxPin, txPin);

unsigned long lastTimeMillis = 0;

void setup() {
  Serial.begin(115200);   
  ESP8266.begin(115200);
  reset();
  connectWifi();
  delay(2000);
}


//reset the esp8266 module

void reset() {

ESP8266.println("AT+RST");

delay(1000);

if(ESP8266.find("OK") ) Serial.println("Module Reset");

}


//connect to your wifi network
void connectWifi() {

String cmd = "AT+CWJAP=\"" +ssid+"\",\"" +password+ "\"";
ESP8266.println(cmd);

delay(4000);

if(ESP8266.find("OK")) {

Serial.println("Connected!");

}

else {

connectWifi();

Serial.println("Cannot connect to wifi"); }

}

void printResponse() {
  while (ESP8266.available()) {
    Serial.println(ESP8266.readStringUntil('\n')); 
  }
}

void loop() {

  if (millis() - lastTimeMillis > 30000) {
    lastTimeMillis = millis();

    ESP8266.println("AT+CIPMUX=1");
    delay(1000);
    printResponse();

    ESP8266.println("AT+CIPSTART=4,\"TCP\",\"192.168.1.161\",80");
    delay(1000);
    printResponse();

    String cmd = "GET /ard/sensor.html HTTP/1.1";
    ESP8266.println("AT+CIPSEND=4," + String(cmd.length() +4));
    delay(1000);

    ESP8266.println(cmd);
    delay(1000);
    ESP8266.println(""); 
  }

  if (ESP8266.available()) {
    Serial.write(ESP8266.read());
  }

}
    Module Reset
Connected!

AT+CIPMV⸮=1




OK

AT+CIPSTART=4,#TCP","192.068.1.161",80


4,CONOECT



OK

AZ⸮⸮R5NDOi⸮j

O⸮C⸮⸮
Qecv ⸮&⸮ѕ⸮5

SEND OK

+IPD,4,501:HTTP/1.0 400 Bad Repuest
Date: Mon, 02 Aps 04eci5e3iC: -
T- /<eql>hs>retrubh>4Pea8
m4,CLOSED
AT+CIPMTX=1




OK

AT+CIPSTART=4,"TCP","192.068.1.161",80


4,CONNDCT



OK

AR⸮⸮R5⸮DOi⸮j

O⸮C⸮⸮
Qecv 33 bytes

SEND OK

+IPD,4,501;HTTP/1.1 400 Bad Request
Date: Moo, 02 Apr 2:v2)1L
 exr9OPEL<
B/h<eY esls/
A /eo/b
4,CLOSED
AT+CIPMUX=1
    Module Reset
Connected!

AT+CIPMV⸮=1




OK

AT+CIPSTART=4,#TCP","192.068.1.161",80


4,CONOECT



OK

AZ⸮⸮R5NDOi⸮j

O⸮C⸮⸮
Qecv ⸮&⸮ѕ⸮5

SEND OK

+IPD,4,501:HTTP/1.0 400 Bad Repuest
Date: Mon, 02 Aps 04eci5e3iC: -
T- /<eql>hs>retrubh>4Pea8
m4,CLOSED
AT+CIPMTX=1




OK

AT+CIPSTART=4,"TCP","192.068.1.161",80


4,CONNDCT



OK

AR⸮⸮R5⸮DOi⸮j

O⸮C⸮⸮
Qecv 33 bytes

SEND OK

+IPD,4,501;HTTP/1.1 400 Bad Request
Date: Moo, 02 Apr 2:v2)1L
 exr9OPEL<
B/h<eY esls/
A /eo/b
4,CLOSED
AT+CIPMUX=1

Sometimes I get HTTP/1.0 400 Bad Repuest and sometimes HTTP/1.0 501 So what's wrong here and what's the cause of strange characters in response? How to retrieve the correct data from web page? Thanks in advance

Problem of fetching data from web page using Arduino uno and ESP8266

Project goal is to control a relay over web. I made a php page that receives the post data from Arduino then store the values sent into a mysql database (which is the relay status now). Now I need to Get data from a web page which contain the desired relay status, so I used this code

#include <SoftwareSerial.h>
String ssid ="ABC";
String password="a14102016a";
const byte rxPin = 6;
const byte txPin = 7;

SoftwareSerial ESP8266 (rxPin, txPin);

unsigned long lastTimeMillis = 0;

void setup() {
  Serial.begin(115200);   
  ESP8266.begin(115200);
  reset();
  connectWifi();
  delay(2000);
}


//reset the esp8266 module

void reset() {

ESP8266.println("AT+RST");

delay(1000);

if(ESP8266.find("OK") ) Serial.println("Module Reset");

}


//connect to your wifi network
void connectWifi() {

String cmd = "AT+CWJAP=\"" +ssid+"\",\"" +password+ "\"";
ESP8266.println(cmd);

delay(4000);

if(ESP8266.find("OK")) {

Serial.println("Connected!");

}

else {

connectWifi();

Serial.println("Cannot connect to wifi"); }

}

void printResponse() {
  while (ESP8266.available()) {
    Serial.println(ESP8266.readStringUntil('\n')); 
  }
}

void loop() {

  if (millis() - lastTimeMillis > 30000) {
    lastTimeMillis = millis();

    ESP8266.println("AT+CIPMUX=1");
    delay(1000);
    printResponse();

    ESP8266.println("AT+CIPSTART=4,\"TCP\",\"192.168.1.161\",80");
    delay(1000);
    printResponse();

    String cmd = "GET /ard/sensor.html HTTP/1.1";
    ESP8266.println("AT+CIPSEND=4," + String(cmd.length() +4));
    delay(1000);

    ESP8266.println(cmd);
    delay(1000);
    ESP8266.println(""); 
  }

  if (ESP8266.available()) {
    Serial.write(ESP8266.read());
  }

}
    Module Reset
Connected!

AT+CIPMV⸮=1




OK

AT+CIPSTART=4,#TCP","192.068.1.161",80


4,CONOECT



OK

AZ⸮⸮R5NDOi⸮j

O⸮C⸮⸮
Qecv ⸮&⸮ѕ⸮5

SEND OK

+IPD,4,501:HTTP/1.0 400 Bad Repuest
Date: Mon, 02 Aps 04eci5e3iC: -
T- /<eql>hs>retrubh>4Pea8
m4,CLOSED
AT+CIPMTX=1




OK

AT+CIPSTART=4,"TCP","192.068.1.161",80


4,CONNDCT



OK

AR⸮⸮R5⸮DOi⸮j

O⸮C⸮⸮
Qecv 33 bytes

SEND OK

+IPD,4,501;HTTP/1.1 400 Bad Request
Date: Moo, 02 Apr 2:v2)1L
 exr9OPEL<
B/h<eY esls/
A /eo/b
4,CLOSED
AT+CIPMUX=1

Sometimes I get HTTP/1.0 400 Bad Repuest and sometimes HTTP/1.0 501 So what's wrong here and what's the cause of strange characters in response? How to retrieve the correct data from web page? Thanks in advance

Problem of fetching data from web page using Arduino Uno and ESP8266

Project goal is to control a relay over web. I made a php page that receives the post data from Arduino then store the values sent into a mysql database (which is the relay status now). Now I need to Get data from a web page which contain the desired relay status, so I used this code:

#include <SoftwareSerial.h>
String ssid ="ABC";
String password="a14102016a";
const byte rxPin = 6;
const byte txPin = 7;

SoftwareSerial ESP8266 (rxPin, txPin);

unsigned long lastTimeMillis = 0;

void setup() {
  Serial.begin(115200);   
  ESP8266.begin(115200);
  reset();
  connectWifi();
  delay(2000);
}


//reset the esp8266 module

void reset() {

ESP8266.println("AT+RST");

delay(1000);

if(ESP8266.find("OK") ) Serial.println("Module Reset");

}


//connect to your wifi network
void connectWifi() {

String cmd = "AT+CWJAP=\"" +ssid+"\",\"" +password+ "\"";
ESP8266.println(cmd);

delay(4000);

if(ESP8266.find("OK")) {

Serial.println("Connected!");

}

else {

connectWifi();

Serial.println("Cannot connect to wifi"); }

}

void printResponse() {
  while (ESP8266.available()) {
    Serial.println(ESP8266.readStringUntil('\n')); 
  }
}

void loop() {

  if (millis() - lastTimeMillis > 30000) {
    lastTimeMillis = millis();

    ESP8266.println("AT+CIPMUX=1");
    delay(1000);
    printResponse();

    ESP8266.println("AT+CIPSTART=4,\"TCP\",\"192.168.1.161\",80");
    delay(1000);
    printResponse();

    String cmd = "GET /ard/sensor.html HTTP/1.1";
    ESP8266.println("AT+CIPSEND=4," + String(cmd.length() +4));
    delay(1000);

    ESP8266.println(cmd);
    delay(1000);
    ESP8266.println(""); 
  }

  if (ESP8266.available()) {
    Serial.write(ESP8266.read());
  }

}
    Module Reset
Connected!

AT+CIPMV⸮=1




OK

AT+CIPSTART=4,#TCP","192.068.1.161",80


4,CONOECT



OK

AZ⸮⸮R5NDOi⸮j

O⸮C⸮⸮
Qecv ⸮&⸮ѕ⸮5

SEND OK

+IPD,4,501:HTTP/1.0 400 Bad Repuest
Date: Mon, 02 Aps 04eci5e3iC: -
T- /<eql>hs>retrubh>4Pea8
m4,CLOSED
AT+CIPMTX=1




OK

AT+CIPSTART=4,"TCP","192.068.1.161",80


4,CONNDCT



OK

AR⸮⸮R5⸮DOi⸮j

O⸮C⸮⸮
Qecv 33 bytes

SEND OK

+IPD,4,501;HTTP/1.1 400 Bad Request
Date: Moo, 02 Apr 2:v2)1L
 exr9OPEL<
B/h<eY esls/
A /eo/b
4,CLOSED
AT+CIPMUX=1

Sometimes I get HTTP/1.0 400 Bad Repuest and sometimes HTTP/1.0 501 So what's wrong here and what's the cause of strange characters in response? How to retrieve the correct data from web page?

Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Source Link
ali_m
  • 43
  • 1
  • 4

Problem of fetching data from web page using Arduino uno and ESP8266

Project goal is to control a relay over web. I made a php page that receives the post data from Arduino then store the values sent into a mysql database (which is the relay status now). Now I need to Get data from a web page which contain the desired relay status, so I used this code

#include <SoftwareSerial.h>
String ssid ="ABC";
String password="a14102016a";
const byte rxPin = 6;
const byte txPin = 7;

SoftwareSerial ESP8266 (rxPin, txPin);

unsigned long lastTimeMillis = 0;

void setup() {
  Serial.begin(115200);   
  ESP8266.begin(115200);
  reset();
  connectWifi();
  delay(2000);
}


//reset the esp8266 module

void reset() {

ESP8266.println("AT+RST");

delay(1000);

if(ESP8266.find("OK") ) Serial.println("Module Reset");

}


//connect to your wifi network
void connectWifi() {

String cmd = "AT+CWJAP=\"" +ssid+"\",\"" +password+ "\"";
ESP8266.println(cmd);

delay(4000);

if(ESP8266.find("OK")) {

Serial.println("Connected!");

}

else {

connectWifi();

Serial.println("Cannot connect to wifi"); }

}

void printResponse() {
  while (ESP8266.available()) {
    Serial.println(ESP8266.readStringUntil('\n')); 
  }
}

void loop() {

  if (millis() - lastTimeMillis > 30000) {
    lastTimeMillis = millis();

    ESP8266.println("AT+CIPMUX=1");
    delay(1000);
    printResponse();

    ESP8266.println("AT+CIPSTART=4,\"TCP\",\"192.168.1.161\",80");
    delay(1000);
    printResponse();

    String cmd = "GET /ard/sensor.html HTTP/1.1";
    ESP8266.println("AT+CIPSEND=4," + String(cmd.length() +4));
    delay(1000);

    ESP8266.println(cmd);
    delay(1000);
    ESP8266.println(""); 
  }

  if (ESP8266.available()) {
    Serial.write(ESP8266.read());
  }

}

But the response from server was

    Module Reset
Connected!

AT+CIPMV⸮=1




OK

AT+CIPSTART=4,#TCP","192.068.1.161",80


4,CONOECT



OK

AZ⸮⸮R5NDOi⸮j

O⸮C⸮⸮
Qecv ⸮&⸮ѕ⸮5

SEND OK

+IPD,4,501:HTTP/1.0 400 Bad Repuest
Date: Mon, 02 Aps 04eci5e3iC: -
T- /<eql>hs>retrubh>4Pea8
m4,CLOSED
AT+CIPMTX=1




OK

AT+CIPSTART=4,"TCP","192.068.1.161",80


4,CONNDCT



OK

AR⸮⸮R5⸮DOi⸮j

O⸮C⸮⸮
Qecv 33 bytes

SEND OK

+IPD,4,501;HTTP/1.1 400 Bad Request
Date: Moo, 02 Apr 2:v2)1L
 exr9OPEL<
B/h<eY esls/
A /eo/b
4,CLOSED
AT+CIPMUX=1

Sometimes I get HTTP/1.0 400 Bad Repuest and sometimes HTTP/1.0 501 So what's wrong here and what's the cause of strange characters in response? How to retrieve the correct data from web page? Thanks in advance