|
| 1 | +# SlicingDice Official Arduino Client (v1.0) |
| 2 | + |
| 3 | +Official Arduino client for [SlicingDice](http://www.slicingdice.com/), Data Warehouse and Analytics Database as a Service. |
| 4 | + |
| 5 | +## Documentation |
| 6 | + |
| 7 | +If you are new to SlicingDice, check our [quickstart guide](http://panel.slicingdice.com/docs/#quickstart-guide) and learn to use it in 15 minutes. |
| 8 | + |
| 9 | +Please refer to the [SlicingDice official documentation](http://panel.slicingdice.com/docs/) for more information on [analytics databases](http://panel.slicingdice.com/docs/#analytics-concepts), [data modeling](http://panel.slicingdice.com/docs/#data-modeling), [indexing](http://panel.slicingdice.com/docs/#data-indexing), [querying](http://panel.slicingdice.com/docs/#data-querying), [limitations](http://panel.slicingdice.com/docs/#current-slicingdice-limitations) and [API details](http://panel.slicingdice.com/docs/#api-details). |
| 10 | + |
| 11 | +## Installing |
| 12 | + |
| 13 | +[Click here]() to download our Arduino client as a `zip` file. After downloading it, you only need to import the zipped contents into your project path. |
| 14 | + |
| 15 | +## Usage |
| 16 | + |
| 17 | +```c |
| 18 | +#include <SlicingDice.h> |
| 19 | +#include <ArduinoJson.h> |
| 20 | + |
| 21 | +#define BUFFER_SIZE 256 |
| 22 | + |
| 23 | +SlicingDice sd = SlicingDice("API_KEY"); |
| 24 | + |
| 25 | +void setup() { |
| 26 | + // Open serial communication and wait for port to open |
| 27 | + Serial.begin(9600); |
| 28 | + while (!Serial) { |
| 29 | + } |
| 30 | + |
| 31 | + // Arduino network settings |
| 32 | + byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; |
| 33 | + byte ip[] = { 192, 168, 1, 10 }; |
| 34 | + byte gateway[] = { 192, 168, 1, 1 }; |
| 35 | + byte subnet[] = { 255, 255, 255, 0 }; |
| 36 | + byte dns[] = { 8, 8, 8, 8 }; |
| 37 | + Ethernet.begin(mac, ip, dns, gateway, subnet); |
| 38 | +} |
| 39 | + |
| 40 | +void loop() { |
| 41 | + // Create JSON object |
| 42 | + StaticJsonBuffer<BUFFER_SIZE> jsonBuffer; |
| 43 | + JsonObject& queryIndex = jsonBuffer.createObject(); |
| 44 | + JsonObject& nestedQueryIndex = queryIndex.createNestedObject("[email protected]"); |
| 45 | + nestedQueryIndex["age"] = 22; |
| 46 | + |
| 47 | + // Index object |
| 48 | + sd.index(queryIndex); |
| 49 | + |
| 50 | + // Print response for debugging |
| 51 | + Serial.print("Status code: "); |
| 52 | + Serial.println(sd.statusCode); |
| 53 | + Serial.println(sd.response); |
| 54 | +} |
| 55 | +``` |
| 56 | + |
| 57 | +## Tests and examples |
| 58 | + |
| 59 | +Whether you want to test the client installation or simply check more examples on how the client works, take a look at [tests directory](test/). |
| 60 | + |
| 61 | +## Reference |
| 62 | + |
| 63 | +`SlicingDice` encapsulates logic for sending requests to the [index endpoint](http://panel.slicingdice.com/docs/#api-details-api-endpoints-post-index). |
| 64 | + |
| 65 | +### Attributes |
| 66 | + |
| 67 | +* `statusCode (int)` - HTTP status code after indexing to SlicingDice. Should be `200` in ordinary circumstances or one of the HTTP requests defined at the [API errors](http://panel.slicingdice.com/docs/#api-details-api-errors) section. |
| 68 | +* `response (String)` - Response after indexing data. Useful for debugging purposes. |
| 69 | + |
| 70 | +### Constructors |
| 71 | + |
| 72 | +`SlicingDice(const char* apiKey)` |
| 73 | +* `apiKey (const char*)` - [API key](http://panel.slicingdice.com/docs/#api-details-api-connection-api-keys) to authenticate requests with the SlicingDice API. |
| 74 | + |
| 75 | +`SlicingDice(const char* apiKey, const char* host)` |
| 76 | +* `apiKey (const char*)` - [API key](http://panel.slicingdice.com/docs/#api-details-api-connection-api-keys) to authenticate requests with the SlicingDice API. |
| 77 | +* `host (const char*)` - [Connection endpoint](http://panel.slicingdice.com/docs/#api-details-api-connection-connection-endpoints) to use when generating requests to SlicingDice. |
| 78 | + |
| 79 | +`SlicingDice(const char* apiKey, const char* host, int port)` |
| 80 | +* `apiKey (const char*)` - [API key](http://panel.slicingdice.com/docs/#api-details-api-connection-api-keys) to authenticate requests with the SlicingDice API. |
| 81 | +* `host (const char*)` - [Connection endpoint](http://panel.slicingdice.com/docs/#api-details-api-connection-connection-endpoints) to use when generating requests to SlicingDice. |
| 82 | +* `port (int)` - Port to connect to when generating requests. Particularly useful when connect to `http://localhost`. |
| 83 | + |
| 84 | +### `void index(JsonObject& query)` |
| 85 | +Index data to existing entities or create new entities, if necessary. This method corresponds to a [POST request at /index](http://panel.slicingdice.com/docs/#api-details-api-endpoints-post-index). |
| 86 | + |
| 87 | +#### Request example |
| 88 | + |
| 89 | +```c |
| 90 | +#include <SlicingDice.h> |
| 91 | +#include <ArduinoJson.h> |
| 92 | + |
| 93 | +#define BUFFER_SIZE 256 |
| 94 | + |
| 95 | +SlicingDice sd = SlicingDice("API_KEY"); |
| 96 | + |
| 97 | +void setup() { |
| 98 | + // Open serial communication and wait for port to open |
| 99 | + Serial.begin(9600); |
| 100 | + while (!Serial) { |
| 101 | + } |
| 102 | + |
| 103 | + // Arduino network settings |
| 104 | + byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; |
| 105 | + byte ip[] = { 192, 168, 1, 10 }; |
| 106 | + byte gateway[] = { 192, 168, 1, 1 }; |
| 107 | + byte subnet[] = { 255, 255, 255, 0 }; |
| 108 | + byte dns[] = { 8, 8, 8, 8 }; |
| 109 | + Ethernet.begin(mac, ip, dns, gateway, subnet); |
| 110 | +} |
| 111 | + |
| 112 | +void loop() { |
| 113 | + // Create JSON object |
| 114 | + StaticJsonBuffer<BUFFER_SIZE> jsonBuffer; |
| 115 | + JsonObject& queryIndex = jsonBuffer.createObject(); |
| 116 | + JsonObject& nestedQueryIndex = queryIndex.createNestedObject("[email protected]"); |
| 117 | + nestedQueryIndex["age"] = 22; |
| 118 | + |
| 119 | + // Index object |
| 120 | + sd.index(queryIndex); |
| 121 | + |
| 122 | + // Print response for debugging |
| 123 | + Serial.print("Status code: "); |
| 124 | + Serial.println(sd.statusCode); |
| 125 | + Serial.println(sd.response); |
| 126 | +} |
| 127 | +``` |
| 128 | + |
| 129 | +#### Output example |
| 130 | + |
| 131 | +``` |
| 132 | +Status code: 200 |
| 133 | +{ |
| 134 | + "status": "success", |
| 135 | + "indexed-entities": 1, |
| 136 | + "indexed-fields": 1, |
| 137 | + "took": 0.023 |
| 138 | +} |
| 139 | +``` |
| 140 | + |
| 141 | +### `void index(JsonObject& query, boolean autoCreateFields)` |
| 142 | +Index data to existing entities or create new entities, if necessary. This method corresponds to a [POST request at /index](http://panel.slicingdice.com/docs/#api-details-api-endpoints-post-index). |
| 143 | + |
| 144 | +#### Request example |
| 145 | + |
| 146 | +```c |
| 147 | +#include <SlicingDice.h> |
| 148 | +#include <ArduinoJson.h> |
| 149 | + |
| 150 | +#define BUFFER_SIZE 256 |
| 151 | + |
| 152 | +SlicingDice sd = SlicingDice("API_KEY"); |
| 153 | + |
| 154 | +void setup() { |
| 155 | + // Open serial communication and wait for port to open |
| 156 | + Serial.begin(9600); |
| 157 | + while (!Serial) { |
| 158 | + } |
| 159 | + |
| 160 | + // Arduino network settings |
| 161 | + byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; |
| 162 | + byte ip[] = { 192, 168, 1, 10 }; |
| 163 | + byte gateway[] = { 192, 168, 1, 1 }; |
| 164 | + byte subnet[] = { 255, 255, 255, 0 }; |
| 165 | + byte dns[] = { 8, 8, 8, 8 }; |
| 166 | + Ethernet.begin(mac, ip, dns, gateway, subnet); |
| 167 | +} |
| 168 | + |
| 169 | +void loop() { |
| 170 | + // Create JSON object |
| 171 | + StaticJsonBuffer<BUFFER_SIZE> jsonBuffer; |
| 172 | + JsonObject& queryIndex = jsonBuffer.createObject(); |
| 173 | + JsonObject& nestedQueryIndex = queryIndex.createNestedObject("[email protected]"); |
| 174 | + nestedQueryIndex["age"] = 22; |
| 175 | + |
| 176 | + // Index object |
| 177 | + sd.index(queryIndex, true); |
| 178 | + |
| 179 | + // Print response for debugging |
| 180 | + Serial.print("Status code: "); |
| 181 | + Serial.println(sd.statusCode); |
| 182 | + Serial.println(sd.response); |
| 183 | +} |
| 184 | +``` |
| 185 | + |
| 186 | +#### Output example |
| 187 | + |
| 188 | +``` |
| 189 | +Status code: 200 |
| 190 | +{ |
| 191 | + "status": "success", |
| 192 | + "indexed-entities": 1, |
| 193 | + "indexed-fields": 1, |
| 194 | + "took": 0.023 |
| 195 | +} |
| 196 | +``` |
| 197 | + |
| 198 | +## License |
| 199 | + |
| 200 | +[MIT](https://opensource.org/licenses/MIT) |
0 commit comments