Manage Connections
The library exposes one class per connection mode. The widget code in your sketch — the WHEN_* blocks, the instant.<widget>(...) method calls — is identical from one mode to the other. Only the #include and the constructor change.
Available modes
| Class | Mode | Use when |
|---|---|---|
InstantIoTWiFiAP | Direct Mode | Your phone connects directly to your Arduino. Single device, no router needed. |
InstantIoTWiFiServer | Server Mode | Your Arduino connects to your self-hosted InstantIoT Server via WiFi. Multiple devices, persistent state, history. |
Direct Mode — InstantIoTWiFiAP
Your Arduino broadcasts its own Wi-Fi network. Your phone joins it. The dashboard communicates with the sketch directly over that network — no router involved, no server in the middle.
#include <InstantIoTWiFiAP.hpp>
const char* AP_SSID = "InstantIoT-Greenhouse";
const char* AP_PASS = "12345678";
#define LED_PIN 2
InstantIoTWiFiAP instant(AP_SSID, AP_PASS);
ISimpleButton("btn1") {
WHEN_TOGGLED(isOn) {
digitalWrite(LED_PIN, isOn ? HIGH : LOW);
}
};
void setup() {
Serial.begin(115200);
pinMode(LED_PIN, OUTPUT);
instant.begin();
}
void loop() {
instant.loop();
}
| Method | What it does |
|---|---|
InstantIoTWiFiAP(SSID, PASS) | Creates the runtime. SSID is the Wi-Fi network name your Arduino broadcasts. |
begin() | Starts the access point and the protocol. |
loop() | Drives the protocol. Call it once per Arduino loop() iteration. |
connected() | Returns true when at least one phone is joined. |
getIP() | The Arduino’s IP on its own network (mostly informational). |
getSSID() | The broadcast network name. |
Use cases:
- Prototyping at your bench, no router involved.
- Standalone field setups (a greenhouse with no Wi-Fi nearby).
- Demos and workshops.
Server Mode — InstantIoTWiFiServer
Your Arduino joins your home Wi-Fi and connects to your self-hosted InstantIoT Server. The server holds project state, keeps history, and brokers multiple devices and phones at once.
#include <InstantIoTWiFiServer.hpp>
const char* WIFI_SSID = "YOUR_WIFI_SSID";
const char* WIFI_PASS = "YOUR_WIFI_PASSWORD";
const char* SERVER_IP = "192.168.1.42";
const uint16_t SERVER_PORT = 9001;
const char* DEVICE_TOKEN = "YOUR_DEVICE_TOKEN";
#define LED_PIN 2
InstantIoTWiFiServer instant(SERVER_IP, SERVER_PORT, DEVICE_TOKEN);
ISimpleButton("btn1") {
WHEN_TOGGLED(isOn) {
digitalWrite(LED_PIN, isOn ? HIGH : LOW);
}
};
void setup() {
Serial.begin(115200);
pinMode(LED_PIN, OUTPUT);
instant.setHeartbeat(1000);
instant.begin(WIFI_SSID, WIFI_PASS);
}
void loop() {
instant.loop();
}
| Method | What it does |
|---|---|
InstantIoTWiFiServer(IP, PORT, TOKEN) | Creates the runtime pointing at your server. The token comes from the server’s dashboard when you register the device. |
begin(SSID, PASS) | Connects to your Wi-Fi, then to the server. |
loop() | Drives the protocol. |
connected() | Returns true when authenticated with the server. |
getLocalIP() | The Arduino’s IP on your home Wi-Fi. |
setHeartbeat(uint32_t ms) | How often to ping the server. Default works for most setups; tune if your network is noisy. |
Use cases:
- Multiple devices in one project.
- You want history, persistence, multi-user access.
- Centralized management across devices in a home, a workshop, a greenhouse.
Comparison
| Direct Mode | Server Mode | |
|---|---|---|
| Setup | Arduino only | Arduino + Server |
| Network | Arduino’s own Wi-Fi | Your existing Wi-Fi |
| Devices per project | 1 | Many |
| State persistence | In RAM only | Server-side, survives reboots |
| History | No | Yes |
| Multi-user | No | Yes |
Coming soon
The library is structured to support more transports. Ethernet is on the roadmap — same widget code, different connection class. Existing sketches won’t change when those classes ship.
Next
→ Setup — Install the library and flash your first sketch.
→ Examples — Complete sketches in both modes.
→ Apps / Direct Mode and Apps / Server Mode — How the corresponding modes work in the app.