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.h
- Revision:
- 0:96532c59670f
- Child:
- 1:d532e96fca12
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plotly.h Wed Jul 02 08:47:09 2014 +0000 @@ -0,0 +1,85 @@ +#ifndef plotly_streaming_ethernet_h +#define plotly_streaming_ethernet_h + +#include <EthernetInterface.h> +#include <TCPSocketConnection.h> + +EthernetInterface eth; + +/********************************* +in main.cpp +#define num_traces 1 +// Sign up to plotly here: https://plot.ly +// View your API key and stream tokens in your settings: https://plot.ly/settings +char *streaming_tokens[num_traces] = {"leofdu7cun"}; +plotly graph = plotly("AndyA", "acchq52p7j", streaming_tokens, "test1", num_traces); + +void plotSetup() { + +// eth.init(); +// eth.connect(); + + // Initialize a streaming graph in your plotly account + pc.printf("plot init..\n"); + graph.init(); + pc.printf("Open stream..\n"); + // Initialize plotly's streaming service + graph.openStream(); +} + +void plotGenerateData() { + static int counter = 0; + graph.plot(counter, counter*counter, streaming_tokens[0]); + counter++; +} + + +********************************************/ +class plotly +{ + public: + plotly(char *username, char *api_key, char* stream_tokens[], char *filename, int nTraces); + ~plotly(); + bool init(); + void openStream(); + void closeStream(); + void reconnectStream(); + void jsonStart(int i); + void jsonMiddle(); + void jsonEnd(char *token); + + void plot(unsigned long x, int y, char *token); + void plot(unsigned long x, float y, char *token); + + int log_level; + bool dry_run; + int maxpoints; + bool world_readable; + bool convertTimestamp; + char *timezone; + char *fileopt; + + private: + void print_(int d); + void print_(unsigned long d); + void print_(float d); + void print_(char *d); + void printHex_(uint16_t d); + + int len_(int i); + int len_(unsigned long i); + int len_(char *i); + + char txBuffer[128]; + char rxBuffer[128]; + TCPSocketConnection socket; + + unsigned long fibonacci_; + char *username_; + char *api_key_; + char** stream_tokens_; + char *filename_; + int nTraces_; + +}; +#endif