Plotly Cloud Dienst mit Sensorwerten

Dependencies:   EthernetInterface mbed-rtos mbed plotly

Fork of Plotly_HelloWorld by Andy A

Committer:
stefan1691
Date:
Wed Mar 18 12:51:58 2015 +0000
Revision:
2:99852a7499da
Parent:
1:5e7145bb2184
Plotly Cloud Dienst mit Sensorwerten

Who changed what in which revision?

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