SinricPro Library
SinricProClass

The main class of this library, handling communication between SinricPro Server and your devices. More...

Inherits SinricProInterface.

Public Types

typedef std::function< void(void)> ConnectedCallbackHandler
 Callback definition for onConnected function. More...
 
typedef std::function< void(void)> DisconnectedCallbackHandler
 Callback definition for onDisconnected function. More...
 

Public Member Functions

void begin (AppKey socketAuthToken, AppSecret signingKey, String serverURL=SINRICPRO_SERVER_URL)
 Initializing SinricProClass to be able to connect to SinricPro Server. More...
 
void handle ()
 Handles communication between device and SinricPro Server. More...
 
void onConnected (ConnectedCallbackHandler cb)
 Set callback function for websocket connected event. More...
 
void onDisconnected (DisconnectedCallbackHandler cb)
 Set callback function for websocket disconnected event. More...
 
void restoreDeviceStates (bool flag)
 Enable / disable restore device states function. More...
 
proxy operator[] (const DeviceId deviceId)
 operator[] is used tor create a new device instance or get an existing device instance More...
 
unsigned long getTimestamp () override
 Get the current timestamp. More...
 

Detailed Description

The main class of this library, handling communication between SinricPro Server and your devices.

Member Typedef Documentation

◆ ConnectedCallbackHandler

typedef std::function<void(void)> ConnectedCallbackHandler

Callback definition for onConnected function.

Gets called when device is connected to SinricPro server

Parameters
void
Returns
void

◆ DisconnectedCallbackHandler

typedef std::function<void(void)> DisconnectedCallbackHandler

Callback definition for onDisconnected function.

Gets called when device is disconnected from SinricPro server

Parameters
void
Returns
void

Member Function Documentation

◆ begin()

void begin ( AppKey  socketAuthToken,
AppSecret  signingKey,
String  serverURL = SINRICPRO_SERVER_URL 
)

Initializing SinricProClass to be able to connect to SinricPro Server.

Parameters
socketAuthTokenString containing APP_KEY (see credentials from https://sinric.pro )
signingKeyString containing APP_SECRET (see credentials from https:://sinric.pro)
serverURLString containing SinricPro Server URL (default="ws.sinric.pro")

Example-Code

#define APP_KEY "YOUR-APP-KEY" // Should look like "de0bxxxx-1x3x-4x3x-ax2x-5dabxxxxxxxx"
#define APP_SECRET "YOUR-APP-SECRET" // Should look like "5f36xxxx-x3x7-4x3x-xexe-e86724a9xxxx-4c4axxxx-3x3x-x5xe-x9x3-333d65xxxxxx"
void setup() {
SinricPro.begin(APP_KEY, APP_SECRET);
}
The main instance of SinricProClass.

◆ getTimestamp()

unsigned long getTimestamp ( )
inlineoverride

Get the current timestamp.

Returns
unsigned long current timestamp (unix epoch time)

◆ handle()

void handle ( )

Handles communication between device and SinricPro Server.

This is the absolute main function which handles communication between your device and SinricPro Server.
It is responsible for connect, disconnect to SinricPro Server, handling requests, responses and events.
This function has to be called as often as possible. So it must be called in your main loop() function!
For proper function, begin() must be called with valid values for 'APP_KEY' and 'APP_SECRET'

Example-Code

void loop() {
SinricPro.handle();
}

◆ onConnected()

void onConnected ( ConnectedCallbackHandler  cb)

Set callback function for websocket connected event.

Parameters
cbFunction pointer to a ConnectedCallbackHandler function
Returns
void
See also
ConnectedCallbackHandler

Example-Code

SinricPro.onConnected([](){ Serial.printf("Connected to SinricPro\r\n"); });

◆ onDisconnected()

void onDisconnected ( DisconnectedCallbackHandler  cb)

Set callback function for websocket disconnected event.

Parameters
cbFunction pointer to a DisconnectedCallbackHandler function
Returns
void
See also
DisconnectedCallbackHandler

Example-Code

SinricPro.onDisconnected([](){ Serial.printf("Disconnected from SinricPro\r\n"); });

◆ operator[]()

proxy operator[] ( const DeviceId  deviceId)
inline

operator[] is used tor create a new device instance or get an existing device instance

If the device is unknown to SinricProClass it will create a new device instance

Parameters
deviceIda String containing deviceId for device that have to been created or retreived
Returns
returns a proxy object representing the reference to a device derrivered from SinricProDevice

Syntax

<DeviceType> &reference = SinricPro[<DEVICE_ID>];

[] Example-Code

#define SWITCH_ID "YOUR-DEVICE-ID" // Should look like "5dc1564130xxxxxxxxxxxxxx"
..
SinricProSwitch &mySwitch = SinricPro[SWITCH_ID];
..
Device suporting basic on / off command.
Definition: SinricProSwitch.h:20

◆ restoreDeviceStates()

void restoreDeviceStates ( bool  flag)

Enable / disable restore device states function.

If this flag is enabled (true), SinricProServer will send last known device states to your device directly after connection to SinricPro server has been established.
For every state the corresponding callback (like onPowerState) will be called
This is useful after a power failure / reboot of your device.

Parameters
flagtrue = enabled
false= disabled