Pages: [1]   Go Down
Author Topic: HTTP/1.1 400 Bad Request from Cosm website  (Read 2078 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Full Member
***
Karma: 0
Posts: 112
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i have been trying to post data on my cosm feed but i keep getting the below mentioned error. I have given below the commands that I am sending. Does any body has an idea whats the thing wrong in my line of commands ?

And my guess was that the user agent is the device name we give in cosm. when i added this, i started getting the bad request error. Before this, without adding the user agent part, i was getting the unauthorized error.

Please help


> PUT /v2/feeds/62521.csv HTTP/1.1
Host: api.cosm.com
X-ApiKey: 4HaJl25MfMGEb9g2khkjhujhk9leaSAKxCNl
User-Agent: Arduino
Content-Length: 12
Connection: close

This is a post



SEND OK
HTTP/1.1 400 Bad Request
Logged

ਪੰਜਾਬ
Offline Offline
Edison Member
*
Karma: 12
Posts: 1601
Another year! Alone! :(
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Definitely there is something left out in your code ,may be letting us view whole code may make us catch the culprit
Logged

"Real Men can Accomplish  Anything"
-  Website  
- skype : nishants5  

ਫ਼ਤੇਹ ਕਰੂਂ !

Switzerland
Offline Offline
Faraday Member
**
Karma: 108
Posts: 5144
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
This is a post

Wrong, this is a PUT. And that's probably the problem. I don't know COSM but it seems they don't accept PUT requests. Try using

Code:
telnet api.cosm.com 80

and write the same stuff as you have above, you'll get the same answer. Try modifying the request till you have a working  request structure. Then implement it into Arduino software.
Logged

ਪੰਜਾਬ
Offline Offline
Edison Member
*
Karma: 12
Posts: 1601
Another year! Alone! :(
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

rightly said by pylon try it
Logged

"Real Men can Accomplish  Anything"
-  Website  
- skype : nishants5  

ਫ਼ਤੇਹ ਕਰੂਂ !

UK
Offline Offline
Faraday Member
**
Karma: 99
Posts: 4153
Where is your SSCCE?!?!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I haven't used the csv interface to COSM - I use the JSON one, but it looks to me like the data you are sending in the PUT request (Yes, COSM does support PUT) is invalid.

Have you tried looking at the debug information on your cosm account?  (select your username in top-right, then select debug).  You can see the requests coming in live as they are made and should give you more information.

Also, try looking at the existing csv feed file (do a GET on the same URI), and copying the format of the data exactly.

Btw: my solar charger cosm feed: https://cosm.com/feeds/62902 - data pushed direct from an UNO using a home-made ENC28J60 ethernet shield.
« Last Edit: June 13, 2012, 04:28:18 am by majenko » Logged

Get 10% off all 4D Systems TFT screens this month: use discount code MAJENKO10

Offline Offline
Full Member
***
Karma: 0
Posts: 112
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have been able to post the some data on the cosm. I changed the text given in the previous post "This is a post" to "Awake    ," and it started to post the data. I am not sure but i guess it has something to do with the content length.

Can you please elaborate to me how this content length works and if i need to send the variable such as float or double after the string what I need to do.

Plus i checked out your solar charger feed and its really cool. You have done a great job. I need to post some voltage data. How have you drawn the graphs. Is there a way to fetch variable data from the string or data that is being posted.
Logged

UK
Offline Offline
Faraday Member
**
Karma: 99
Posts: 4153
Where is your SSCCE?!?!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I have been able to post the some data on the cosm. I changed the text given in the previous post "This is a post" to "Awake    ," and it started to post the data. I am not sure but i guess it has something to do with the content length.

Can you please elaborate to me how this content length works and if i need to send the variable such as float or double after the string what I need to do.

The content-length is the total number of characters in the body of the post.  This includes any line-feeds and carriage-returns.

Quote
Plus i checked out your solar charger feed and its really cool. You have done a great job. I need to post some voltage data. How have you drawn the graphs. Is there a way to fetch variable data from the string or data that is being posted.
Cosm draws the graphs - that is the purpose of it.  You send data, it graphs it.
Logged

Get 10% off all 4D Systems TFT screens this month: use discount code MAJENKO10

Offline Offline
Full Member
***
Karma: 0
Posts: 112
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If i send a string of characters and a float number, then how should i check the value for content length. I mean how many characters does the float variable represent ?

Secondly I want to make a graph that counts the time a particular feed is received. But I am unable to find a way to count the feed and plot the graph. Can u give me any link to a tutorial or provide any clue ?

Thanks a lot for the help.

Do you know how to get the volts value out of the feed and use it in the graph
Logged

UK
Offline Offline
Faraday Member
**
Karma: 99
Posts: 4153
Where is your SSCCE?!?!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

If i send a string of characters and a float number, then how should i check the value for content length. I mean how many characters does the float variable represent ?

I have no idea - the ethernet library I use calculates it all automatically and adds all the relevent headers for me.  Without knowing how you are making the connection, and with what libraries, I can't say.

Quote
Secondly I want to make a graph that counts the time a particular feed is received. But I am unable to find a way to count the feed and plot the graph. Can u give me any link to a tutorial or provide any clue ?

Thanks a lot for the help.

Do you know how to get the volts value out of the feed and use it in the graph

Sorry, I am a newbie to cosm too.  I just send data from my Arduino and graphs appear.
Logged

Get 10% off all 4D Systems TFT screens this month: use discount code MAJENKO10

0
Offline Offline
Newbie
*
Karma: 0
Posts: 14
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

the problem is that you are making a PUT request using the wrong data format for cosm - looks like you are using the old data format (from the v1 api, it's now v2). the second data you sent ('awake ,') looks like the v2 data format but it isn't quite right either, because it should be in the form 'datastream_id, value' (assuming you want 'awake' to be your value not '<blank>').

this is in the documentation here: http://cosm.com/docs/v2/feed/update.html (click "CSV") and you'll see the correct data format.

by the way you left your API key in your forum post - this is a mistake! remember your API key is like a password to your data so you should delete the key since it's now public and could be used maliciously (look for the 'Keys' link in the menu in your user bar in the top right hand corner).
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 14
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

by the way you might find this library useful since it takes care of all the content length etc and communicating with cosm servers for you: https://github.com/amcewen/Cosm-Arduino/downloads
Logged

Boston
Offline Offline
God Member
*****
Karma: 3
Posts: 575
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm using the following for cosm.com and it seems to work.
I haven't tested for version 2 yet. 

Code:
uint8 ip[] = {216,52,233,121};
char hostName[] = "api.cosm.com\nX-PachubeApiKey: "Your key here"\nConnection: close";
char url[] = "/v1/feeds/58529.csv?_method=put";
POSTrequest postPachube(ip, 80, hostName, url, feedData);
Logged

Pages: [1]   Go Up
Jump to: