-
Notifications
You must be signed in to change notification settings - Fork 0
Getting Started
Once this library is installed into the Arduino IDE (see the README for instructions), you have to include the library in your code to use it. That's as simple as adding the following line to the top of your Arduino sketch:
#include <server.h>
Before you can send data to the server, you have to initialize the connection.
(These instructions make the assumption that you downloaded the preconfigured library from the CubeServer web app.)
The next step is to create the server object. Because there is normally only one connection to the server at a time, it is best to make this a global variable. To create the server object in the recommended way (though there are other options better-suited to specific applications), put the following line outside of any functions (before the "void setup() {" line of the Arduino sketch):
CubeServer server;
In the setup() function, call the server.connect() method to initialize the connection to the server:
server.connect();
For more advanced users, this method returns a value based on the status of the connection (0 means success, other values are typically bad). Additionally, you can specify a pointer to a function to call in the loop of waiting to connect to the server. This function should return a boolean true under normal circumstances and return false if it is time to abort the connecting process or time-out.
Learn by Examples (temp, humidity, pressure, and light intensity may be integers or doubles):
// Post a temp of 32 degrees F:
server.postTemperature(32);
// Post a humidity of 73.0%:
server.postHumidity(73.0);
// Post a pressure of 25.3 inHg:
server.postPressure(25.3);
// Post a light intensity of 10034 lux:
server.postLightIntensity(10034);
// Post a comment that says, "Hello World!":
server.postComment("Hello World!");
An additional functionality is the ability to get the "status". As of this writing, status includes the current unix timestamp/epoch time and this team's current score and number of strikes:
GameStatus stats; // Make a variable to put the status in
int responseCode = server.get_status(&stats); // get the status
// responseCode should be 200 (HTTP OK), 400 or 401 indicates improper configuration,
// and a negative value typically indicates a problem with the server, although possibly an issue with configuration.
if(responseCode == 200) {
// Let's print the timestamp, score, and number of strikes:
Serial.printf("Time: %i; Score: %i; Strikes: %i;\n", stats.unix_time, stats.score, stats.strikes);
}