Simple demo for plotly library
Dependencies: EthernetInterface mbed-rtos mbed plotly
main.cpp
00001 00002 #include "mbed.h" 00003 #include "EthernetInterface.h" 00004 #include "plotly.h" 00005 00006 Serial pc(USBTX,USBRX); 00007 00008 EthernetInterface eth; 00009 00010 // plotly account details 00011 const int numberOfTraces = 3; 00012 const char PlotlyUsername[] = "YoutUsername"; 00013 const char PlotlyAPIToken[] = "YourAPIKey"; 00014 const char *PlotlyStreamingTokens[numberOfTraces] = {"YourStreamToken","YourSecondStreamToken"}; // or {"YourStreamToken"} for a single line. Must match numberOfTraces 00015 const char PlotlyFileName[] = "Mbed Test Chart"; 00016 00017 plotly graph = plotly(PlotlyUsername,PlotlyAPIToken, PlotlyStreamingTokens, PlotlyFileName, numberOfTraces); 00018 00019 void plotSetup() 00020 { 00021 graph.log_level = 1; // turn on status output 00022 graph.maxpoints = 72; 00023 if (graph.init()) { 00024 graph.openStreams(); 00025 } 00026 00027 } 00028 00029 // Generate some simple sample data points 00030 void plotGenerateDataPoint() 00031 { 00032 static float counter = 0; 00033 00034 // generate a series of sine waves with slightly different frequencies. 00035 for (int i = 0; i < numberOfTraces; i++) { 00036 graph.plot(counter, (float)sin(counter * (1-i*0.1)), i); 00037 } 00038 00039 counter+=0.2; 00040 } 00041 00042 00043 int main() 00044 { 00045 pc.baud(115200); 00046 00047 pc.printf("Connecting network...\n"); 00048 00049 eth.init(); 00050 eth.connect(); 00051 00052 char *ipAddress = eth.getIPAddress(); 00053 if (ipAddress && (strlen(ipAddress) > 4)) { 00054 00055 pc.printf("IP Address is %s\n",eth.getIPAddress()); 00056 pc.printf("Initalise plot..\n"); 00057 00058 plotSetup(); 00059 00060 pc.printf("Generating data, press any key to abort.\n"); 00061 while (!pc.readable()) { 00062 plotGenerateDataPoint(); 00063 wait(0.5); 00064 } 00065 graph.closeStreams(); 00066 00067 } else 00068 pc.printf("No IP Address\n"); 00069 00070 eth.disconnect(); 00071 00072 pc.printf("Done\n"); 00073 00074 while (1) { 00075 wait(10); 00076 } 00077 }
Generated on Thu Jul 21 2022 19:35:07 by 1.7.2