Issue posting data to plot.ly

Hi All,

I have been using plot.ly to graph data from my imp for some time now and suddenly I have been receiving the following error when trying to post new data.

2015-11-10 08:18:45 UTC-8 [Agent] { "body": "{\"url\": \"\", \"message\": \"\", \"warning\": \"\", \"filename\": \"\", \"error\": \"Missing required POST parameters: platform un key origin args kwargs\"}", "statuscode": 200, "headers": { "server": "nginx/1.4.6 (Ubuntu)", "content-length": "138", "connection":

As far as I know my code has not changed so I am assuming plotly may have changed the way in which they expect to receive data.

Any insight into this issue would be greatly appreciated. Relevant code can be seen here:

// Setting up Data to be POSTed local payload = { un = "spellbin", key = "****************", origin = "plot", platform = "electricimp", args = http.jsonencode(data), kwargs = http.jsonencode(layout), version = "0.0.1" };
// encode data and log
local headers = { "Content-Type" : "application/json" };
local body = http.urlencode(payload);
local url = "https://plot.ly/clientresp";
server.log(payload);
server.log(body);
HttpPostWrapper(url, headers, body, true);

});

Thanks!

The code you’ve pasted above looks the same as what I have working right now and I can’t see any reason why that shouldn’t be working… Perhaps it’s something else it’s complaining about… What do you have in your ‘layout’ object? … Do you have your full code available somewhere? Cheers!!

Actually… I spoke too soon… I’ve just checked and I’m getting the same ‘Missing required POST parameters’… This was all working fine yesterday, and I’ve got the data on my plots to prove it… Sigh… fix required for me too.

Interesting. Could you paste the #require line you’re using for the library?

edit: Oh, you’re not using the Plotly library. Nevermind then :wink:

Nah - not using the library as it didn’t exist back when I wrote my code (10 months ago)… I can give you a link to my code though if that’s any help… https://github.com/jimconner/greenhouse_monitoring … Cheers!!

I’ve now given things a try with the electric Imp libary for Plotly, using the ‘minimal’ example provided at https://github.com/electricimp/Plotly/tree/master/examples/minimal

Here’s the require line from that example…


#require "Plotly.class.nut:1.0.0"

Things are not working for me using this library either… I don’t get any new plots showing up, and it doesn’t seem to be returning the URL for the graph after it posts the data. I’m not getting the same ‘Missing required POST paramaters’ message, but that might just be getting supressed within the library.


2015-11-15 12:13:49 UTC+0 	[Status] 	Agent restarted: reload.
2015-11-15 12:13:49 UTC+0 	[Status] 	Downloading new code; 8.30% program storage used
2015-11-15 12:13:50 UTC+0 	[Agent] 	See plot at 
2015-11-15 12:13:51 UTC+0 	[Device] 	sleeping until 1447589659000
2015-11-15 12:13:51 UTC+0 	[Status] 	Device disconnected
2015-11-15 12:15:31 UTC+0 	[Status] 	Agent restarted: reload.
2015-11-15 12:15:32 UTC+0 	[Agent] 	See plot at 
2015-11-15 12:21:37 UTC+0 	[Status] 	Downloading new code; 8.36% program storage used
2015-11-15 12:21:39 UTC+0 	[Status] 	Device disconnected
2015-11-15 12:21:39 UTC+0 	[Device] 	sleeping until 1447590157000

I’ve now managed to get a modified version of the ‘minimal’ example working by adding some extra logging code so that I could get the error message back from plot.ly - This is just plotting a very simple graph for now with only one data series. I stuck my test code up on github in case it comes in useful for anyone. https://github.com/jimconner/plotly_test_imp

And I’ve also now got things working with more complete code… so I can confirm 100% that using the electricimp plotly libary solves the issue 100%.

Excellent. I’ll have to port my code over to use the library as well I guess. Good work!

Just been notified from the plot.ly forums (thanks to sutherlandmj) that the root cause of this problem is having Content-type Application/JSON in the headers. If you set ‘local headers = {};’ instead, then the original code works fine. Cheers!!

Great news. Thanks Jim!