plotly interface based on ardunio sample code

Dependents:   Plotly_HelloWorld

Library for plotting a simple x/y scatter chart on the plot.ly website.

See plotly_HelloWorld for sample usage.

Revision:
6:e57d6e9313f4
Parent:
2:d53d74ed68ac
Child:
7:9409a72ab6c0
--- a/plotly.h	Fri Jul 11 08:08:06 2014 +0000
+++ b/plotly.h	Tue Jul 29 11:45:09 2014 +0000
@@ -4,55 +4,25 @@
 #include <EthernetInterface.h>
 #include <TCPSocketConnection.h>
 
-
-/*********************************
-in main.cpp
-EthernetInterface eth;
-#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++;
-}
-
-
-********************************************/
-
 #define k_bufferSize 512
 
 class plotly
 {
     public:
-        plotly(char *username, char *api_key, char* stream_tokens[], char *filename, int nTraces);
+        plotly(const char *username, const char *api_key, const char* stream_tokens[], const char *filename, int nTraces);
         ~plotly();
         bool init();
-        void openStream();
-        void closeStream();
-        void reconnectStream();
-        void jsonStart(int i);
-        void jsonMiddle();
-        void jsonEnd(char *token);
+        
+        void openStreams();
+        void closeStreams();
+        
+        void openStream(int stream);
+        void closeStream(int stream);
+        void reconnectStream(int stream);
 
-        void plot(unsigned long x, int y, char *token);
-        void plot(unsigned long x, float y, char *token);
+        void plot(unsigned long x, int y, int stream = 0);
+        void plot(unsigned long x, float y, int stream = 0);
+        void plot(float x, float y, int stream = 0);
 
         int log_level;
         bool dry_run;
@@ -63,29 +33,25 @@
         char *fileopt;
 
     private:
-        bool print_(int d);
-        bool print_(unsigned long d);
-        bool print_(float d);
-        bool print_(char *d);
-        bool printHex_(uint16_t d);
+
+        bool print_(int d,int stream = 0);
+        bool print_(unsigned long d,int stream = 0);
+        bool print_(float d,int stream = 0);
+        bool print_(char *d,int stream = 0) {return print_((const char *)d, stream);};
+        bool print_(const char *d,int stream = 0);
+        bool printHex_(uint16_t d,int stream = 0);
         
-        bool sendFormatedText(char* data, int size);
-        void echoRxData();
-
-
-        int len_(int i);
-        int len_(unsigned long i);
-        int len_(char *i);
+        bool sendFormatedText(char* data, int size,int stream = 0);
 
         char buffer[512];
 //        char rxBuffer[128];
-        TCPSocketConnection *socket;
+        TCPSocketConnection **sockets;
         
         unsigned long fibonacci_;
-        char *username_;
-        char *api_key_;
-        char** stream_tokens_;
-        char *filename_;
+        const char *username_;
+        const char *api_key_;
+        const char** stream_tokens_;
+        const char *filename_;
         int nTraces_;
         
         bool initalised;