Plotly Cloud Dienst mit Sensorwerten

Dependencies:   EthernetInterface mbed-rtos mbed plotly

Fork of Plotly_HelloWorld by Andy A

Committer:
AndyA
Date:
Tue Jul 29 13:55:43 2014 +0000
Revision:
1:5e7145bb2184
Parent:
0:c7329ea5d8d5
Child:
2:99852a7499da
Updated to show demonstrate multi-line chart support

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AndyA 0:c7329ea5d8d5 1
AndyA 0:c7329ea5d8d5 2 #include "mbed.h"
AndyA 0:c7329ea5d8d5 3 #include "EthernetInterface.h"
AndyA 0:c7329ea5d8d5 4 #include "plotly.h"
AndyA 0:c7329ea5d8d5 5
AndyA 0:c7329ea5d8d5 6 Serial pc(USBTX,USBRX);
AndyA 0:c7329ea5d8d5 7
AndyA 0:c7329ea5d8d5 8 EthernetInterface eth;
AndyA 0:c7329ea5d8d5 9
AndyA 0:c7329ea5d8d5 10 // plotly account details
AndyA 1:5e7145bb2184 11 const int numberOfTraces = 3;
AndyA 1:5e7145bb2184 12 const char PlotlyUsername[] = "YoutUsername";
AndyA 1:5e7145bb2184 13 const char PlotlyAPIToken[] = "YourAPIKey";
AndyA 1:5e7145bb2184 14 const char *PlotlyStreamingTokens[numberOfTraces] = {"YourStreamToken","YourSecondStreamToken"}; // or {"YourStreamToken"} for a single line. Must match numberOfTraces
AndyA 1:5e7145bb2184 15 const char PlotlyFileName[] = "Mbed Test Chart";
AndyA 0:c7329ea5d8d5 16
AndyA 1:5e7145bb2184 17 plotly graph = plotly(PlotlyUsername,PlotlyAPIToken, PlotlyStreamingTokens, PlotlyFileName, numberOfTraces);
AndyA 0:c7329ea5d8d5 18
AndyA 0:c7329ea5d8d5 19 void plotSetup()
AndyA 0:c7329ea5d8d5 20 {
AndyA 1:5e7145bb2184 21 graph.log_level = 1; // turn on status output
AndyA 0:c7329ea5d8d5 22 graph.maxpoints = 72;
AndyA 0:c7329ea5d8d5 23 if (graph.init()) {
AndyA 1:5e7145bb2184 24 graph.openStreams();
AndyA 0:c7329ea5d8d5 25 }
AndyA 0:c7329ea5d8d5 26
AndyA 0:c7329ea5d8d5 27 }
AndyA 0:c7329ea5d8d5 28
AndyA 1:5e7145bb2184 29 // Generate some simple sample data points
AndyA 0:c7329ea5d8d5 30 void plotGenerateDataPoint()
AndyA 0:c7329ea5d8d5 31 {
AndyA 1:5e7145bb2184 32 static float counter = 0;
AndyA 1:5e7145bb2184 33
AndyA 1:5e7145bb2184 34 // generate a series of sine waves with slightly different frequencies.
AndyA 1:5e7145bb2184 35 for (int i = 0; i < numberOfTraces; i++) {
AndyA 1:5e7145bb2184 36 graph.plot(counter, (float)sin(counter * (1-i*0.1)), i);
AndyA 1:5e7145bb2184 37 }
AndyA 1:5e7145bb2184 38
AndyA 1:5e7145bb2184 39 counter+=0.2;
AndyA 0:c7329ea5d8d5 40 }
AndyA 0:c7329ea5d8d5 41
AndyA 0:c7329ea5d8d5 42
AndyA 0:c7329ea5d8d5 43 int main()
AndyA 0:c7329ea5d8d5 44 {
AndyA 0:c7329ea5d8d5 45 pc.baud(115200);
AndyA 0:c7329ea5d8d5 46
AndyA 0:c7329ea5d8d5 47 pc.printf("Connecting network...\n");
AndyA 0:c7329ea5d8d5 48
AndyA 0:c7329ea5d8d5 49 eth.init();
AndyA 0:c7329ea5d8d5 50 eth.connect();
AndyA 0:c7329ea5d8d5 51
AndyA 0:c7329ea5d8d5 52 char *ipAddress = eth.getIPAddress();
AndyA 0:c7329ea5d8d5 53 if (ipAddress && (strlen(ipAddress) > 4)) {
AndyA 0:c7329ea5d8d5 54
AndyA 0:c7329ea5d8d5 55 pc.printf("IP Address is %s\n",eth.getIPAddress());
AndyA 0:c7329ea5d8d5 56 pc.printf("Initalise plot..\n");
AndyA 0:c7329ea5d8d5 57
AndyA 0:c7329ea5d8d5 58 plotSetup();
AndyA 0:c7329ea5d8d5 59
AndyA 0:c7329ea5d8d5 60 pc.printf("Generating data, press any key to abort.\n");
AndyA 0:c7329ea5d8d5 61 while (!pc.readable()) {
AndyA 0:c7329ea5d8d5 62 plotGenerateDataPoint();
AndyA 0:c7329ea5d8d5 63 wait(0.5);
AndyA 0:c7329ea5d8d5 64 }
AndyA 1:5e7145bb2184 65 graph.closeStreams();
AndyA 0:c7329ea5d8d5 66
AndyA 0:c7329ea5d8d5 67 } else
AndyA 0:c7329ea5d8d5 68 pc.printf("No IP Address\n");
AndyA 0:c7329ea5d8d5 69
AndyA 0:c7329ea5d8d5 70 eth.disconnect();
AndyA 0:c7329ea5d8d5 71
AndyA 0:c7329ea5d8d5 72 pc.printf("Done\n");
AndyA 0:c7329ea5d8d5 73
AndyA 0:c7329ea5d8d5 74 while (1) {
AndyA 0:c7329ea5d8d5 75 wait(10);
AndyA 0:c7329ea5d8d5 76 }
AndyA 0:c7329ea5d8d5 77 }