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

main.cpp

Committer:
AndyA
Date:
2014-07-29
Revision:
1:5e7145bb2184
Parent:
0:c7329ea5d8d5

File content as of revision 1:5e7145bb2184:


#include "mbed.h"
#include "EthernetInterface.h"
#include "plotly.h"

Serial pc(USBTX,USBRX);

EthernetInterface eth;

// plotly account details
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, PlotlyStreamingTokens, PlotlyFileName, numberOfTraces);

void plotSetup()
{
    graph.log_level = 1; // turn on status output
    graph.maxpoints = 72;
    if (graph.init()) {
        graph.openStreams();
    }

}

// Generate some simple sample data points
void plotGenerateDataPoint()
{
    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;
}


int main()
{
    pc.baud(115200);

    pc.printf("Connecting network...\n");

    eth.init();
    eth.connect();

    char *ipAddress = eth.getIPAddress();
    if (ipAddress && (strlen(ipAddress) > 4)) {

        pc.printf("IP Address is %s\n",eth.getIPAddress());
        pc.printf("Initalise plot..\n");

        plotSetup();

        pc.printf("Generating data, press any key to abort.\n");
        while (!pc.readable()) {
            plotGenerateDataPoint();
            wait(0.5);
            }
        graph.closeStreams();

    } else
        pc.printf("No IP Address\n");

    eth.disconnect();

    pc.printf("Done\n");

    while (1) {
      wait(10);
    }
}