Plotly Cloud Dienst mit Sensorwerten

Dependencies:   EthernetInterface mbed-rtos mbed plotly

Fork of Plotly_HelloWorld by Andy A

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);
    }
}