Simple demo for plotly library
Dependencies: EthernetInterface mbed-rtos mbed plotly
A basic example of streaming data to a chart on plot.ly
Assumes a wired ethernet connection with direct internet access and a DHCP server.
Chart URL and status is output via the usb serial port at 115200.
You will need to modify the plot.ly account information at the start of main.cpp to match your account on http://plot.ly
Revision 1:5e7145bb2184, committed 2014-07-29
- Comitter:
- AndyA
- Date:
- Tue Jul 29 13:55:43 2014 +0000
- Parent:
- 0:c7329ea5d8d5
- Commit message:
- Updated to show demonstrate multi-line chart support
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
plotly.lib | Show annotated file Show diff for this revision Revisions of this file |
diff -r c7329ea5d8d5 -r 5e7145bb2184 main.cpp --- a/main.cpp Fri Jul 11 10:11:00 2014 +0000 +++ b/main.cpp Tue Jul 29 13:55:43 2014 +0000 @@ -8,30 +8,35 @@ EthernetInterface eth; // plotly account details -char PlotlyUsername[] = "YoutUsername"; -char PlotlyAPIToken[] = "YourAPIKey"; -char streaming_token[] = "YourStreamToken"; -char fileName[] = "Mbed Test Chart"; +const int numberOfTraces = 3; +const char PlotlyUsername[] = "YoutUsername"; +const char PlotlyAPIToken[] = "YourAPIKey"; +const char *PlotlyStreamingTokens[numberOfTraces] = {"YourStreamToken","YourSecondStreamToken"}; // or {"YourStreamToken"} for a single line. Must match numberOfTraces +const char PlotlyFileName[] = "Mbed Test Chart"; -plotly graph = plotly(PlotlyUsername, PlotlyAPIToken, streaming_token, fileName); +plotly graph = plotly(PlotlyUsername,PlotlyAPIToken, PlotlyStreamingTokens, PlotlyFileName, numberOfTraces); void plotSetup() { - graph.log_level = 2; // turn on status output + graph.log_level = 1; // turn on status output graph.maxpoints = 72; if (graph.init()) { - graph.openStream(); + graph.openStreams(); } } -// Generate a sample chart +// Generate some simple sample data points void plotGenerateDataPoint() { - static int counter = 0; - float yValue = sin(counter*3.14159/180); - graph.plot(counter, yValue); - counter+=5; + static float counter = 0; + + // generate a series of sine waves with slightly different frequencies. + for (int i = 0; i < numberOfTraces; i++) { + graph.plot(counter, (float)sin(counter * (1-i*0.1)), i); + } + + counter+=0.2; } @@ -57,7 +62,7 @@ plotGenerateDataPoint(); wait(0.5); } - graph.closeStream(); + graph.closeStreams(); } else pc.printf("No IP Address\n");
diff -r c7329ea5d8d5 -r 5e7145bb2184 plotly.lib --- a/plotly.lib Fri Jul 11 10:11:00 2014 +0000 +++ b/plotly.lib Tue Jul 29 13:55:43 2014 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/AndyA/code/plotly/#33006c37c633 +http://mbed.org/users/AndyA/code/plotly/#d4f705ba2ea5