API Reference

The full C++ API on the global Pulsync instance.

Initialization

void setWiFi(const char *ssid, const char *password = nullptr);
void setServer(const char *server);
void setVersion(const char *version);
bool begin(const char *pairing_code = nullptr);
void loop();

Call setWiFi, setServer, and setVersion before begin(). begin() returns false if NVS is unavailable.

Scheduler

uint16_t setInterval(std::function<void()> cb, uint32_t interval_ms);
uint16_t setTimeout(std::function<void()> cb, uint32_t delay_ms);
bool clearInterval(uint16_t id);
bool clearTimeout(uint16_t id);

Sending data

void send(const char *key, float value);
void send(const char *key, int value);
void send(const char *key, bool value);
void send(const char *key, const char *value);

// Grouped payload
void beginPayload();
void add(const char *key, float value);   // also int / bool / const char*
void endPayload();

Receiving commands

Typed handlers unwrap {"command":"name","payload":{"value":X}}:

void onInt(const char *command, std::function<void(int)> handler);
void onFloat(const char *command, std::function<void(float)> handler);
void onBool(const char *command, std::function<void(bool)> handler);
void onString(const char *command, std::function<void(const char *)> handler);
void on(const char *command, std::function<void()> handler);          // no value
void on(const char *command, std::function<void(Payload &)> handler); // full payload

Remote config

void onConfig(const char *key, std::function<void(int)> cb, int default_val = 0);
// also float / bool / const char* overloads

int   config(const char *key, int default_val);
float config(const char *key, float default_val);
bool  config(const char *key, bool default_val);

Configuration & status

void setHeartbeatInterval(uint32_t interval_ms);  // min 30s
void setResetPin(int pin);                        // hold 5s to factory reset

bool isConnected();
bool isWiFiConnected();
const char *getTransportName();
const char *getIP();
int queuedCount();
int queueCapacity();