![](/media/cache/profiles/1006ff12c465532f8c574aeaa4461b16.50x50_q85.jpg)
A test program for Pachube library.
Dependencies: mbed ThermistorPack Pachube EthernetNetIf
main.cpp@2:2446c674625b, 2010-10-13 (annotated)
- Committer:
- shintamainjp
- Date:
- Wed Oct 13 10:50:23 2010 +0000
- Revision:
- 2:2446c674625b
- Parent:
- 1:d4f8908bf66f
First version.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
shintamainjp | 0:edeb42b3d357 | 1 | /** |
shintamainjp | 0:edeb42b3d357 | 2 | * A test program for Pachube API interface driver. (Version 0.0.1) |
shintamainjp | 0:edeb42b3d357 | 3 | * |
shintamainjp | 0:edeb42b3d357 | 4 | * Copyright (C) 2010 Shinichiro Nakamura (CuBeatSystems) |
shintamainjp | 0:edeb42b3d357 | 5 | * http://shinta.main.jp/ |
shintamainjp | 0:edeb42b3d357 | 6 | */ |
shintamainjp | 0:edeb42b3d357 | 7 | |
shintamainjp | 0:edeb42b3d357 | 8 | #include "mbed.h" |
shintamainjp | 0:edeb42b3d357 | 9 | #include "PachubeV2CSV.h" |
shintamainjp | 0:edeb42b3d357 | 10 | #include "EthernetNetIf.h" |
shintamainjp | 0:edeb42b3d357 | 11 | #include "HTTPClient.h" |
shintamainjp | 0:edeb42b3d357 | 12 | #include "ThermistorMCP9701.h" |
shintamainjp | 0:edeb42b3d357 | 13 | |
shintamainjp | 1:d4f8908bf66f | 14 | #define API_KEY "YourAPIKey" |
shintamainjp | 1:d4f8908bf66f | 15 | #define FEED_ID 99999 |
shintamainjp | 1:d4f8908bf66f | 16 | #define STREAM_ID "YourStreamID" |
shintamainjp | 1:d4f8908bf66f | 17 | |
shintamainjp | 1:d4f8908bf66f | 18 | PachubeV2CSV web(API_KEY); |
shintamainjp | 0:edeb42b3d357 | 19 | EthernetNetIf eth; |
shintamainjp | 0:edeb42b3d357 | 20 | ThermistorMCP9701 thermistor1(p16); |
shintamainjp | 0:edeb42b3d357 | 21 | |
shintamainjp | 2:2446c674625b | 22 | /** |
shintamainjp | 2:2446c674625b | 23 | * Example No.1 |
shintamainjp | 2:2446c674625b | 24 | */ |
shintamainjp | 2:2446c674625b | 25 | void example1(void) { |
shintamainjp | 0:edeb42b3d357 | 26 | int page = 1; |
shintamainjp | 0:edeb42b3d357 | 27 | int per_page = 10; |
shintamainjp | 0:edeb42b3d357 | 28 | std::string content = ""; |
shintamainjp | 0:edeb42b3d357 | 29 | std::string q = ""; |
shintamainjp | 0:edeb42b3d357 | 30 | std::string tag = ""; |
shintamainjp | 0:edeb42b3d357 | 31 | std::string user = ""; |
shintamainjp | 0:edeb42b3d357 | 32 | std::string units = ""; |
shintamainjp | 0:edeb42b3d357 | 33 | std::string status = ""; |
shintamainjp | 0:edeb42b3d357 | 34 | std::string order = ""; |
shintamainjp | 0:edeb42b3d357 | 35 | std::string datatext = ""; |
shintamainjp | 0:edeb42b3d357 | 36 | web.listAllAvailableFeeds( |
shintamainjp | 0:edeb42b3d357 | 37 | page, |
shintamainjp | 0:edeb42b3d357 | 38 | per_page, |
shintamainjp | 0:edeb42b3d357 | 39 | content, |
shintamainjp | 0:edeb42b3d357 | 40 | q, |
shintamainjp | 0:edeb42b3d357 | 41 | tag, |
shintamainjp | 0:edeb42b3d357 | 42 | user, |
shintamainjp | 0:edeb42b3d357 | 43 | units, |
shintamainjp | 0:edeb42b3d357 | 44 | status, |
shintamainjp | 0:edeb42b3d357 | 45 | order, |
shintamainjp | 0:edeb42b3d357 | 46 | datatext); |
shintamainjp | 0:edeb42b3d357 | 47 | printf("====Data====\n%s\n============\n", datatext.c_str()); |
shintamainjp | 0:edeb42b3d357 | 48 | } |
shintamainjp | 0:edeb42b3d357 | 49 | |
shintamainjp | 2:2446c674625b | 50 | /** |
shintamainjp | 2:2446c674625b | 51 | * Example No.2 |
shintamainjp | 2:2446c674625b | 52 | */ |
shintamainjp | 2:2446c674625b | 53 | void example2_loop(void) { |
shintamainjp | 1:d4f8908bf66f | 54 | const int feed_id = FEED_ID; |
shintamainjp | 1:d4f8908bf66f | 55 | const std::string stream_id = STREAM_ID; |
shintamainjp | 0:edeb42b3d357 | 56 | |
shintamainjp | 0:edeb42b3d357 | 57 | int cnt = 0; |
shintamainjp | 0:edeb42b3d357 | 58 | while (1) { |
shintamainjp | 0:edeb42b3d357 | 59 | double val1 = thermistor1.read(); |
shintamainjp | 0:edeb42b3d357 | 60 | char val1_text[32]; |
shintamainjp | 0:edeb42b3d357 | 61 | sprintf(val1_text, "%f", val1); |
shintamainjp | 0:edeb42b3d357 | 62 | if (cnt == 0) { |
shintamainjp | 0:edeb42b3d357 | 63 | printf("createNewDataStream(%d)\n", web.createNewDataStream(feed_id, stream_id, std::string(val1_text))); |
shintamainjp | 0:edeb42b3d357 | 64 | } else { |
shintamainjp | 0:edeb42b3d357 | 65 | printf("updateDataStream(%d)\n", web.updateDataStream(feed_id, stream_id, std::string(val1_text))); |
shintamainjp | 0:edeb42b3d357 | 66 | } |
shintamainjp | 0:edeb42b3d357 | 67 | cnt++; |
shintamainjp | 0:edeb42b3d357 | 68 | wait(10); |
shintamainjp | 0:edeb42b3d357 | 69 | } |
shintamainjp | 0:edeb42b3d357 | 70 | } |
shintamainjp | 0:edeb42b3d357 | 71 | |
shintamainjp | 2:2446c674625b | 72 | /** |
shintamainjp | 2:2446c674625b | 73 | * Entry point. |
shintamainjp | 2:2446c674625b | 74 | */ |
shintamainjp | 0:edeb42b3d357 | 75 | int main() { |
shintamainjp | 0:edeb42b3d357 | 76 | eth.setup(); |
shintamainjp | 0:edeb42b3d357 | 77 | |
shintamainjp | 0:edeb42b3d357 | 78 | example1(); |
shintamainjp | 0:edeb42b3d357 | 79 | example2_loop(); |
shintamainjp | 0:edeb42b3d357 | 80 | } |