Error 400 Bad Request | ESP Wi-Fi | Forum

Avatar

Please consider registering
Guest

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —






— Match —





— Forum Options —





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

sp_Feed sp_TopicIcon
Error 400 Bad Request
No permission to create posts
June 22, 2015
2:11 am
Avatar
SESupply
New Member
Members
Forum Posts: 4
Member Since:
June 22, 2015
sp_UserOfflineSmall Offline

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.

June 22, 2015
12:10 pm
Avatar
Michel_J

Silver
Members
Forum Posts: 13
Member Since:
February 8, 2015
sp_UserOfflineSmall Offline

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

June 23, 2015
2:14 am
Avatar
SESupply
New Member
Members
Forum Posts: 4
Member Since:
June 22, 2015
sp_UserOfflineSmall Offline

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??

June 24, 2015
4:05 pm
Avatar
Michel_J

Silver
Members
Forum Posts: 13
Member Since:
February 8, 2015
sp_UserOfflineSmall Offline

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)

June 28, 2015
12:30 am
Avatar
SESupply
New Member
Members
Forum Posts: 4
Member Since:
June 22, 2015
sp_UserOfflineSmall Offline

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

September 23, 2015
2:23 pm
Avatar
MatHoff
New Member
Members
Forum Posts: 3
Member Since:
September 23, 2015
sp_UserOfflineSmall Offline

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.

September 23, 2015
2:42 pm
Avatar
lee

Admin
Forum Posts: 457
Member Since:
March 14, 2011
sp_UserOfflineSmall Offline

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

September 23, 2015
3:43 pm
Avatar
MatHoff
New Member
Members
Forum Posts: 3
Member Since:
September 23, 2015
sp_UserOfflineSmall Offline

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

September 23, 2015
3:51 pm
Avatar
lee

Admin
Forum Posts: 457
Member Since:
March 14, 2011
sp_UserOfflineSmall Offline

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

September 26, 2015
8:29 am
Avatar
MatHoff
New Member
Members
Forum Posts: 3
Member Since:
September 23, 2015
sp_UserOfflineSmall Offline

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?

September 28, 2015
8:51 am
Avatar
lee

Admin
Forum Posts: 457
Member Since:
March 14, 2011
sp_UserOfflineSmall Offline

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

January 18, 2016
2:55 pm
Avatar
yukimach
New Member
Members
Forum Posts: 2
Member Since:
January 18, 2016
sp_UserOfflineSmall Offline

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

January 18, 2016
3:17 pm
Avatar
Michel_J

Silver
Members
Forum Posts: 13
Member Since:
February 8, 2015
sp_UserOfflineSmall Offline

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.

July 4, 2016
9:11 am
Avatar
jenifferhomes
New Member
Members
Forum Posts: 3
Member Since:
June 21, 2016
sp_UserOfflineSmall Offline

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: 166

Currently Online:
19 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

rw950431: 272

Vinod: 240

piajola: 95

turgo: 70

vespapierre: 63

Adarsh_Murthy: 62

Member Stats:

Guest Posters: 1

Members: 8665

Moderators: 1

Admins: 2

Forum Stats:

Groups: 3

Forums: 14

Topics: 1600

Posts: 5760

Newest Members:

dogarty, dlwiener, bulksms, bmchoice4u, irajames, YesItsMe

Moderators: cstapels: 460

Administrators: Hans: 405, lee: 457