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

Dependencies:   mbed ThermistorPack Pachube EthernetNetIf

Files at this revision

API Documentation at this revision

Comitter:
shintamainjp
Date:
Wed Oct 13 21:58:32 2010 +0000
Child:
1:3c57da48fc0c
Commit message:
Hi. Mr.Jeff Mourich-san. Here is a test program for your case. Please try this :)

Changed in this revision

extlib/EthernetNetIf.lib Show annotated file Show diff for this revision Revisions of this file
extlib/HTTPClient.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
mylib/Pachube.lib Show annotated file Show diff for this revision Revisions of this file
mylib/ThermistorPack.lib Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/extlib/EthernetNetIf.lib	Wed Oct 13 21:58:32 2010 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/donatien/code/EthernetNetIf/#bc7df6da7589
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/extlib/HTTPClient.lib	Wed Oct 13 21:58:32 2010 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/donatien/code/HTTPClient/#d0be6af2d1db
--- /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);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Oct 13 21:58:32 2010 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/e2ac27c8e93e
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mylib/Pachube.lib	Wed Oct 13 21:58:32 2010 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/shintamainjp/code/Pachube/#19accbe9a05e
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mylib/ThermistorPack.lib	Wed Oct 13 21:58:32 2010 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/shintamainjp/code/ThermistorPack/#4f84f03b1703