ThingTweet& ESP8266: "400 Bad Request" | ThingSpeak Apps | 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
ThingTweet& ESP8266: "400 Bad Request"
No permission to create posts
April 27, 2015
5:50 pm
Avatar
2BitBot
New Member
Members
Forum Posts: 3
Member Since:
April 27, 2015
sp_UserOfflineSmall Offline

Its been at least 400 this afternoon.. It took me 4 days to get the ESP8266 to talk to my Arduino then it took another 3 days to solve the 64 character buffer limit issue preventing me from sending any data greater than 64 characters to a URL. Now at least I am getting data to ThingSpeak but No matter how I format the POST I get an error. Can somebody provide an example of a POST from an ESP8266 that actually reaches Twitter?

I send the POST statement exactly the way I copied if off the documentation page:
POST +Space+URL + CR+LF+Tab+api_key+CR+LF+Tab+Status+CR+LF+CR+LF

Here is the output I am getting from my program:

AT+CIPSTART="TCP","184.106.153.149", 80
AT+CIPSEND=121
>

DebugMsg: Everything looks good so far... sending command..:-)
POST https://api.thingspeak.com/apps/thingtweet/1/statuses/update api_key=MYLONGKEYHERE status=Arduino Tweet 001

SEND OK

+IPD,172:
400 Bad Request

400 Bad Request


nginx/1.7.5

OK

OK
Unlink
DebugMsg: Another Error message! Start over :-(

April 27, 2015
8:02 pm
Avatar
2BitBot
New Member
Members
Forum Posts: 3
Member Since:
April 27, 2015
sp_UserOfflineSmall Offline

Ha! :-) Found another code example on GitHub and it works! It's Alive!

The Correct format is:

POST /apps/thingtweet/1/statuses/update HTTP/1.1
Host: api.thingspeak.com
Connection: close
Content-Type: application/x-www-form-urlencoded
Content-Length: 49

api_key=MYLONGKEYHERE&status=Arduino Tweet 001

Cool

April 28, 2015
10:22 am
Avatar
Mona_kh
New Member
Members
Forum Posts: 4
Member Since:
April 27, 2015
sp_UserOfflineSmall Offline

Hey their
I am interested to do the same as you did but never get the correct code I'm getting errors for that , may you please show me hoe you wrote your code for this part ,

Thanks

April 28, 2015
1:05 pm
Avatar
2BitBot
New Member
Members
Forum Posts: 3
Member Since:
April 27, 2015
sp_UserOfflineSmall Offline

If by "Part" you mean the HTTP code format here you go....
This is the Arduino sketch code I used.
The variable "request" holds the text I am sending to Twitter..
Oh the "\ n" at the end of several lines is the line feed character.. I don't know how to put that in here without it turning into a an actual line feed... just remove the space between the \ and the n in your code.

//create the request string
request = "api_key=MYLONGKEYHERE&status="+request;

String sendcommand = "POST /apps/thingtweet/1/statuses/update HTTP/1.1\ n";
sendcommand += "Host: api.thingspeak.com\ n";
sendcommand += "Connection: close\ n";
sendcommand += "Content-Type: application/x-www-form-urlencoded\ n";
sendcommand += "Content-Length: ";
sendcommand += request.length();
sendcommand += "\ n\ n";
sendcommand += request;

First you connect to Thingspeak.com using CIPSTART
String startcommand = "AT+CIPSTART=\"TCP\",\"184.106.153.149\", 80";

Then you tell it how many characters of data to send wtih CIPSEND
Serial.print("AT+CIPSEND=");
Serial.println(sendcommand.length()+2);

Finally you send the "sendcommand" string 64 characters at a time pausing to wait for ESP8266 to echo back the substring just sent before sending the next substring.
Serial.print(sendcommand.substring(t,i));
t=i; i+=64;
while (Serial.available()) {dbugMon.print(Serial.read())}
Keep Looping until all sendcommand characters are sent. where i >sendcommand.length()

and if you don't make any syntax errors like usually do Embarassed it works!

Once I pretty up my code I'll post it online as part of my Tweeting Dehumidifier that tweets when it needs to have it's bucket emptied. I'll be looking for funny suggestions for the tweet text..

Hope this helps! Good Luck!

October 14, 2015
2:07 pm
Avatar
asadujjaman
New Member
Members
Forum Posts: 2
Member Since:
October 14, 2015
sp_UserOfflineSmall Offline

2BitBot said

Ha! :-) Found another code example on GitHub and it works! It's Alive!
Cool

can you please give me that GitHub link where you find that example or please send me your code.

Thanks!!!

Forum Timezone: America/New_York

Most Users Ever Online: 114

Currently Online:
31 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

rw950431: 261

Vinod: 196

piajola: 85

turgo: 70

vespapierre: 63

Adarsh_Murthy: 62

Member Stats:

Guest Posters: 1

Members: 5703

Moderators: 0

Admins: 2

Forum Stats:

Groups: 4

Forums: 17

Topics: 1313

Posts: 4565

Newest Members:

JudestAboth, concettazx4, lyndarf60, caseybo16, iodiree, emiliacz4

Administrators: Hans: 387, lee: 457