This is a test program for my Pachube API driver classes.

Dependencies:   mbed ThermistorPack Pachube EthernetNetIf

Revision:
0:20bfb9085fda
Child:
1:3c57da48fc0c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Oct 13 21:58:32 2010 +0000
@@ -0,0 +1,96 @@
+/**
+ * A test program for Pachube API interface driver. (Version 0.0.1)
+ *
+ * Copyright (C) 2010 Shinichiro Nakamura (CuBeatSystems)
+ * http://shinta.main.jp/
+ */
+
+#include "mbed.h"
+#include "PachubeV2CSV.h"
+#include "EthernetNetIf.h"
+#include "HTTPClient.h"
+#include "ThermistorMCP9701.h"
+
+#define API_KEY "YourAPIKey"
+#define FEED_ID 99999
+#define STREAM_ID1 "TempNo.1"
+#define STREAM_ID2 "TempNo.2"
+#define STREAM_ID3 "TempNo.3"
+#define STREAM_ID4 "TempNo.4"
+#define STREAM_ID5 "TempNo.5"
+
+PachubeV2CSV web(API_KEY);
+EthernetNetIf eth;
+ThermistorMCP9701 thermistor1(p15);
+ThermistorMCP9701 thermistor2(p16);
+ThermistorMCP9701 thermistor3(p17);
+ThermistorMCP9701 thermistor4(p19);
+ThermistorMCP9701 thermistor5(p20);
+
+/**
+ * Convert double to char.
+ *
+ * @param val Value.
+ * @param buf A pointer to a buffer.
+ * @param bufsiz The buffer size.
+ */
+void convertDoubleToChar(double val, char *buf, size_t bufsiz) {
+    snprintf(buf, bufsiz, "%f", val);
+}
+
+/**
+ * Probe temperatures.
+ *
+ * @param SPM Sample Per Minutes.
+ */
+void probe_temperatures(const int SPM) {
+    int cnt = 0;
+    while (1) {
+        char val1[16];
+        char val2[16];
+        char val3[16];
+        char val4[16];
+        char val5[16];
+        convertDoubleToChar(thermistor1.read(), val1, sizeof(val1));
+        convertDoubleToChar(thermistor2.read(), val2, sizeof(val2));
+        convertDoubleToChar(thermistor3.read(), val3, sizeof(val3));
+        convertDoubleToChar(thermistor4.read(), val4, sizeof(val4));
+        convertDoubleToChar(thermistor5.read(), val5, sizeof(val5));
+        if (cnt == 0) {
+            printf("createNewDataStream(%d)\n", web.createNewDataStream(FEED_ID, STREAM_ID1, std::string(val1)));
+            printf("createNewDataStream(%d)\n", web.createNewDataStream(FEED_ID, STREAM_ID2, std::string(val2)));
+            printf("createNewDataStream(%d)\n", web.createNewDataStream(FEED_ID, STREAM_ID3, std::string(val3)));
+            printf("createNewDataStream(%d)\n", web.createNewDataStream(FEED_ID, STREAM_ID4, std::string(val4)));
+            printf("createNewDataStream(%d)\n", web.createNewDataStream(FEED_ID, STREAM_ID5, std::string(val5)));
+        } else {
+            printf("updateDataStream(%d)\n", web.updateDataStream(FEED_ID, STREAM_ID1, std::string(val1)));
+            printf("updateDataStream(%d)\n", web.updateDataStream(FEED_ID, STREAM_ID2, std::string(val2)));
+            printf("updateDataStream(%d)\n", web.updateDataStream(FEED_ID, STREAM_ID3, std::string(val3)));
+            printf("updateDataStream(%d)\n", web.updateDataStream(FEED_ID, STREAM_ID4, std::string(val4)));
+            printf("updateDataStream(%d)\n", web.updateDataStream(FEED_ID, STREAM_ID5, std::string(val5)));
+        }
+        cnt++;
+
+        /*
+         * This is not exactlly SPM[min.].
+         * But this is good for your starting points I think.
+         */
+        for (int i = 0; i < SPM; i++) {
+            /*
+             * Wait 60 seconds.
+             */
+            wait(60);
+            printf("%d[min.]\n", i + 1);
+        }
+    }
+}
+
+/**
+ * Entry point.
+ */
+int main() {
+    eth.setup();
+
+    const int SamplePerMinutes = 5;
+    probe_temperatures(SamplePerMinutes);
+}