Can't send GET request using Mega+ESP-01+AT Commands via Serial Monitor. HELP!

Hi Arduino Masters!

What I'm trying to do is send a GET request to my server using an Arduino Mega and an 2866 ESP-01 connected to my Rx and Tx Pins (1 and 2). They are hooked up in parallel to the Rx and Tx pins on the ESP-01.

See 2 attached diagram pics of the setup.

I can communicate fine via Serial Monitor sending AT commands to the ESP01. I can connect the ESP to my wifi network, I can configure it in Station mode, I can connect to a server, etc. I can also send a request and receive a response.

However, the response I get from the server is 400 Bad Request. Here's what my Serial Monitor looks like:

AT+CIPSTART="TCP","couplestherapyexposed.com",80

CONNECT

OK
AT+CIPSEND=174

OK

Recv 174 bytes

SEND OK

+IPD,338:HTTP/1.1 400 Bad Request
Date: Wed, 05 Sep 2018 21:45:46 GMT
Content-Type: text/html
Content-Length: 171
Connection: close
Server: cloudflare-nginx
CF-RAY: -

400 Bad Request

400 Bad Request


cloudflare CLOSED

This is the command i'm sending after the AT+CIPSEND=174 command:

GET /tests/poolGenie.php HTTP/1.1\r\n
Host: couplestherapyexposed.com:80\r\n
User-Agent: wget/1.12\r\n
Connection: keep-alive\r\n
Upgrade-Insecure-Requests: 1\r\n\
\r\n\r\n

As you can see, I get 'SEND OK' but the server is complaining about my headers. I've tried every variation I could think of with no success.

To keep is simple when I was first trying to get this to work (before adding more and more headers trying to get it to work), I started with just this

GET /tests/poolGenie.php HTTP/1.1\r\n\r\n

And this is what shows up in Serial Monitor:

OK
AT+CIPSEND=43

OK

Recv 43 bytes

SEND OK

+IPD,338:HTTP/1.1 400 Bad Request
Date: Wed, 05 Sep 2018 21:56:37 GMT
Content-Type: text/html
Content-Length: 171
Connection: close
Server: cloudflare-nginx
CF-RAY: -

400 Bad Request

400 Bad Request


cloudflare CLOSED

No progress.

So I decided to try requesting google.com and here's what the serial monitor looks like for that:

AT

OK
AT+CWMODE=1

OK
AT+CIPMUX=0

OK
AT+CWJAP="PGKL3","CDDV8LJK5LQX5KBN"

WIFI DISCONNECT
WIFI CONNECTED
WIFI GOT IP

OK
AT+CIPSTART="TCP","google.com",80

CONNECT

OK
AT+CIPSEND=25

OK

Recv 25 bytes

SEND OK

Google's server gave me no response at all. So weird.

This is the GET command I used:

GET / HTTP/1.1\r\n\r\n

I'm having a terrible time figuring this issue out. I literally watched hours of videos, read countless articles, tried everything I could think of, but still no joy.

I would be EXTREMELY appreciative if you could help me with this hurdle.

I read somewhere that there's some kind of issue with sending a request through serial monitor and that it works by using software serial but I'm not really familiar with that. I tried sending the commands using Serial.write("") in the loop section of the Arduino sketch and reading the response but can't figure that out either.

I'm guessing that the solution is something simple but I just can't figure it out with my limited knowledge and experience with Arduino.

Please help! :slight_smile:

esp-01_PINS.jpg

esp-arduinomega_connections.jpg

connected to my Rx and Tx Pins (1 and 2).

Pins 0 and 1 are the RX and TX pins...

Why on earth would you put the ESP on the same pins that are used to talk to the PC?

Put it on RX1 and TX1, and use Serial1 to talk to it. Use Serial to talk to the PC.

In addition to what PaulS wrote, the ESP-01 requires its own 3.3V power supply.
The 3.3V output from the Arduino is not enough.

Also, because the ESP8266 is a 3.3V device, it is generally recommended that you either use either a level shifter module ( https://www.sparkfun.com/products/12009 ) or a voltage divider for the TX Arduino to RX ESP-01 connection.

Both of these will give you a more reliable circuit.

.

Thanks Guys. I got it working by learning how to use the IDE instead of trying to send a GET request through serial monitor. Works like a charm.

By the way, the ESP is working well with the 3.3v from Arduino. I haven't had any issues with that. I wonder though if I may run into wifi signal strength using the lower power. If I do, I will attach the external power supply.

Thanks again :slight_smile: