Error 400 Bad Request | ESP8266 Wi-Fi Module | Forum

Avatar

Please consider registering
Guest

Search

— Forum Scope —






— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

Register Lost password?
sp_Feed sp_TopicIcon
Error 400 Bad Request
Avatar
SESupply
New Member
Forum Posts: 4
sp_UserOfflineSmall Offline
1
June 22, 2015 - 2:11 am
sp_Permalink sp_Print

I have a little project using a ESP8266 on an Arduino Uno that simply reads a value (well, 3 values) from a serial device (UV dosimeter). I finally have everything talking together nicely (the arduino's serial monitor, so that I can see what's going on; the serial UV sensor; and the ESP8266). I have not had any success in getting the updates - I have now been trying to update manually using Terminal v1.93b.

Here is the process I am using (I have no problem connecting):

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

4, CONNECT

OK

AT+CIPSEND=4,67

OK
>GET /update?key={my_API_key}&field1=5&field2=255&field3=300

+IPD,4,172:
400 Bad Request

400 Bad Request


nginx/1.7.5

4,CLOSED

I have tried updating my channel via my browser and that works fine.

I would appreciate any help I can get.

Avatar
Michel_J

Silver
Forum Posts: 13
sp_UserOfflineSmall Offline
2
June 22, 2015 - 12:10 pm
sp_Permalink sp_Print sp_EditHistory

Try this:

GET /update?key={my_API_key}&field1=5&field2=255&field3=300&headers=false HTTP/1.1{CrLf}Host: api.thingspeak.com{CrLf}Connection: close{CrLf}Accept: */*{CrLf}{CrLf}

Replace {CrLf} by CrLf ( 13, 10 )
The keyword "headers=false" will remove extra headers from response.
The keyword "Connection: close" will close the connection automatically.

HTH

Avatar
SESupply
New Member
Forum Posts: 4
sp_UserOfflineSmall Offline
3
June 23, 2015 - 2:14 am
sp_Permalink sp_Print

Hi Michael, thanks for the reply - I'm getting so frustrated with this that I'm starting to chew on my keyboard!
I tried your suggestion, but I get an error - I'm replacing your {CrLf} with

in the string I'm sending but it doesn't seem to work. (How exactly can I put the {CrLf} chars into the string in Terminal?) At the moment I'm trying to send an update manually using Terminal so I can send exactly the string I want & see the response. Everything works perfectly right up till the GET statement.
I've tried updating my channel from a browser and that works fine. Could it be the ESP module itself??

Avatar
Michel_J

Silver
Forum Posts: 13
sp_UserOfflineSmall Offline
4
June 24, 2015 - 4:05 pm
sp_Permalink sp_Print

Make sure your terminal software send CrLf when you hit the return key on your keyboard. If you have Visual Studio I suggest you try with Visual Basic or C# to test your commands:

dim _SerialPort As New System.IO.Ports.SerialPort("COM3")

With _SerialPort
.BaudRate = "9600"
.Parity = IO.Ports.Parity.None
.DataBits = 8
.StopBits = IO.Ports.StopBits.One
.Handshake = IO.Ports.Handshake.None
.ReadTimeout = 10000
.NewLine = Microsoft.VisualBasic.Constants.vbCrLf

.Open()

'Clear the buffer
.DiscardInBuffer()
.DiscardOutBuffer()

.WriteLine("ATE0")

End With

cmd = _
"GET /update?key={my_API_key}&field1=20.0200&headers=false HTTP/1.1" & vbCr & vbLf & "Host: api.thingspeak.com" & vbCr & vbLf & "Connection: close" & vbCr & vbLf & "Accept: */*" & vbCr & vbLf & vbCr & vbLf

_SerialPort.WriteLine("AT+CIPSEND=" & cmd.Length.ToString)
System.Threading.Thread.Sleep(100)
_SerialPort.Write(cmd)

Avatar
SESupply
New Member
Forum Posts: 4
sp_UserOfflineSmall Offline
5
June 28, 2015 - 12:30 am
sp_Permalink sp_Print

Hi Michael, thanks so much for your help - it is now finally working.
Cool

Avatar
MatHoff
New Member
Forum Posts: 3
sp_UserOfflineSmall Offline
6
September 23, 2015 - 2:23 pm
sp_Permalink sp_Print

Hi,

Im trying to create simple Arduino project. 2 Arduino Uno boards, first one is sending sensor data to Thingspeak by ESP8266, second one is responding to received data. I managed to setup sending device without any problems, but i get 400 error while im trying to receive data with second device. To make sure it's not problem with my code i used Termite terminal and simply send AT commands to ESP. CR and LF signs are enabled.

This is the field im trying to get data from: https://thingspeak.com/channels/39433/fields/2/last

This is my terminal window:

AT+CWMODE=1
AT+CWMODE=1

OK
AT+CWJAP="test","12345678"
AT+CWJAP="test","12345678"

OK
AT+CIPSTART="TCP","184.106.153.149",80
AT+CIPSTART="TCP","184.106.153.149",80

CONNECT

OK
AT+CIPSEND=51
AT+CIPSEND=51

OK
> https://thingspeak.com/channels/39433/fields/2/last
https://thingspeak.com/channels/39433/fields/2/last
busy s...

SEND OK

+IPD,323:HTTP/1.1 400 Bad Request
Server: nginx/1.7.5
Date: Wed, 23 Sep 2015 18:21:41 GMT
Content-Type: text/html
Content-Length: 172
Connection: close

400 Bad Request

400 Bad Request


nginx/1.7.5

CLOSED

What am i doing wrong? Thanks for any help.

Avatar
lee

Forum Posts: 457
sp_UserOfflineSmall Offline
7
September 23, 2015 - 2:42 pm
sp_Permalink sp_Print

Hi,

You may have more success using our API URL which bypasses HTTPS, for example: http://api.thingspeak.com/channels/39433/fields/2/last .

lee

Avatar
MatHoff
New Member
Forum Posts: 3
sp_UserOfflineSmall Offline
8
September 23, 2015 - 3:43 pm
sp_Permalink sp_Print

Just tried your suggestion, i still get the same error. Any more ideas?

Avatar
lee

Forum Posts: 457
sp_UserOfflineSmall Offline
9
September 23, 2015 - 3:51 pm
sp_Permalink sp_Print

Hi MatHoff,

Are you able to provide more details as to what your HTTP request looks like? Are you able to make HTTP requests to other websites?

lee

Avatar
MatHoff
New Member
Forum Posts: 3
sp_UserOfflineSmall Offline
10
September 26, 2015 - 8:29 am
sp_Permalink sp_Print

Hi.

Im not sure if i understand you well, this is my first IoT project. Im not using HTTP POST request, im using GET method from this tutorial https://thingspeak.com/docs/channels#update_feed , paragraph "Get last entry in a field feed". Im just sending URL from example to ThingSpeak server just like i did in code from post 6. Am i doing it right?

Avatar
lee

Forum Posts: 457
sp_UserOfflineSmall Offline
11
September 28, 2015 - 8:51 am
sp_Permalink sp_Print

Hi MatHoff,

Yes that is the right API command to update a feed. Instead of sending a request to ThingSpeak, can you try sending a HTTP GET request to google.com, yahoo.com, or some other service to determine if your HTTP requests are formatted correctly and sending correctly? My guess is that before the request is sent, in your code the request is somehow being formed incorrectly.

lee

Avatar
yukimach
New Member
Forum Posts: 2
sp_UserOfflineSmall Offline
12
January 18, 2016 - 2:55 pm
sp_Permalink sp_Print

I've just tried to send the following
GET /update?key=[apikey]&field1=200&headers=false HTTP/1.1
Host: api.thingspeak.com
Connection: close
Accept: */*

and got the folowing back:

wrong syntax

ERROR

SEND OK

+IPD,4,323:HTTP/1.1 400 Bad Request
Server: nginx/1.7.5
Date: Mon, 18 Jan 2016 19:50:43 GMT
Content-Type: text/html
Content-Length: 172
Connection: close

I'm using an Arduino +ESP8266 set up and can't seem to get my channel update to work.
I've also tried
GET http://api.thingspeak.com/update?key=%5Bkey%5D&field1=800/r/n/r/n
Which seem to be recognised by my channel as data, as the last update read "less than a minute ago". However, the point isn't plotted or not visible on my chart. when i paste thehttp://api.thingspeak.com/update?key=[key]&field1=800/r/n/r/n into my browser it updates the field fine.. Is the ESP not sending the GET command in the right format?

Would really appreciate some help Yell

Avatar
Michel_J

Silver
Forum Posts: 13
sp_UserOfflineSmall Offline
13
January 18, 2016 - 3:17 pm
sp_Permalink sp_Print

yukimach said

wrong syntax

ERROR

SEND OK

"wrong syntax" comes from the ESP8266. Inspect carrefully your code. If you have a spare USB to TTL serial use a terminal to spy on what you actually send to the ESP, that helps a lot.

Avatar
jenifferhomes
New Member
Forum Posts: 3
sp_UserOfflineSmall Offline
14
July 4, 2016 - 9:11 am
sp_Permalink sp_Print

i get 400 error while im trying to receive data with second device. To make sure it's not problem with my code i used Termite terminal and simply send AT commands to ESP. CR and LF signs are enabled.

Forum Timezone: America/New_York

Most Users Ever Online: 114

Currently Online:
21 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

rw950431: 252

Vinod: 164

cstapels: 96

piajola: 75

vespapierre: 63

Adarsh_Murthy: 59

Newest Members:

yeseniara11

RomanFug

JamesPes

RobertBak

ScottSmiva

Amourhotte

Forum Stats:

Groups: 4

Forums: 17

Topics: 1313

Posts: 4565

 

Member Stats:

Guest Posters: 1

Members: 5703

Moderators: 0

Admins: 2

Administrators: Hans, lee