plotly interface based on ardunio sample code
Library for plotting a simple x/y scatter chart on the plot.ly website.
See plotly_HelloWorld for sample usage.
Diff: plotly.cpp
- Revision:
- 3:967be3d46701
- Parent:
- 2:d53d74ed68ac
- Child:
- 4:33006c37c633
- Child:
- 6:e57d6e9313f4
--- a/plotly.cpp Thu Jul 03 15:21:30 2014 +0000 +++ b/plotly.cpp Fri Jul 11 08:08:06 2014 +0000 @@ -1,14 +1,9 @@ #include "plotly.h" #include "mbed.h" -#define plotlyURL "arduino.plot.ly" - +#define plotlyURL "plot.ly" #define dataURL "arduino.plot.ly" - -//#define plotlyURL "192.168.1.87" -//#define dataURL "192.168.1.87" - plotly::plotly(char *username, char *api_key, char* stream_tokens[], char *filename, int nTraces) { log_level = 0; // 0 = Debugging, 1 = Informational, 2 = Status, 3 = Errors, 4 = Quiet (// Serial Off) @@ -63,7 +58,7 @@ print_("POST /clientresp HTTP/1.1\r\n"); print_("Host: 107.21.214.199\r\n"); - print_("User-Agent: mBedAA0.01\r\n"); + print_("User-Agent: Arduino/0.5.1\r\n"); print_("plotly-streamtoken: "); print_(stream_tokens_[0]); print_("\r\n"); @@ -100,7 +95,7 @@ // fprintf(stderr,"AutoVersion:\n"); - int lineLen = snprintf(buffer,k_bufferSize,"version=2.2&origin=plot&platform=arduino&un=%s&key=%s&args=[",username_,api_key_); + int lineLen = snprintf(buffer,k_bufferSize,"version=2.3&origin=plot&platform=arduino&un=%s&key=%s&args=[",username_,api_key_); for(int i=0; i<nTraces_; i++) { lineLen += snprintf((buffer+lineLen),k_bufferSize-lineLen,"{\"y\": [], \"x\": [], \"type\": \"scatter\", \"stream\": {\"token\": \"%s\", \"maxpoints\": %d}}%s",stream_tokens_[i],maxpoints,((nTraces_ > 1) && (i != nTraces_-1))?", ":""); } @@ -112,7 +107,7 @@ print_(lineLen); print_("\r\n\r\n"); - lineLen = snprintf(buffer,k_bufferSize,"version=2.2&origin=plot&platform=arduino&un=%s&key=%s&args=[",username_,api_key_); + lineLen = snprintf(buffer,k_bufferSize,"version=2.3&origin=plot&platform=arduino&un=%s&key=%s&args=[",username_,api_key_); for(int i=0; i<nTraces_; i++) { lineLen += snprintf((buffer+lineLen),k_bufferSize-lineLen,"{\"y\": [], \"x\": [], \"type\": \"scatter\", \"stream\": {\"token\": \"%s\", \"maxpoints\": %d}}%s",stream_tokens_[i],maxpoints,((nTraces_ > 1) && (i != nTraces_-1))?", ":""); } @@ -294,10 +289,10 @@ if(log_level < 3) fprintf(stderr,"... Connected to plotly's streaming servers\n... Initializing stream\n"); print_("POST / HTTP/1.1\r\n"); - print_("Host: 127.0.0.1\r\n"); - print_("User-Agent: mBedAA0.01\r\n"); + print_("Host: arduino.plot.ly\r\n"); + print_("User-Agent: Python\r\n"); print_("Transfer-Encoding: chunked\r\n"); - print_("Connection: keep-alive\r\n"); + print_("Connection: close\r\n"); print_("plotly-streamtoken: "); print_(stream_tokens_[0]); print_("\r\n");