Examples

The library ships four examples (also under examples/ in the repo).

Basic scheduler

Non-blocking timers with no network:

#include <Pulsync.h>

void setup() {
  pinMode(2, OUTPUT);
  Pulsync.setInterval([]() {
    digitalWrite(2, !digitalRead(2));
  }, 500);
}

void loop() { Pulsync.loop(); }

Cloud send

Pulsync.setInterval([]() {
  Pulsync.beginPayload();
  Pulsync.add("temperature", (float)(analogRead(34) * 0.1f));
  Pulsync.add("humidity", (float)(analogRead(35) * 0.05f));
  Pulsync.endPayload();
}, 10000);

Receive commands

Pulsync.onBool("set_led", [](bool state) {
  digitalWrite(2, state ? HIGH : LOW);
});

reboot is built in since library 0.3.4. The device restarts from loop() about one second after the command. A sketch handler is optional and, if you register one, runs first.

Remote config

Pulsync.onConfig("readInterval", [](int value) {
  readIntervalMs = value;
}, 5000);

SoftAP + local HTTP (library 0.3.5+)

Hold SoftAP for a sketch server on a port other than 80. The config portal still uses port 80 when open and keeps priority for the SSID.

#include <WebServer.h>

WebServer server(8080);

void setup() {
  Pulsync.begin("PUL-A7K9X2");
  Pulsync.enableAP("MyDevice", "secret");  // open AP if password omitted
  server.on("/", []() { server.send(200, "text/plain", "ok"); });
  server.begin();
}

void loop() {
  Pulsync.loop();
  server.handleClient();
}