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-11
Revision:
0:c7329ea5d8d5
Child:
1:5e7145bb2184

File content as of revision 0:c7329ea5d8d5:


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

Serial pc(USBTX,USBRX);

EthernetInterface eth;

// plotly account details
char PlotlyUsername[] =  "YoutUsername";
char PlotlyAPIToken[] = "YourAPIKey";
char streaming_token[] = "YourStreamToken";
char fileName[] = "Mbed Test Chart";

plotly graph = plotly(PlotlyUsername, PlotlyAPIToken, streaming_token, fileName);

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

}

// Generate a sample chart
void plotGenerateDataPoint()
{
    static  int counter = 0;
    float yValue = sin(counter*3.14159/180);
    graph.plot(counter, yValue);
    counter+=5;
}


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.closeStream();

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

    eth.disconnect();

    pc.printf("Done\n");

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