An Arduino library for connecting your microcontroller to Deploii, an educational IoT platform developed by Company of Things
The first thing you want to do is import the library and create an instance of the Deploii class. Here you will need to provide your board ID from Deploii, as well as a medium and protocol. A list of all currently available mediums and protocols can be found here.
#include <deploii.h>
Deploii oi("Board ID", Medium::WiFi, Protocol::WebSockets);
In the setup function of the Arduino sketch, you need to call the connect function to connect to Deploii. The parameters of the connect function will vary based on your selected medium and protocol. For connection with Wifi and WebSockets this looks like:
void setup() {
oi.connect("WiFi SSID", "WiFi Password");
}
Now you can send data using the send function and providing a data stream ID and a variable containing your data. The send function works on all datatypes and arrays.
oi.send("Data stream ID", data);
If you want to do repeated tasks such as sending data at a set interval, you can use the interval function. You call the interval function in setup to register an interval. The function takes an interval specified in milliseconds and a function to be executed at that interval.
oi.interval(1000, myFunction);
For protocols that maintain a persistent connection, such as the WebSocket protocol or when using intervals, it is required that you call the Deploii loop function inside of the arduino void loop. You also cannot use delays or other blocking code when using these protocols as they might break the connection.
void loop(){
oi.loop();
}
For more examples of how to use the library, please see examples.
WiFi/WebSockets | WiFi/HTTP | |
---|---|---|
ESP32 | ✅ | ✅ |
Arduino WiFi | ❌ | ❌ |