![](/media/cache/profiles/DalekSelfie2.jpg.50x50_q85.jpg)
mbed based IoT Gateway More details http://blog.thiseldo.co.uk/wp-filez/IoTGateway.pdf
Dependencies: NetServices FatFileSystem csv_parser mbed MQTTClient RF12B DNSResolver SDFileSystem
Outputs/OutputEmonCms.h@4:d460406ac780, 2012-05-01 (annotated)
- Committer:
- SomeRandomBloke
- Date:
- Tue May 01 21:43:40 2012 +0000
- Revision:
- 4:d460406ac780
- Child:
- 5:0dbc27a7af55
Added output module for Sen.Se and emonCMS
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
SomeRandomBloke | 4:d460406ac780 | 1 | /** IoT Gateway Output definition for Open Energy Monitor emonCms |
SomeRandomBloke | 4:d460406ac780 | 2 | * |
SomeRandomBloke | 4:d460406ac780 | 3 | * @author Andrew Lindsay |
SomeRandomBloke | 4:d460406ac780 | 4 | * |
SomeRandomBloke | 4:d460406ac780 | 5 | * @section LICENSE |
SomeRandomBloke | 4:d460406ac780 | 6 | * |
SomeRandomBloke | 4:d460406ac780 | 7 | * Copyright (c) 2012 Andrew Lindsay (andrew [at] thiseldo [dot] co [dot] uk) |
SomeRandomBloke | 4:d460406ac780 | 8 | * |
SomeRandomBloke | 4:d460406ac780 | 9 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
SomeRandomBloke | 4:d460406ac780 | 10 | * of this software and associated documentation files (the "Software"), to deal |
SomeRandomBloke | 4:d460406ac780 | 11 | * in the Software without restriction, including without limitation the rights |
SomeRandomBloke | 4:d460406ac780 | 12 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
SomeRandomBloke | 4:d460406ac780 | 13 | * copies of the Software, and to permit persons to whom the Software is |
SomeRandomBloke | 4:d460406ac780 | 14 | * furnished to do so, subject to the following conditions: |
SomeRandomBloke | 4:d460406ac780 | 15 | |
SomeRandomBloke | 4:d460406ac780 | 16 | * The above copyright notice and this permission notice shall be included in |
SomeRandomBloke | 4:d460406ac780 | 17 | * all copies or substantial portions of the Software. |
SomeRandomBloke | 4:d460406ac780 | 18 | * |
SomeRandomBloke | 4:d460406ac780 | 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
SomeRandomBloke | 4:d460406ac780 | 20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
SomeRandomBloke | 4:d460406ac780 | 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
SomeRandomBloke | 4:d460406ac780 | 22 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
SomeRandomBloke | 4:d460406ac780 | 23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
SomeRandomBloke | 4:d460406ac780 | 24 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
SomeRandomBloke | 4:d460406ac780 | 25 | * THE SOFTWARE. |
SomeRandomBloke | 4:d460406ac780 | 26 | * |
SomeRandomBloke | 4:d460406ac780 | 27 | * @section DESCRIPTION |
SomeRandomBloke | 4:d460406ac780 | 28 | * |
SomeRandomBloke | 4:d460406ac780 | 29 | * |
SomeRandomBloke | 4:d460406ac780 | 30 | */ |
SomeRandomBloke | 4:d460406ac780 | 31 | |
SomeRandomBloke | 4:d460406ac780 | 32 | #ifndef _OUTPUTEMONCMS_H |
SomeRandomBloke | 4:d460406ac780 | 33 | #define _OUTPUTEMONCMS_H |
SomeRandomBloke | 4:d460406ac780 | 34 | |
SomeRandomBloke | 4:d460406ac780 | 35 | #include "mbed.h" |
SomeRandomBloke | 4:d460406ac780 | 36 | #include "HTTPClient.h" |
SomeRandomBloke | 4:d460406ac780 | 37 | #include "HTTPText.h" |
SomeRandomBloke | 4:d460406ac780 | 38 | |
SomeRandomBloke | 4:d460406ac780 | 39 | #define DATABUF_SIZE 128 |
SomeRandomBloke | 4:d460406ac780 | 40 | |
SomeRandomBloke | 4:d460406ac780 | 41 | #define EMONCMS_URL "http://api.pachube.com/v2/feeds/%d.csv?_method=PUT" |
SomeRandomBloke | 4:d460406ac780 | 42 | |
SomeRandomBloke | 4:d460406ac780 | 43 | /** Output definition class for sending readings to OpenEnergyMonitor emonCms |
SomeRandomBloke | 4:d460406ac780 | 44 | */ |
SomeRandomBloke | 4:d460406ac780 | 45 | class OutputEmonCms { |
SomeRandomBloke | 4:d460406ac780 | 46 | public: |
SomeRandomBloke | 4:d460406ac780 | 47 | /** Default Constructor |
SomeRandomBloke | 4:d460406ac780 | 48 | */ |
SomeRandomBloke | 4:d460406ac780 | 49 | OutputEmonCms(); |
SomeRandomBloke | 4:d460406ac780 | 50 | |
SomeRandomBloke | 4:d460406ac780 | 51 | /** Alternative Constructor |
SomeRandomBloke | 4:d460406ac780 | 52 | * |
SomeRandomBloke | 4:d460406ac780 | 53 | * @param internalBufferStart An internal buffer used to build up requests. |
SomeRandomBloke | 4:d460406ac780 | 54 | * @param url Pointer to API Url |
SomeRandomBloke | 4:d460406ac780 | 55 | * @param key Pointer to API key |
SomeRandomBloke | 4:d460406ac780 | 56 | */ |
SomeRandomBloke | 4:d460406ac780 | 57 | OutputEmonCms( char *internalBufferStart, char *url, char *key ); |
SomeRandomBloke | 4:d460406ac780 | 58 | |
SomeRandomBloke | 4:d460406ac780 | 59 | /** Set the API Key to use for sending readings to Pachube |
SomeRandomBloke | 4:d460406ac780 | 60 | * |
SomeRandomBloke | 4:d460406ac780 | 61 | * @param key Pointer to API key |
SomeRandomBloke | 4:d460406ac780 | 62 | */ |
SomeRandomBloke | 4:d460406ac780 | 63 | // void setApiKey( char *key ); |
SomeRandomBloke | 4:d460406ac780 | 64 | |
SomeRandomBloke | 4:d460406ac780 | 65 | /** Initialise output definition object |
SomeRandomBloke | 4:d460406ac780 | 66 | */ |
SomeRandomBloke | 4:d460406ac780 | 67 | virtual void init(); |
SomeRandomBloke | 4:d460406ac780 | 68 | |
SomeRandomBloke | 4:d460406ac780 | 69 | /** Add a character pointer reading to output |
SomeRandomBloke | 4:d460406ac780 | 70 | * |
SomeRandomBloke | 4:d460406ac780 | 71 | * @param dataFeed The feed to update |
SomeRandomBloke | 4:d460406ac780 | 72 | * @param dataStream The data stream within the feed to update or null if no feed |
SomeRandomBloke | 4:d460406ac780 | 73 | * @param reading The new value |
SomeRandomBloke | 4:d460406ac780 | 74 | */ |
SomeRandomBloke | 4:d460406ac780 | 75 | virtual void addReading(char *dataFeed, char *dataStream, char *reading ); |
SomeRandomBloke | 4:d460406ac780 | 76 | |
SomeRandomBloke | 4:d460406ac780 | 77 | /** Send any collected readings to the api |
SomeRandomBloke | 4:d460406ac780 | 78 | * |
SomeRandomBloke | 4:d460406ac780 | 79 | * @returns -1 for fail, 1 for success |
SomeRandomBloke | 4:d460406ac780 | 80 | */ |
SomeRandomBloke | 4:d460406ac780 | 81 | virtual int send(); |
SomeRandomBloke | 4:d460406ac780 | 82 | |
SomeRandomBloke | 4:d460406ac780 | 83 | protected: |
SomeRandomBloke | 4:d460406ac780 | 84 | int sendCount; |
SomeRandomBloke | 4:d460406ac780 | 85 | // OEM config |
SomeRandomBloke | 4:d460406ac780 | 86 | char *apiUrl; |
SomeRandomBloke | 4:d460406ac780 | 87 | char *apiKey; |
SomeRandomBloke | 4:d460406ac780 | 88 | char *dataBuffer; |
SomeRandomBloke | 4:d460406ac780 | 89 | char *dbufPtr; |
SomeRandomBloke | 4:d460406ac780 | 90 | bool hasData; |
SomeRandomBloke | 4:d460406ac780 | 91 | |
SomeRandomBloke | 4:d460406ac780 | 92 | }; |
SomeRandomBloke | 4:d460406ac780 | 93 | |
SomeRandomBloke | 4:d460406ac780 | 94 | #endif /* _OUTPUTEMONCMS_H */ |