GroveStreams is a helper class to assist with pushing data into the GroveStreams.com IoT platform.
GroveStreams.h@0:8b675b2726b7, 2017-01-05 (annotated)
- Committer:
- mmills
- Date:
- Thu Jan 05 18:39:43 2017 +0000
- Revision:
- 0:8b675b2726b7
Initial Revision.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mmills | 0:8b675b2726b7 | 1 | /* |
mmills | 0:8b675b2726b7 | 2 | GroveStreams is a helper class to assist with pushing data into the |
mmills | 0:8b675b2726b7 | 3 | GroveStreams.com IoT platform. |
mmills | 0:8b675b2726b7 | 4 | |
mmills | 0:8b675b2726b7 | 5 | License: |
mmills | 0:8b675b2726b7 | 6 | Copyright (C) 2017 GroveStreams LLC. |
mmills | 0:8b675b2726b7 | 7 | Licensed under the Apache License, Version 2.0 (the "License"); |
mmills | 0:8b675b2726b7 | 8 | you may not use this file except in compliance with the License. |
mmills | 0:8b675b2726b7 | 9 | You may obtain a copy of the License at: http://www.apache.org/licenses/LICENSE-2.0 |
mmills | 0:8b675b2726b7 | 10 | |
mmills | 0:8b675b2726b7 | 11 | Unless required by applicable law or agreed to in writing, software |
mmills | 0:8b675b2726b7 | 12 | distributed under the License is distributed on an "AS IS" BASIS, |
mmills | 0:8b675b2726b7 | 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
mmills | 0:8b675b2726b7 | 14 | See the License for the specific language governing permissions and |
mmills | 0:8b675b2726b7 | 15 | limitations under the License. |
mmills | 0:8b675b2726b7 | 16 | */ |
mmills | 0:8b675b2726b7 | 17 | |
mmills | 0:8b675b2726b7 | 18 | #ifndef GROVESTREAMS_H_ |
mmills | 0:8b675b2726b7 | 19 | #define GROVESTREAMS_H_ |
mmills | 0:8b675b2726b7 | 20 | |
mmills | 0:8b675b2726b7 | 21 | #include "mbed.h" |
mmills | 0:8b675b2726b7 | 22 | #include "EthernetInterface.h" |
mmills | 0:8b675b2726b7 | 23 | #include "NetworkAPI/tcp/socket.hpp" |
mmills | 0:8b675b2726b7 | 24 | #include "LcdDiscoF746NgTracer.h" |
mmills | 0:8b675b2726b7 | 25 | |
mmills | 0:8b675b2726b7 | 26 | class GroveStreams |
mmills | 0:8b675b2726b7 | 27 | { |
mmills | 0:8b675b2726b7 | 28 | |
mmills | 0:8b675b2726b7 | 29 | protected: |
mmills | 0:8b675b2726b7 | 30 | EthernetInterface _eth; |
mmills | 0:8b675b2726b7 | 31 | LcdDiscoF746NgTracer* _pLcd; |
mmills | 0:8b675b2726b7 | 32 | |
mmills | 0:8b675b2726b7 | 33 | const char* _domain; |
mmills | 0:8b675b2726b7 | 34 | uint16_t _port; |
mmills | 0:8b675b2726b7 | 35 | const char* _apiKey; |
mmills | 0:8b675b2726b7 | 36 | const char* _myIPAddress; //Don't Change. Set below from DHCP. Needed by GroveStreams to verify that a device is not uploading more than once every 10s. |
mmills | 0:8b675b2726b7 | 37 | |
mmills | 0:8b675b2726b7 | 38 | |
mmills | 0:8b675b2726b7 | 39 | public: |
mmills | 0:8b675b2726b7 | 40 | |
mmills | 0:8b675b2726b7 | 41 | /** Constructor with apiKey and Lcd tracer |
mmills | 0:8b675b2726b7 | 42 | * |
mmills | 0:8b675b2726b7 | 43 | * \param apiKey the secret api_key for your GroveStreams organization |
mmills | 0:8b675b2726b7 | 44 | * \param pLcd optional. Pass NULL or and LCD for tracing |
mmills | 0:8b675b2726b7 | 45 | */ |
mmills | 0:8b675b2726b7 | 46 | GroveStreams(const char* apiKey, LcdDiscoF746NgTracer* pLcd); |
mmills | 0:8b675b2726b7 | 47 | |
mmills | 0:8b675b2726b7 | 48 | /** Constructor with apiKey and Lcd tracer. |
mmills | 0:8b675b2726b7 | 49 | * |
mmills | 0:8b675b2726b7 | 50 | * \param apiKey the secret api_key for your GroveStreams organization |
mmills | 0:8b675b2726b7 | 51 | */ |
mmills | 0:8b675b2726b7 | 52 | GroveStreams(const char* apiKey); |
mmills | 0:8b675b2726b7 | 53 | |
mmills | 0:8b675b2726b7 | 54 | /** Destructor |
mmills | 0:8b675b2726b7 | 55 | * |
mmills | 0:8b675b2726b7 | 56 | */ |
mmills | 0:8b675b2726b7 | 57 | ~GroveStreams(); |
mmills | 0:8b675b2726b7 | 58 | |
mmills | 0:8b675b2726b7 | 59 | protected: |
mmills | 0:8b675b2726b7 | 60 | int init(const char* apiKey, LcdDiscoF746NgTracer* pLcd); |
mmills | 0:8b675b2726b7 | 61 | void printf(const char* format, ...); |
mmills | 0:8b675b2726b7 | 62 | |
mmills | 0:8b675b2726b7 | 63 | public: |
mmills | 0:8b675b2726b7 | 64 | |
mmills | 0:8b675b2726b7 | 65 | /** Send sample data to GroveStreams. Attempts to restore dropped ethernet |
mmills | 0:8b675b2726b7 | 66 | * connections |
mmills | 0:8b675b2726b7 | 67 | * |
mmills | 0:8b675b2726b7 | 68 | * \param componentId The ID of the component to put the samples into |
mmills | 0:8b675b2726b7 | 69 | * \param samples a string that is URL Encoded and contains all of the |
mmills | 0:8b675b2726b7 | 70 | * samples. Place an ampersand at the beggining of each sample substring. |
mmills | 0:8b675b2726b7 | 71 | * The substring is &streamId=value. |
mmills | 0:8b675b2726b7 | 72 | * Example: &temp=6&eres=78.231&on=true&position=on+ground |
mmills | 0:8b675b2726b7 | 73 | * \return 0 on success |
mmills | 0:8b675b2726b7 | 74 | */ |
mmills | 0:8b675b2726b7 | 75 | unsigned long send(const char* componentId, const char* samples); |
mmills | 0:8b675b2726b7 | 76 | |
mmills | 0:8b675b2726b7 | 77 | |
mmills | 0:8b675b2726b7 | 78 | /** Send sample data to GroveStreams. Attempts to restore dropped ethernet |
mmills | 0:8b675b2726b7 | 79 | * connections |
mmills | 0:8b675b2726b7 | 80 | * |
mmills | 0:8b675b2726b7 | 81 | * \param componentId The ID of the component to put the samples into |
mmills | 0:8b675b2726b7 | 82 | * \param samples a string that is URL Encoded and contains all of the |
mmills | 0:8b675b2726b7 | 83 | * samples. Place an ampersand at the beggining of each sample substring. |
mmills | 0:8b675b2726b7 | 84 | * The substring is &streamId=value. |
mmills | 0:8b675b2726b7 | 85 | * Example: &temp=6&eres=78.231&on=true&position=on+ground |
mmills | 0:8b675b2726b7 | 86 | * \param resultBuffer a string that will contain the http result body |
mmills | 0:8b675b2726b7 | 87 | * \param resultBufferSize the size of the result buffer |
mmills | 0:8b675b2726b7 | 88 | * \return 0 on success |
mmills | 0:8b675b2726b7 | 89 | */ |
mmills | 0:8b675b2726b7 | 90 | unsigned long send(const char* componentId, const char* samples, char* resultBuffer, size_t resultBufferSize); |
mmills | 0:8b675b2726b7 | 91 | |
mmills | 0:8b675b2726b7 | 92 | /** Send sample data to GroveStreams. Attempts to restore dropped ethernet |
mmills | 0:8b675b2726b7 | 93 | * connections |
mmills | 0:8b675b2726b7 | 94 | * |
mmills | 0:8b675b2726b7 | 95 | * \param componentId The ID of the component to put the samples into |
mmills | 0:8b675b2726b7 | 96 | * \param samples a string that is URL Encoded and contains all of the |
mmills | 0:8b675b2726b7 | 97 | * samples. Place an ampersand at the beggining of each sample substring. |
mmills | 0:8b675b2726b7 | 98 | * The substring is &streamId=value. |
mmills | 0:8b675b2726b7 | 99 | * Example: &temp=6&eres=78.231&on=true&position=on+ground |
mmills | 0:8b675b2726b7 | 100 | * \param componentName optional (NULL). the name assigned to a newly created component. |
mmills | 0:8b675b2726b7 | 101 | * \param compTmplId optional (NULL). the component template ID to be used for creating a |
mmills | 0:8b675b2726b7 | 102 | * new component |
mmills | 0:8b675b2726b7 | 103 | * \param resultBuffer a string that will contain the http result body |
mmills | 0:8b675b2726b7 | 104 | * \param resultBufferSize the size of the result buffer |
mmills | 0:8b675b2726b7 | 105 | * \return 0 on success |
mmills | 0:8b675b2726b7 | 106 | */ |
mmills | 0:8b675b2726b7 | 107 | unsigned long send(const char* componentId, const char* samples, const char* componentName, const char* compTmplId, char* resultBuffer, size_t resultBufferSize); |
mmills | 0:8b675b2726b7 | 108 | |
mmills | 0:8b675b2726b7 | 109 | /** Send sample data to GroveStreams. Does not attempt to restore dropped |
mmills | 0:8b675b2726b7 | 110 | * ethernet connections. |
mmills | 0:8b675b2726b7 | 111 | * |
mmills | 0:8b675b2726b7 | 112 | * \param componentId The ID of the component to put the samples into |
mmills | 0:8b675b2726b7 | 113 | * \param samples a string that is URL Encoded and contains all of the |
mmills | 0:8b675b2726b7 | 114 | * samples. Place an ampersand at the beggining of each sample substring. |
mmills | 0:8b675b2726b7 | 115 | * The substring is &streamId=value. |
mmills | 0:8b675b2726b7 | 116 | * Example: &temp=6&eres=78.231&on=true&position=on+ground |
mmills | 0:8b675b2726b7 | 117 | * \param componentName optional (NULL). the name assigned to a newly created component. |
mmills | 0:8b675b2726b7 | 118 | * \param compTmplId optional (NULL). the component template ID to be used for creating a |
mmills | 0:8b675b2726b7 | 119 | * new component |
mmills | 0:8b675b2726b7 | 120 | * \param resultBuffer a string that will contain the http result body |
mmills | 0:8b675b2726b7 | 121 | * \param resultBufferSize the size of the result buffer |
mmills | 0:8b675b2726b7 | 122 | * \return 0 on success |
mmills | 0:8b675b2726b7 | 123 | */ |
mmills | 0:8b675b2726b7 | 124 | unsigned long sendNoRetry(const char* componentId, const char* samples, const char* componentName, const char* compTmplId, char* resultBuffer, size_t resultBufferSize); |
mmills | 0:8b675b2726b7 | 125 | |
mmills | 0:8b675b2726b7 | 126 | /** Starts ethernet. |
mmills | 0:8b675b2726b7 | 127 | * Stops ethernet if it is running before starting it. |
mmills | 0:8b675b2726b7 | 128 | * \return 0 on success |
mmills | 0:8b675b2726b7 | 129 | */ |
mmills | 0:8b675b2726b7 | 130 | int startEthernet(); |
mmills | 0:8b675b2726b7 | 131 | |
mmills | 0:8b675b2726b7 | 132 | /** Get the MAC address of your Ethernet interface |
mmills | 0:8b675b2726b7 | 133 | * \return a pointer to a string containing the MAC address |
mmills | 0:8b675b2726b7 | 134 | */ |
mmills | 0:8b675b2726b7 | 135 | const char* getMACAddress(); |
mmills | 0:8b675b2726b7 | 136 | |
mmills | 0:8b675b2726b7 | 137 | }; |
mmills | 0:8b675b2726b7 | 138 | |
mmills | 0:8b675b2726b7 | 139 | #endif /* GROVESTREAMS_H_ */ |