I've updated the code to work with the current API (as of 11:42PM 9th June 2016).
The code required "Content-Type: application/x-www-form-urlencoded\r\n" be placed in the POST header.
POST /clientresp HTTP/1.1
Host: plot.ly:80
User-Agent: Arduino/0.6.0
Content-Type: application/x-www-form-urlencoded
Content-Length: 241
version=2.3&origin=plot&platform=arduino&un=johnnyizz&key=xxxxxxxxxx&args=[{"y": [], "x": [], "type": "scatter", "stream": {"token": "xxxxxxxxxx", "maxpoints": 30}}]&kwargs={"fileopt": "overwrite", "filename": "test", "world_readable": true}
The rest of the code remains untouched.
The API has change since I first wrote my code, it is much more flexible now, so some other modifications can be made to make the code more simple.
This type POST will now work: (Notice Content-Length doesn't need calculation!)
POST /clientresp HTTP/1.1
Host: plot.ly
Content-Type: application/x-www-form-urlencoded
version=2.3&origin=plot&platform=arduino&un=johnnyizz&key=xxxxxxxxxx&args=[{"y": [], "x": [], "type": "scatter", "stream": {"token": "xxxxxxxxxx", "maxpoints": 30}}]&kwargs={"fileopt": "overwrite", "filename": "test", "world_readable": true}
Data can now also be sent as: (Notice JSON string length doesn't need calculating!)
POST HTTP/1.1
Host: arduino.plot.ly
{"x": 1234, "y": 1234, "streamtoken": "xxxxxxxxxx"}
orPOST HTTP/1.1
Host: stream.plot.ly
plotly-streamtoken: xxxxxxxxxx
{"x": 1234, "y": 1234}
A following "\r\n0\r\n\r\n" (as seen in the my code) will close the connection (you will need to resend the header) or 60 seconds of the server not receiving a '\n'. If the connection doesn't close, subsequent data (e.g. "{"x": 1234, "y": 1234}\n") can be sent.
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.