|
1 | 1 | # CubeServer-api-arduino |
2 | 2 | [](https://codeclimate.com/github/snorklerjoe/CubeServer-api-arduino/maintainability) |
3 | 3 |
|
4 | | -An arduino-C implementation of the API wrapper for this project |
| 4 | +An arduino-C implementation of the API wrapper for CubeServer |
5 | 5 |
|
6 | | -This currently only supports ESP8266, and only sort of... |
7 | | -(In development!) |
| 6 | +_This currently only supports ESP8266 (It's in development!)_ |
| 7 | + |
| 8 | +---------------------------------------------------------------- |
| 9 | + |
| 10 | +## Example Sketches |
| 11 | +(client_config.h is downloaded from the CubeServer webapp): |
| 12 | + |
| 13 | +Bare minimum: |
| 14 | +``` C++ |
| 15 | +#include <Arduino.h> |
| 16 | +#include <server.h> |
| 17 | +#include "client_config.h" |
| 18 | + |
| 19 | +CubeServer server(TEAM_NAME, TEAM_SECRET, SERVER_FINGERPRINT); |
| 20 | + |
| 21 | +void setup() { |
| 22 | + server.connect(); |
| 23 | + server.postTemperature(32); |
| 24 | +} |
| 25 | + |
| 26 | +void loop() { |
| 27 | +} |
| 28 | + |
| 29 | +``` |
| 30 | +
|
| 31 | +Advanced features demonstrated: |
| 32 | +``` C++ |
| 33 | +#include <Arduino.h> |
| 34 | +#include <server.h> |
| 35 | +#include "client_config.h" |
| 36 | +
|
| 37 | +CubeServer server(TEAM_NAME, TEAM_SECRET, SERVER_FINGERPRINT); |
| 38 | +
|
| 39 | +int code; |
| 40 | +GameStatus stats; |
| 41 | +
|
| 42 | +bool connecting_loop() { |
| 43 | + delay(100); |
| 44 | + Serial.print("."); |
| 45 | + return true; |
| 46 | +} |
| 47 | +
|
| 48 | +void setup() { |
| 49 | + Serial.begin(115200); |
| 50 | + Serial.println("Connecting..."); |
| 51 | + code = server.connect(&connecting_loop); |
| 52 | + if(code >= 0) |
| 53 | + Serial.println("Connected!"); |
| 54 | + else |
| 55 | + Serial.println("Could not connect to the server."); |
| 56 | +
|
| 57 | + code = server.get_status(&stats); |
| 58 | + if(code == 200) |
| 59 | + Serial.printf("Time: %i; Score: %i; Strikes: %i;\n", stats.unix_time, stats.score, stats.strikes); |
| 60 | + else |
| 61 | + Serial.println("There was an issue connecting to the server."); |
| 62 | +
|
| 63 | +
|
| 64 | + Serial.println("Posting some data:"); |
| 65 | + code = server.postHumidity(99.99); |
| 66 | + //code = server.postTemperature(32); |
| 67 | + //code = server.postLightIntensity(12.5); |
| 68 | + //code = server.postPressure(25.2); |
| 69 | + //code = server.postComment("Hello World!"); |
| 70 | + if(code == 201) |
| 71 | + Serial.println("Data posted successfully!"); |
| 72 | + else |
| 73 | + Serial.println("There was a problem with posting the data."); |
| 74 | +} |
| 75 | +
|
| 76 | +void loop() { |
| 77 | +} |
| 78 | +``` |
0 commit comments