diff --git a/Doxyfile b/Doxyfile index 6be05bb..8dc7ff1 100644 --- a/Doxyfile +++ b/Doxyfile @@ -829,7 +829,8 @@ WARN_LOGFILE = # spaces. See also FILE_PATTERNS and EXTENSION_MAPPING # Note: If this tag is empty the current directory is searched. -INPUT = C:\Users\Boris\.platformio\lib\esp8266-esp32-sdk\src +INPUT = C:\Users\Boris\.platformio\lib\esp8266-esp32-sdk\src \ + README.md # This tag can be used to specify the character encoding of the source files # that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses diff --git a/README.md b/README.md index 6d05730..b938e48 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,13 @@ # SinricPro (ESP8266 / ESP32 SDK) -## Version 2.2.6 +## Version 2.2.7 ## Installation ### VS Code & PlatformIO: 1. Install [VS Code](https://code.visualstudio.com/) 2. Install [PlatformIO](https://platformio.org/platformio-ide) 3. Install **SinricPro** library by using [Library Manager](https://docs.platformio.org/en/latest/librarymanager/) -4. Use included [platformio.ini](https://github.com/sinricpro/esp8266-esp32-sdk/blob/master/pio-examples/switch/platformio.ini) files from [examples](https://github.com/sinricpro/esp8266-esp32-sdk/tree/master/pio-examples) to ensure that all dependent libraries will installed automaticly. +4. Use included [platformio.ini](examples/platformio/platformio.ini) file from examples to ensure that all dependent libraries will installed automaticly. ![sinricpro library manager](https://raw.githubusercontent.com/sinricpro/images/master/platformio-install-sinricpro.png) @@ -28,13 +28,7 @@ --- ## Examples -|PlatformIO|Arduino| -|:--:|:--:| -| [Switch](https://github.com/sinricpro/esp8266-esp32-sdk/tree/master/pio-examples/switch) |[Switch](https://github.com/sinricpro/esp8266-esp32-sdk/tree/master/examples/Switch)| -| [Doorbell](https://github.com/sinricpro/esp8266-esp32-sdk/tree/master/pio-examples/doorbell)|[Doorbell](https://github.com/sinricpro/esp8266-esp32-sdk/tree/master/examples/doorbell)| -| - | [Lock](https://github.com/sinricpro/esp8266-esp32-sdk/tree/master/examples/GarageDoor)| -| [TemperatureSensor](https://github.com/sinricpro/esp8266-esp32-sdk/tree/master/pio-examples/temperaturesensor) |[TemperatureSensor](https://github.com/sinricpro/esp8266-esp32-sdk/tree/master/examples/temperaturesensor)| -| [TV](https://github.com/sinricpro/esp8266-esp32-sdk/tree/master/pio-examples/tv) | [TV](https://github.com/sinricpro/esp8266-esp32-sdk/tree/master/examples/tv) +See [examples](https://github.com/sinricpro/esp8266-esp32-sdk/tree/master/examples) on GitHub --- @@ -127,5 +121,5 @@ Example 1 --- # Full user documentation -Please see full user documentation here https://sinricpro.github.io/esp8266-esp32-sdk +Please see here for [full user documentation](https://sinricpro.github.io/esp8266-esp32-sdk) diff --git a/changelog.md b/changelog.md index bc50e78..9bad4d5 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,21 @@ # Changelog +## Version 2.2.7 + +New: +- Examples + - Dimmable Switch + - Light + - Speaker + +Updated: +- User documentation + - added SinricPro.onConnected() / SinricPro.onDisconnected() + +Fixed: +- Examples + - Some examples didn't use BAUD_RATE + ## Version 2.2.6 New: diff --git a/doc-examples/callbacks.cpp b/doc-examples/callbacks.cpp index 6ae4ee9..9870ec6 100644 --- a/doc-examples/callbacks.cpp +++ b/doc-examples/callbacks.cpp @@ -367,4 +367,12 @@ bool onSelectInput(const String &deviceId, String &input) { Serial.printf("Device %s input changed to %s\r\n", deviceId.c_str(), input.c_str()); return true; } -//! [onSelectInput] \ No newline at end of file +//! [onSelectInput] + +//! [onConnected] + SinricPro.onConnected([](){ Serial.printf("Connected to SinricPro\r\n"); }); +//! [onConnected] + +//! [onDisconnected] + SinricPro.onDisconnected([](){ Serial.printf("Disconnected from SinricPro\r\n"); }); +//! [onDisconnected] diff --git a/docs/_sinric_pro_8h_source.html b/docs/_sinric_pro_8h_source.html index 87d3dbe..e3e5125 100644 --- a/docs/_sinric_pro_8h_source.html +++ b/docs/_sinric_pro_8h_source.html @@ -136,442 +136,446 @@
32  void stop();
33  bool isConnected();
34 
-
35  typedef std::function<void(void)> ConnectCallbackHandler;
-
36  void onConnected(ConnectCallbackHandler cb);
-
37  void onDisconnected(ConnectCallbackHandler cb);
-
38 
-
39  void restoreDeviceStates(bool flag);
-
40 
-
41  DynamicJsonDocument prepareResponse(JsonDocument& requestMessage);
-
42  DynamicJsonDocument prepareEvent(const char* deviceId, const char* action, const char* cause) override;
-
43  void sendMessage(JsonDocument& jsonMessage) override;
-
44 
-
45  struct proxy {
-
46  proxy(SinricProClass* ptr, String deviceId) : ptr(ptr), deviceId(deviceId) {}
-
47  SinricProClass* ptr;
-
48  String deviceId;
-
49  template <typename DeviceType>
-
50  operator DeviceType&() { return as<DeviceType>(); }
-
51  template <typename DeviceType>
-
52  DeviceType& as() { return ptr->getDeviceInstance<DeviceType>(deviceId); }
-
53  };
-
70  proxy operator[](const String deviceId) { return proxy(this, deviceId); }
-
71 
-
72  // setResponseMessage is is just a workaround until verison 3.x.x will be released
-
73  void setResponseMessage(String &&message) { responseMessageStr = message; }
-
74 
-
75  private:
-
76  void handleReceiveQueue();
-
77  void handleSendQueue();
-
78 
-
79  void handleRequest(DynamicJsonDocument& requestMessage, interface_t Interface);
-
80  void handleResponse(DynamicJsonDocument& responseMessage);
-
81 
-
82  DynamicJsonDocument prepareRequest(const char* deviceId, const char* action);
-
83 
-
84  void connect();
-
85  void disconnect();
-
86  void reconnect();
-
87 
-
88  void onConnect() { DEBUG_SINRIC("[SinricPro]: Connected to \"%s\"!]\r\n", serverURL.c_str()); }
-
89  void onDisconnect() { DEBUG_SINRIC("[SinricPro]: Disconnect\r\n"); }
-
90 
-
91  bool verifyDeviceId(const char* id);
-
92  bool verifyAppKey(const char* key);
-
93  bool verifyAppSecret(const char* secret);
-
94  void extractTimestamp(JsonDocument &message);
-
95 
-
96  SinricProDeviceInterface* getDevice(String deviceId);
-
97 
-
98  template <typename DeviceType>
-
99  DeviceType& getDeviceInstance(String deviceId);
-
100 
-
101  std::vector<SinricProDeviceInterface*> devices;
-
102  String socketAuthToken;
-
103  String signingKey;
-
104  String serverURL;
+
42  typedef std::function<void(void)> ConnectedCallbackHandler;
+
50  typedef std::function<void(void)> DisconnectedCallbackHandler;
+
51  void onConnected(ConnectedCallbackHandler cb);
+
52  void onDisconnected(DisconnectedCallbackHandler cb);
+
53 
+
54  void restoreDeviceStates(bool flag);
+
55 
+
56  DynamicJsonDocument prepareResponse(JsonDocument& requestMessage);
+
57  DynamicJsonDocument prepareEvent(const char* deviceId, const char* action, const char* cause) override;
+
58  void sendMessage(JsonDocument& jsonMessage) override;
+
59 
+
60  struct proxy {
+
61  proxy(SinricProClass* ptr, String deviceId) : ptr(ptr), deviceId(deviceId) {}
+
62  SinricProClass* ptr;
+
63  String deviceId;
+
64  template <typename DeviceType>
+
65  operator DeviceType&() { return as<DeviceType>(); }
+
66  template <typename DeviceType>
+
67  DeviceType& as() { return ptr->getDeviceInstance<DeviceType>(deviceId); }
+
68  };
+
85  proxy operator[](const String deviceId) { return proxy(this, deviceId); }
+
86 
+
87  // setResponseMessage is is just a workaround until verison 3.x.x will be released
+
88  void setResponseMessage(String &&message) { responseMessageStr = message; }
+
89 
+
90  private:
+
91  void handleReceiveQueue();
+
92  void handleSendQueue();
+
93 
+
94  void handleRequest(DynamicJsonDocument& requestMessage, interface_t Interface);
+
95  void handleResponse(DynamicJsonDocument& responseMessage);
+
96 
+
97  DynamicJsonDocument prepareRequest(const char* deviceId, const char* action);
+
98 
+
99  void connect();
+
100  void disconnect();
+
101  void reconnect();
+
102 
+
103  void onConnect() { DEBUG_SINRIC("[SinricPro]: Connected to \"%s\"!]\r\n", serverURL.c_str()); }
+
104  void onDisconnect() { DEBUG_SINRIC("[SinricPro]: Disconnect\r\n"); }
105 
-
106  websocketListener _websocketListener;
-
107  udpListener _udpListener;
-
108  SinricProQueue_t receiveQueue;
-
109  SinricProQueue_t sendQueue;
+
106  bool verifyDeviceId(const char* id);
+
107  bool verifyAppKey(const char* key);
+
108  bool verifyAppSecret(const char* secret);
+
109  void extractTimestamp(JsonDocument &message);
110 
-
111  unsigned long getTimestamp() { return baseTimestamp + (millis()/1000); }
-
112  unsigned long baseTimestamp = 0;
-
113 
-
114  bool _begin = false;
-
115  String responseMessageStr = "";
-
116 };
-
117 
-
118 SinricProDeviceInterface* SinricProClass::getDevice(String deviceId) {
-
119  for (auto& device : devices) {
-
120  if (deviceId == String(device->getDeviceId())) return device;
-
121  }
-
122  return nullptr;
-
123 }
-
124 
-
125 template <typename DeviceType>
-
126 DeviceType& SinricProClass::getDeviceInstance(String deviceId) {
-
127  DeviceType* tmp_device = (DeviceType*) getDevice(deviceId);
-
128  if (tmp_device) return *tmp_device;
-
129 
-
130  DEBUG_SINRIC("[SinricPro]: Device \"%s\" does not exist. Creating new device\r\n", deviceId.c_str());
-
131  DeviceType& tmp_deviceInstance = add<DeviceType>(deviceId.c_str());
+
111  SinricProDeviceInterface* getDevice(String deviceId);
+
112 
+
113  template <typename DeviceType>
+
114  DeviceType& getDeviceInstance(String deviceId);
+
115 
+
116  std::vector<SinricProDeviceInterface*> devices;
+
117  String socketAuthToken;
+
118  String signingKey;
+
119  String serverURL;
+
120 
+
121  websocketListener _websocketListener;
+
122  udpListener _udpListener;
+
123  SinricProQueue_t receiveQueue;
+
124  SinricProQueue_t sendQueue;
+
125 
+
126  unsigned long getTimestamp() { return baseTimestamp + (millis()/1000); }
+
127  unsigned long baseTimestamp = 0;
+
128 
+
129  bool _begin = false;
+
130  String responseMessageStr = "";
+
131 };
132 
-
133  if (isConnected()) {
-
134  DEBUG_SINRIC("[SinricPro]: Reconnecting to server.\r\n");
-
135  reconnect();
+
133 SinricProDeviceInterface* SinricProClass::getDevice(String deviceId) {
+
134  for (auto& device : devices) {
+
135  if (deviceId == String(device->getDeviceId())) return device;
136  }
-
137 
-
138  return tmp_deviceInstance;
-
139 }
-
140 
-
157 void SinricProClass::begin(String socketAuthToken, String signingKey, String serverURL) {
-
158  bool success = true;
-
159  if (!verifyAppKey(socketAuthToken.c_str())) {
-
160  DEBUG_SINRIC("[SinricPro:begin()]: App-Key \"%s\" is invalid!! Please check your app-key!! SinricPro will not work!\r\n", socketAuthToken.c_str());
-
161  success = false;
-
162  }
-
163  if (!verifyAppSecret(signingKey.c_str())) {
-
164  DEBUG_SINRIC("[SinricPro:begin()]: App-Secret \"%s\" is invalid!! Please check your app-secret!! SinricPro will not work!\r\n", signingKey.c_str());
-
165  success = false;
-
166  return;
-
167  }
-
168 
-
169  if(!success) {
-
170  _begin = false;
-
171  return;
-
172  }
-
173 
-
174  this->socketAuthToken = socketAuthToken;
-
175  this->signingKey = signingKey;
-
176  this->serverURL = serverURL;
-
177  _begin = true;
-
178  _udpListener.begin(&receiveQueue);
-
179 }
-
180 
-
181 template <typename DeviceType>
-
182 DeviceType& SinricProClass::add(const char* deviceId, unsigned long eventWaitTime) {
-
183  DeviceType* newDevice = new DeviceType(deviceId, eventWaitTime);
-
184  if (verifyDeviceId(deviceId)){
-
185  DEBUG_SINRIC("[SinricPro:add()]: Adding device with id \"%s\".\r\n", deviceId);
-
186  newDevice->begin(this);
-
187  if (verifyAppKey(socketAuthToken.c_str()) && verifyAppSecret(signingKey.c_str())) _begin = true;
-
188  } else {
-
189  DEBUG_SINRIC("[SinricPro:add()]: DeviceId \"%s\" is invalid!! Device will be ignored and will NOT WORK!\r\n", deviceId);
-
190  }
-
191  devices.push_back(newDevice);
-
192  return *newDevice;
-
193 }
-
194 
-
195 __attribute__ ((deprecated("Please use DeviceType& myDevice = SinricPro.add<DeviceType>(DeviceId);")))
-
196 void SinricProClass::add(SinricProDeviceInterface* newDevice) {
-
197  if (!verifyDeviceId(newDevice->getDeviceId())) return;
-
198  newDevice->begin(this);
-
199  devices.push_back(newDevice);
-
200 }
-
201 
-
202 __attribute__ ((deprecated("Please use DeviceType& myDevice = SinricPro.add<DeviceType>(DeviceId);")))
-
203 void SinricProClass::add(SinricProDeviceInterface& newDevice) {
-
204  if (!verifyDeviceId(newDevice.getDeviceId())) return;
-
205  newDevice.begin(this);
-
206  devices.push_back(&newDevice);
-
207 }
-
208 
-
224 void SinricProClass::handle() {
-
225  static bool begin_error = false;
-
226  if (!_begin) {
-
227  if (!begin_error) { // print this only once!
-
228  DEBUG_SINRIC("[SinricPro:handle()]: ERROR! SinricPro.begin() failed or was not called prior to event handler\r\n");
-
229  DEBUG_SINRIC("[SinricPro:handle()]: -Reasons include an invalid app-key, invalid app-secret or no valid deviceIds)\r\n");
-
230  DEBUG_SINRIC("[SinricPro:handle()]: -SinricPro is disabled! Check earlier log messages for details.\r\n");
-
231  begin_error = true;
-
232  }
-
233  return;
-
234  }
-
235 
-
236 
-
237  if (!isConnected()) connect();
-
238  _websocketListener.handle();
-
239  _udpListener.handle();
-
240 
-
241  handleReceiveQueue();
-
242  handleSendQueue();
-
243 }
-
244 
-
245 DynamicJsonDocument SinricProClass::prepareRequest(const char* deviceId, const char* action) {
-
246  DynamicJsonDocument requestMessage(1024);
-
247  JsonObject header = requestMessage.createNestedObject("header");
-
248  header["payloadVersion"] = 2;
-
249  header["signatureVersion"] = 1;
+
137  return nullptr;
+
138 }
+
139 
+
140 template <typename DeviceType>
+
141 DeviceType& SinricProClass::getDeviceInstance(String deviceId) {
+
142  DeviceType* tmp_device = (DeviceType*) getDevice(deviceId);
+
143  if (tmp_device) return *tmp_device;
+
144 
+
145  DEBUG_SINRIC("[SinricPro]: Device \"%s\" does not exist. Creating new device\r\n", deviceId.c_str());
+
146  DeviceType& tmp_deviceInstance = add<DeviceType>(deviceId.c_str());
+
147 
+
148  if (isConnected()) {
+
149  DEBUG_SINRIC("[SinricPro]: Reconnecting to server.\r\n");
+
150  reconnect();
+
151  }
+
152 
+
153  return tmp_deviceInstance;
+
154 }
+
155 
+
172 void SinricProClass::begin(String socketAuthToken, String signingKey, String serverURL) {
+
173  bool success = true;
+
174  if (!verifyAppKey(socketAuthToken.c_str())) {
+
175  DEBUG_SINRIC("[SinricPro:begin()]: App-Key \"%s\" is invalid!! Please check your app-key!! SinricPro will not work!\r\n", socketAuthToken.c_str());
+
176  success = false;
+
177  }
+
178  if (!verifyAppSecret(signingKey.c_str())) {
+
179  DEBUG_SINRIC("[SinricPro:begin()]: App-Secret \"%s\" is invalid!! Please check your app-secret!! SinricPro will not work!\r\n", signingKey.c_str());
+
180  success = false;
+
181  return;
+
182  }
+
183 
+
184  if(!success) {
+
185  _begin = false;
+
186  return;
+
187  }
+
188 
+
189  this->socketAuthToken = socketAuthToken;
+
190  this->signingKey = signingKey;
+
191  this->serverURL = serverURL;
+
192  _begin = true;
+
193  _udpListener.begin(&receiveQueue);
+
194 }
+
195 
+
196 template <typename DeviceType>
+
197 DeviceType& SinricProClass::add(const char* deviceId, unsigned long eventWaitTime) {
+
198  DeviceType* newDevice = new DeviceType(deviceId, eventWaitTime);
+
199  if (verifyDeviceId(deviceId)){
+
200  DEBUG_SINRIC("[SinricPro:add()]: Adding device with id \"%s\".\r\n", deviceId);
+
201  newDevice->begin(this);
+
202  if (verifyAppKey(socketAuthToken.c_str()) && verifyAppSecret(signingKey.c_str())) _begin = true;
+
203  } else {
+
204  DEBUG_SINRIC("[SinricPro:add()]: DeviceId \"%s\" is invalid!! Device will be ignored and will NOT WORK!\r\n", deviceId);
+
205  }
+
206  devices.push_back(newDevice);
+
207  return *newDevice;
+
208 }
+
209 
+
210 __attribute__ ((deprecated("Please use DeviceType& myDevice = SinricPro.add<DeviceType>(DeviceId);")))
+
211 void SinricProClass::add(SinricProDeviceInterface* newDevice) {
+
212  if (!verifyDeviceId(newDevice->getDeviceId())) return;
+
213  newDevice->begin(this);
+
214  devices.push_back(newDevice);
+
215 }
+
216 
+
217 __attribute__ ((deprecated("Please use DeviceType& myDevice = SinricPro.add<DeviceType>(DeviceId);")))
+
218 void SinricProClass::add(SinricProDeviceInterface& newDevice) {
+
219  if (!verifyDeviceId(newDevice.getDeviceId())) return;
+
220  newDevice.begin(this);
+
221  devices.push_back(&newDevice);
+
222 }
+
223 
+
239 void SinricProClass::handle() {
+
240  static bool begin_error = false;
+
241  if (!_begin) {
+
242  if (!begin_error) { // print this only once!
+
243  DEBUG_SINRIC("[SinricPro:handle()]: ERROR! SinricPro.begin() failed or was not called prior to event handler\r\n");
+
244  DEBUG_SINRIC("[SinricPro:handle()]: -Reasons include an invalid app-key, invalid app-secret or no valid deviceIds)\r\n");
+
245  DEBUG_SINRIC("[SinricPro:handle()]: -SinricPro is disabled! Check earlier log messages for details.\r\n");
+
246  begin_error = true;
+
247  }
+
248  return;
+
249  }
250 
-
251  JsonObject payload = requestMessage.createNestedObject("payload");
-
252  payload["action"] = action;
-
253  payload["createdAt"] = 0;
-
254  payload["deviceId"] = deviceId;
-
255  payload["replyToken"] = MessageID().getID();
-
256  payload["type"] = "request";
-
257  payload.createNestedObject("value");
-
258  return requestMessage;
-
259 }
-
260 
-
261 void SinricProClass::handleResponse(DynamicJsonDocument& responseMessage) {
-
262  DEBUG_SINRIC("[SinricPro.handleResponse()]:\r\n");
-
263 
-
264  #ifndef NODEBUG_SINRIC
-
265  serializeJsonPretty(responseMessage, DEBUG_ESP_PORT);
-
266  Serial.println();
-
267  #endif
-
268 }
-
269 
-
270 void SinricProClass::handleRequest(DynamicJsonDocument& requestMessage, interface_t Interface) {
-
271  DEBUG_SINRIC("[SinricPro.handleRequest()]: handling request\r\n");
-
272  #ifndef NODEBUG_SINRIC
-
273  serializeJsonPretty(requestMessage, DEBUG_ESP_PORT);
-
274  #endif
+
251 
+
252  if (!isConnected()) connect();
+
253  _websocketListener.handle();
+
254  _udpListener.handle();
+
255 
+
256  handleReceiveQueue();
+
257  handleSendQueue();
+
258 }
+
259 
+
260 DynamicJsonDocument SinricProClass::prepareRequest(const char* deviceId, const char* action) {
+
261  DynamicJsonDocument requestMessage(1024);
+
262  JsonObject header = requestMessage.createNestedObject("header");
+
263  header["payloadVersion"] = 2;
+
264  header["signatureVersion"] = 1;
+
265 
+
266  JsonObject payload = requestMessage.createNestedObject("payload");
+
267  payload["action"] = action;
+
268  payload["createdAt"] = 0;
+
269  payload["deviceId"] = deviceId;
+
270  payload["replyToken"] = MessageID().getID();
+
271  payload["type"] = "request";
+
272  payload.createNestedObject("value");
+
273  return requestMessage;
+
274 }
275 
-
276  DynamicJsonDocument responseMessage = prepareResponse(requestMessage);
-
277 
-
278  // handle devices
-
279  bool success = false;
-
280  const char* deviceId = requestMessage["payload"]["deviceId"];
-
281  const char* action = requestMessage["payload"]["action"];
-
282  JsonObject request_value = requestMessage["payload"]["value"];
-
283  JsonObject response_value = responseMessage["payload"]["value"];
+
276 void SinricProClass::handleResponse(DynamicJsonDocument& responseMessage) {
+
277  DEBUG_SINRIC("[SinricPro.handleResponse()]:\r\n");
+
278 
+
279  #ifndef NODEBUG_SINRIC
+
280  serializeJsonPretty(responseMessage, DEBUG_ESP_PORT);
+
281  Serial.println();
+
282  #endif
+
283 }
284 
-
285  for (auto& device : devices) {
-
286  if (strcmp(deviceId, device->getDeviceId()) == 0 && success == false) {
-
287  success = device->handleRequest(deviceId, action, request_value, response_value);
-
288  responseMessage["payload"]["success"] = success;
-
289  if (!success) {
-
290  if (responseMessageStr.length() > 0){
-
291  responseMessage["payload"]["message"] = responseMessageStr;
-
292  responseMessageStr = "";
-
293  } else {
-
294  responseMessage["payload"]["message"] = "Device returned an error while processing the request!";
-
295  }
-
296  }
-
297  }
-
298  }
+
285 void SinricProClass::handleRequest(DynamicJsonDocument& requestMessage, interface_t Interface) {
+
286  DEBUG_SINRIC("[SinricPro.handleRequest()]: handling request\r\n");
+
287  #ifndef NODEBUG_SINRIC
+
288  serializeJsonPretty(requestMessage, DEBUG_ESP_PORT);
+
289  #endif
+
290 
+
291  DynamicJsonDocument responseMessage = prepareResponse(requestMessage);
+
292 
+
293  // handle devices
+
294  bool success = false;
+
295  const char* deviceId = requestMessage["payload"]["deviceId"];
+
296  const char* action = requestMessage["payload"]["action"];
+
297  JsonObject request_value = requestMessage["payload"]["value"];
+
298  JsonObject response_value = responseMessage["payload"]["value"];
299 
-
300  String responseString;
-
301  serializeJson(responseMessage, responseString);
-
302  sendQueue.push(new SinricProMessage(Interface, responseString.c_str()));
-
303 }
-
304 
-
305 void SinricProClass::handleReceiveQueue() {
-
306  if (receiveQueue.count() == 0) return;
-
307 
-
308  DEBUG_SINRIC("[SinricPro.handleReceiveQueue()]: %i message(s) in receiveQueue\r\n", receiveQueue.count());
-
309  while (receiveQueue.count() > 0) {
-
310  SinricProMessage* rawMessage = receiveQueue.pop();
-
311  DynamicJsonDocument jsonMessage(1024);
-
312  deserializeJson(jsonMessage, rawMessage->getMessage());
-
313 
-
314  bool sigMatch = false;
-
315 
-
316  if (strncmp(rawMessage->getMessage(), "{\"timestamp\":", 13) == 0 && strlen(rawMessage->getMessage()) <= 26) {
-
317  sigMatch=true; // timestamp message has no signature...ignore sigMatch for this!
-
318  } else {
-
319  sigMatch = verifyMessage(signingKey, jsonMessage);
-
320  }
-
321 
-
322  String messageType = jsonMessage["payload"]["type"];
-
323 
-
324  if (sigMatch) { // signature is valid process message
-
325  DEBUG_SINRIC("[SinricPro.handleReceiveQueue()]: Signature is valid. Processing message...\r\n");
-
326  extractTimestamp(jsonMessage);
-
327  if (messageType == "response") handleResponse(jsonMessage);
-
328  if (messageType == "request") handleRequest(jsonMessage, rawMessage->getInterface());
-
329  } else {
-
330  DEBUG_SINRIC("[SinricPro.handleReceiveQueue()]: Signature is invalid! Sending messsage to [dev/null] ;)\r\n");
-
331  }
-
332  delete rawMessage;
-
333  }
-
334 }
-
335 
-
336 void SinricProClass::handleSendQueue() {
-
337  if (!isConnected()) return;
-
338  if (!baseTimestamp) return;
-
339  while (sendQueue.count() > 0) {
-
340  DEBUG_SINRIC("[SinricPro:handleSendQueue()]: %i message(s) in sendQueue\r\n", sendQueue.count());
-
341  DEBUG_SINRIC("[SinricPro:handleSendQueue()]: Sending message...\r\n");
-
342 
-
343  SinricProMessage* rawMessage = sendQueue.pop();
-
344 
-
345  DynamicJsonDocument jsonMessage(1024);
-
346  deserializeJson(jsonMessage, rawMessage->getMessage());
-
347  jsonMessage["payload"]["createdAt"] = getTimestamp();
-
348  signMessage(signingKey, jsonMessage);
-
349 
-
350  String messageStr;
-
351 
-
352  serializeJson(jsonMessage, messageStr);
-
353  #ifndef NODEBUG_SINRIC
-
354  serializeJsonPretty(jsonMessage, DEBUG_ESP_PORT);
-
355  Serial.println();
-
356  #endif
+
300  for (auto& device : devices) {
+
301  if (strcmp(deviceId, device->getDeviceId()) == 0 && success == false) {
+
302  success = device->handleRequest(deviceId, action, request_value, response_value);
+
303  responseMessage["payload"]["success"] = success;
+
304  if (!success) {
+
305  if (responseMessageStr.length() > 0){
+
306  responseMessage["payload"]["message"] = responseMessageStr;
+
307  responseMessageStr = "";
+
308  } else {
+
309  responseMessage["payload"]["message"] = "Device returned an error while processing the request!";
+
310  }
+
311  }
+
312  }
+
313  }
+
314 
+
315  String responseString;
+
316  serializeJson(responseMessage, responseString);
+
317  sendQueue.push(new SinricProMessage(Interface, responseString.c_str()));
+
318 }
+
319 
+
320 void SinricProClass::handleReceiveQueue() {
+
321  if (receiveQueue.count() == 0) return;
+
322 
+
323  DEBUG_SINRIC("[SinricPro.handleReceiveQueue()]: %i message(s) in receiveQueue\r\n", receiveQueue.count());
+
324  while (receiveQueue.count() > 0) {
+
325  SinricProMessage* rawMessage = receiveQueue.pop();
+
326  DynamicJsonDocument jsonMessage(1024);
+
327  deserializeJson(jsonMessage, rawMessage->getMessage());
+
328 
+
329  bool sigMatch = false;
+
330 
+
331  if (strncmp(rawMessage->getMessage(), "{\"timestamp\":", 13) == 0 && strlen(rawMessage->getMessage()) <= 26) {
+
332  sigMatch=true; // timestamp message has no signature...ignore sigMatch for this!
+
333  } else {
+
334  sigMatch = verifyMessage(signingKey, jsonMessage);
+
335  }
+
336 
+
337  String messageType = jsonMessage["payload"]["type"];
+
338 
+
339  if (sigMatch) { // signature is valid process message
+
340  DEBUG_SINRIC("[SinricPro.handleReceiveQueue()]: Signature is valid. Processing message...\r\n");
+
341  extractTimestamp(jsonMessage);
+
342  if (messageType == "response") handleResponse(jsonMessage);
+
343  if (messageType == "request") handleRequest(jsonMessage, rawMessage->getInterface());
+
344  } else {
+
345  DEBUG_SINRIC("[SinricPro.handleReceiveQueue()]: Signature is invalid! Sending messsage to [dev/null] ;)\r\n");
+
346  }
+
347  delete rawMessage;
+
348  }
+
349 }
+
350 
+
351 void SinricProClass::handleSendQueue() {
+
352  if (!isConnected()) return;
+
353  if (!baseTimestamp) return;
+
354  while (sendQueue.count() > 0) {
+
355  DEBUG_SINRIC("[SinricPro:handleSendQueue()]: %i message(s) in sendQueue\r\n", sendQueue.count());
+
356  DEBUG_SINRIC("[SinricPro:handleSendQueue()]: Sending message...\r\n");
357 
-
358  switch (rawMessage->getInterface()) {
-
359  case IF_WEBSOCKET: DEBUG_SINRIC("[SinricPro:handleSendQueue]: Sending to websocket\r\n"); _websocketListener.sendMessage(messageStr); break;
-
360  case IF_UDP: DEBUG_SINRIC("[SinricPro:handleSendQueue]: Sending to UDP\r\n");_udpListener.sendMessage(messageStr); break;
-
361  default: break;
-
362  }
-
363  delete rawMessage;
-
364  DEBUG_SINRIC("[SinricPro:handleSendQueue()]: message sent.\r\n");
-
365  }
-
366 }
-
367 
-
368 void SinricProClass::connect() {
-
369  String deviceList;
-
370  int i = 0;
-
371  for (auto& device : devices) {
-
372  const char* deviceId = device->getDeviceId();
-
373  if (verifyDeviceId(deviceId)) {
-
374  if (i>0) deviceList += ';';
-
375  deviceList += String(deviceId);
-
376  i++;
+
358  SinricProMessage* rawMessage = sendQueue.pop();
+
359 
+
360  DynamicJsonDocument jsonMessage(1024);
+
361  deserializeJson(jsonMessage, rawMessage->getMessage());
+
362  jsonMessage["payload"]["createdAt"] = getTimestamp();
+
363  signMessage(signingKey, jsonMessage);
+
364 
+
365  String messageStr;
+
366 
+
367  serializeJson(jsonMessage, messageStr);
+
368  #ifndef NODEBUG_SINRIC
+
369  serializeJsonPretty(jsonMessage, DEBUG_ESP_PORT);
+
370  Serial.println();
+
371  #endif
+
372 
+
373  switch (rawMessage->getInterface()) {
+
374  case IF_WEBSOCKET: DEBUG_SINRIC("[SinricPro:handleSendQueue]: Sending to websocket\r\n"); _websocketListener.sendMessage(messageStr); break;
+
375  case IF_UDP: DEBUG_SINRIC("[SinricPro:handleSendQueue]: Sending to UDP\r\n");_udpListener.sendMessage(messageStr); break;
+
376  default: break;
377  }
-
378  }
-
379  if (i==0) { // no device have been added! -> do not connect!
-
380  _begin = false;
-
381  DEBUG_SINRIC("[SinricPro]: ERROR! No valid devices available. Please add a valid device first!\r\n");
-
382  return;
-
383  }
-
384 
-
385  _websocketListener.begin(serverURL, socketAuthToken, deviceList, &receiveQueue);
-
386 }
-
387 
-
388 
-
389 void SinricProClass::stop() {
-
390  DEBUG_SINRIC("[SinricPro:stop()\r\n");
-
391  _websocketListener.stop();
-
392 }
-
393 
-
394 bool SinricProClass::isConnected() {
-
395  return _websocketListener.isConnected();
-
396 };
-
397 
-
398 
-
399 void SinricProClass::onConnected(ConnectCallbackHandler cb) {
-
400  _websocketListener.onConnected(cb);
+
378  delete rawMessage;
+
379  DEBUG_SINRIC("[SinricPro:handleSendQueue()]: message sent.\r\n");
+
380  }
+
381 }
+
382 
+
383 void SinricProClass::connect() {
+
384  String deviceList;
+
385  int i = 0;
+
386  for (auto& device : devices) {
+
387  const char* deviceId = device->getDeviceId();
+
388  if (verifyDeviceId(deviceId)) {
+
389  if (i>0) deviceList += ';';
+
390  deviceList += String(deviceId);
+
391  i++;
+
392  }
+
393  }
+
394  if (i==0) { // no device have been added! -> do not connect!
+
395  _begin = false;
+
396  DEBUG_SINRIC("[SinricPro]: ERROR! No valid devices available. Please add a valid device first!\r\n");
+
397  return;
+
398  }
+
399 
+
400  _websocketListener.begin(serverURL, socketAuthToken, deviceList, &receiveQueue);
401 }
402 
-
403 void SinricProClass::onDisconnected(ConnectCallbackHandler cb) {
-
404  _websocketListener.onDisconnected(cb);
-
405 }
-
406 
-
407 
-
408 void SinricProClass::reconnect() {
-
409  DEBUG_SINRIC("SinricPro:reconnect(): disconnecting\r\n");
-
410  stop();
-
411  DEBUG_SINRIC("SinricPro:reconnect(): connecting\r\n");
-
412  connect();
-
413 }
-
414 
-
415 bool SinricProClass::verifyDeviceId(const char* id) {
-
416  if (strlen(id) != 24) return false;
-
417  int tmp; char tmp_c;
-
418  return sscanf(id, "%4x%4x%4x%4x%4x%4x%c",
-
419  &tmp, &tmp, &tmp, &tmp, &tmp, &tmp, &tmp_c) == 6;
-
420 }
-
421 
-
422 bool SinricProClass::verifyAppKey(const char* key) {
-
423  if (strlen(key) != 36) return false;
-
424  int tmp; char tmp_c;
-
425  return sscanf(key, "%4x%4x-%4x-%4x-%4x-%4x%4x%4x%c",
-
426  &tmp, &tmp, &tmp, &tmp, &tmp, &tmp, &tmp, &tmp, &tmp_c) == 8;
-
427 }
-
428 
-
429 bool SinricProClass::verifyAppSecret(const char* secret) {
-
430  if (strlen(secret) != 73) return false;
-
431  int tmp; char tmp_c;
-
432  return sscanf(secret, "%4x%4x-%4x-%4x-%4x-%4x%4x%4x-%4x%4x-%4x-%4x-%4x-%4x%4x%4x%c",
-
433  &tmp, &tmp, &tmp, &tmp, &tmp, &tmp, &tmp, &tmp, &tmp, &tmp, &tmp, &tmp, &tmp, &tmp, &tmp, &tmp, &tmp_c) == 16;
-
434 }
-
435 
-
436 
-
437 void SinricProClass::extractTimestamp(JsonDocument &message) {
-
438  unsigned long tempTimestamp = 0;
-
439  // extract timestamp from timestamp message right after websocket connection is established
-
440  tempTimestamp = message["timestamp"] | 0;
-
441  if (tempTimestamp) {
-
442  baseTimestamp = tempTimestamp - (millis() / 1000);
-
443  DEBUG_SINRIC("[SinricPro:extractTimestamp(): Got Timestamp %lu\r\n", tempTimestamp);
-
444  return;
-
445  }
+
403 
+
404 void SinricProClass::stop() {
+
405  DEBUG_SINRIC("[SinricPro:stop()\r\n");
+
406  _websocketListener.stop();
+
407 }
+
408 
+
409 bool SinricProClass::isConnected() {
+
410  return _websocketListener.isConnected();
+
411 };
+
412 
+
422 void SinricProClass::onConnected(ConnectedCallbackHandler cb) {
+
423  _websocketListener.onConnected(cb);
+
424 }
+
425 
+
435 void SinricProClass::onDisconnected(DisconnectedCallbackHandler cb) {
+
436  _websocketListener.onDisconnected(cb);
+
437 }
+
438 
+
439 
+
440 void SinricProClass::reconnect() {
+
441  DEBUG_SINRIC("SinricPro:reconnect(): disconnecting\r\n");
+
442  stop();
+
443  DEBUG_SINRIC("SinricPro:reconnect(): connecting\r\n");
+
444  connect();
+
445 }
446 
-
447  // extract timestamp from request message
-
448  tempTimestamp = message["payload"]["createdAt"] | 0;
-
449  if (tempTimestamp) {
-
450  DEBUG_SINRIC("[SinricPro:extractTimestamp(): Got Timestamp %lu\r\n", tempTimestamp);
-
451  baseTimestamp = tempTimestamp - (millis() / 1000);
-
452  return;
-
453  }
-
454 }
-
455 
-
456 
-
457 void SinricProClass::sendMessage(JsonDocument& jsonMessage) {
-
458  DEBUG_SINRIC("[SinricPro:sendMessage()]: pushing message into sendQueue\r\n");
-
459  String messageString;
-
460  serializeJson(jsonMessage, messageString);
-
461  sendQueue.push(new SinricProMessage(IF_WEBSOCKET, messageString.c_str()));
-
462 }
-
463 
-
473 void SinricProClass::restoreDeviceStates(bool flag) {
-
474  _websocketListener.setRestoreDeviceStates(flag);
-
475 }
-
476 
-
477 DynamicJsonDocument SinricProClass::prepareResponse(JsonDocument& requestMessage) {
-
478  DynamicJsonDocument responseMessage(1024);
-
479  JsonObject header = responseMessage.createNestedObject("header");
-
480  header["payloadVersion"] = 2;
-
481  header["signatureVersion"] = 1;
-
482 
-
483  JsonObject payload = responseMessage.createNestedObject("payload");
-
484  payload["action"] = requestMessage["payload"]["action"];
-
485  payload["clientId"] = requestMessage["payload"]["clientId"];
-
486  payload["createdAt"] = 0;
-
487  payload["deviceId"] = requestMessage["payload"]["deviceId"];
-
488  payload["message"] = "OK";
-
489  payload["replyToken"] = requestMessage["payload"]["replyToken"];
-
490  payload["success"] = false;
-
491  payload["type"] = "response";
-
492  payload.createNestedObject("value");
-
493  return responseMessage;
+
447 bool SinricProClass::verifyDeviceId(const char* id) {
+
448  if (strlen(id) != 24) return false;
+
449  int tmp; char tmp_c;
+
450  return sscanf(id, "%4x%4x%4x%4x%4x%4x%c",
+
451  &tmp, &tmp, &tmp, &tmp, &tmp, &tmp, &tmp_c) == 6;
+
452 }
+
453 
+
454 bool SinricProClass::verifyAppKey(const char* key) {
+
455  if (strlen(key) != 36) return false;
+
456  int tmp; char tmp_c;
+
457  return sscanf(key, "%4x%4x-%4x-%4x-%4x-%4x%4x%4x%c",
+
458  &tmp, &tmp, &tmp, &tmp, &tmp, &tmp, &tmp, &tmp, &tmp_c) == 8;
+
459 }
+
460 
+
461 bool SinricProClass::verifyAppSecret(const char* secret) {
+
462  if (strlen(secret) != 73) return false;
+
463  int tmp; char tmp_c;
+
464  return sscanf(secret, "%4x%4x-%4x-%4x-%4x-%4x%4x%4x-%4x%4x-%4x-%4x-%4x-%4x%4x%4x%c",
+
465  &tmp, &tmp, &tmp, &tmp, &tmp, &tmp, &tmp, &tmp, &tmp, &tmp, &tmp, &tmp, &tmp, &tmp, &tmp, &tmp, &tmp_c) == 16;
+
466 }
+
467 
+
468 
+
469 void SinricProClass::extractTimestamp(JsonDocument &message) {
+
470  unsigned long tempTimestamp = 0;
+
471  // extract timestamp from timestamp message right after websocket connection is established
+
472  tempTimestamp = message["timestamp"] | 0;
+
473  if (tempTimestamp) {
+
474  baseTimestamp = tempTimestamp - (millis() / 1000);
+
475  DEBUG_SINRIC("[SinricPro:extractTimestamp(): Got Timestamp %lu\r\n", tempTimestamp);
+
476  return;
+
477  }
+
478 
+
479  // extract timestamp from request message
+
480  tempTimestamp = message["payload"]["createdAt"] | 0;
+
481  if (tempTimestamp) {
+
482  DEBUG_SINRIC("[SinricPro:extractTimestamp(): Got Timestamp %lu\r\n", tempTimestamp);
+
483  baseTimestamp = tempTimestamp - (millis() / 1000);
+
484  return;
+
485  }
+
486 }
+
487 
+
488 
+
489 void SinricProClass::sendMessage(JsonDocument& jsonMessage) {
+
490  DEBUG_SINRIC("[SinricPro:sendMessage()]: pushing message into sendQueue\r\n");
+
491  String messageString;
+
492  serializeJson(jsonMessage, messageString);
+
493  sendQueue.push(new SinricProMessage(IF_WEBSOCKET, messageString.c_str()));
494 }
495 
-
496 
-
497 DynamicJsonDocument SinricProClass::prepareEvent(const char* deviceId, const char* action, const char* cause) {
-
498  DynamicJsonDocument eventMessage(1024);
-
499  JsonObject header = eventMessage.createNestedObject("header");
-
500  header["payloadVersion"] = 2;
-
501  header["signatureVersion"] = 1;
-
502 
-
503  JsonObject payload = eventMessage.createNestedObject("payload");
-
504  payload["action"] = action;
-
505  payload["cause"].createNestedObject("type");
-
506  payload["cause"]["type"] = cause;
-
507  payload["createdAt"] = 0;
-
508  payload["deviceId"] = deviceId;
-
509  payload["replyToken"] = MessageID().getID();
-
510  payload["type"] = "event";
-
511  payload.createNestedObject("value");
-
512  return eventMessage;
-
513 }
+
505 void SinricProClass::restoreDeviceStates(bool flag) {
+
506  _websocketListener.setRestoreDeviceStates(flag);
+
507 }
+
508 
+
509 DynamicJsonDocument SinricProClass::prepareResponse(JsonDocument& requestMessage) {
+
510  DynamicJsonDocument responseMessage(1024);
+
511  JsonObject header = responseMessage.createNestedObject("header");
+
512  header["payloadVersion"] = 2;
+
513  header["signatureVersion"] = 1;
514 
-
515 #ifndef NOSINRIC_INSTANCE
-
516 
-
523 SinricProClass SinricPro;
-
524 #endif
-
525 
-
526 #endif
+
515  JsonObject payload = responseMessage.createNestedObject("payload");
+
516  payload["action"] = requestMessage["payload"]["action"];
+
517  payload["clientId"] = requestMessage["payload"]["clientId"];
+
518  payload["createdAt"] = 0;
+
519  payload["deviceId"] = requestMessage["payload"]["deviceId"];
+
520  payload["message"] = "OK";
+
521  payload["replyToken"] = requestMessage["payload"]["replyToken"];
+
522  payload["success"] = false;
+
523  payload["type"] = "response";
+
524  payload.createNestedObject("value");
+
525  return responseMessage;
+
526 }
+
527 
+
528 
+
529 DynamicJsonDocument SinricProClass::prepareEvent(const char* deviceId, const char* action, const char* cause) {
+
530  DynamicJsonDocument eventMessage(1024);
+
531  JsonObject header = eventMessage.createNestedObject("header");
+
532  header["payloadVersion"] = 2;
+
533  header["signatureVersion"] = 1;
+
534 
+
535  JsonObject payload = eventMessage.createNestedObject("payload");
+
536  payload["action"] = action;
+
537  payload["cause"].createNestedObject("type");
+
538  payload["cause"]["type"] = cause;
+
539  payload["createdAt"] = 0;
+
540  payload["deviceId"] = deviceId;
+
541  payload["replyToken"] = MessageID().getID();
+
542  payload["type"] = "event";
+
543  payload.createNestedObject("value");
+
544  return eventMessage;
+
545 }
+
546 
+
547 #ifndef NOSINRIC_INSTANCE
+
548 
+
555 SinricProClass SinricPro;
+
556 #endif
+
557 
+
558 #endif
-
SinricProClass::handle
void handle()
Handles communication between device and SinricPro Server.
Definition: SinricPro.h:224
-
SinricProClass::restoreDeviceStates
void restoreDeviceStates(bool flag)
Enable / disable restore device states function.
Definition: SinricPro.h:473
-
SinricProClass::operator[]
proxy operator[](const String deviceId)
operator[] is used tor create a new device instance or get an existing device instance
Definition: SinricPro.h:70
-
SinricProClass::begin
void begin(String socketAuthToken, String signingKey, String serverURL=SINRICPRO_SERVER_URL)
Initializing SinricProClass to be able to connect to SinricPro Server.
Definition: SinricPro.h:157
+
SinricProClass::onConnected
void onConnected(ConnectedCallbackHandler cb)
Set callback function for websocket connected event.
Definition: SinricPro.h:422
+
SinricProClass::handle
void handle()
Handles communication between device and SinricPro Server.
Definition: SinricPro.h:239
+
SinricProClass::onDisconnected
void onDisconnected(DisconnectedCallbackHandler cb)
Set callback function for websocket disconnected event.
Definition: SinricPro.h:435
+
SinricProClass::restoreDeviceStates
void restoreDeviceStates(bool flag)
Enable / disable restore device states function.
Definition: SinricPro.h:505
+
SinricProClass::DisconnectedCallbackHandler
std::function< void(void)> DisconnectedCallbackHandler
Callback definition for onDisconnected function.
Definition: SinricPro.h:50
+
SinricProClass::operator[]
proxy operator[](const String deviceId)
operator[] is used tor create a new device instance or get an existing device instance
Definition: SinricPro.h:85
+
SinricProClass::begin
void begin(String socketAuthToken, String signingKey, String serverURL=SINRICPRO_SERVER_URL)
Initializing SinricProClass to be able to connect to SinricPro Server.
Definition: SinricPro.h:172
+
SinricProClass::ConnectedCallbackHandler
std::function< void(void)> ConnectedCallbackHandler
Callback definition for onConnected function.
Definition: SinricPro.h:42
SinricProClass
The main class of this library, handling communication between SinricPro Server and your devices.
Definition: SinricPro.h:23
SinricPro
The main instance of SinricProClass.
diff --git a/docs/_sinric_pro_config_8h_source.html b/docs/_sinric_pro_config_8h_source.html index d2ccd46..00a29d6 100644 --- a/docs/_sinric_pro_config_8h_source.html +++ b/docs/_sinric_pro_config_8h_source.html @@ -133,7 +133,7 @@
25 // Version Configuration
26 #define SINRICPRO_VERSION_MAJOR 2
27 #define SINRICPRO_VERSION_MINOR 2
-
28 #define SINRICPRO_VERSION_REVISION 6
+
28 #define SINRICPRO_VERSION_REVISION 7
29 #define SINRICPRO_VERSION STR(SINRICPRO_VERSION_MAJOR) "." STR(SINRICPRO_VERSION_MINOR) "." STR(SINRICPRO_VERSION_REVISION)
30 
31 // Server Configuration
diff --git a/docs/class_sinric_pro_class-members.html b/docs/class_sinric_pro_class-members.html index ef0dbab..ffc6766 100644 --- a/docs/class_sinric_pro_class-members.html +++ b/docs/class_sinric_pro_class-members.html @@ -118,7 +118,11 @@

This is the complete list of members for SinricProClass, including all inherited members.

+ + + +
begin(String socketAuthToken, String signingKey, String serverURL=SINRICPRO_SERVER_URL)SinricProClass
ConnectedCallbackHandler typedefSinricProClass
DisconnectedCallbackHandler typedefSinricProClass
handle()SinricProClass
onConnected(ConnectedCallbackHandler cb)SinricProClass
onDisconnected(DisconnectedCallbackHandler cb)SinricProClass
operator[](const String deviceId)SinricProClassinline
restoreDeviceStates(bool flag)SinricProClass
diff --git a/docs/class_sinric_pro_class.html b/docs/class_sinric_pro_class.html index 54f8464..4325b66 100644 --- a/docs/class_sinric_pro_class.html +++ b/docs/class_sinric_pro_class.html @@ -111,6 +111,7 @@
+Public Types | Public Member Functions | List of all members
@@ -123,6 +124,15 @@

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...
 
@@ -131,6 +141,12 @@ + + + + + + @@ -140,7 +156,54 @@

Public Member Functions

void begin (String socketAuthToken, String signingKey, String serverURL=SINRICPRO_SERVER_URL)
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...
 

Detailed Description

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

-

Member Function Documentation

+

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()

@@ -222,6 +285,68 @@

+ +

◆ 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[]()

diff --git a/docs/class_sinric_pro_class.js b/docs/class_sinric_pro_class.js index fdaf5a4..407106f 100644 --- a/docs/class_sinric_pro_class.js +++ b/docs/class_sinric_pro_class.js @@ -5,8 +5,12 @@ var class_sinric_pro_class = [ "Define callback routine(s)", "index.html#autotoc_md13", null ], [ "In setup()", "index.html#autotoc_md14", null ], [ "In loop()", "index.html#autotoc_md15", null ], + [ "ConnectedCallbackHandler", "class_sinric_pro_class.html#a4d7d8547a83d53c20cbd9aa7768e99f5", null ], + [ "DisconnectedCallbackHandler", "class_sinric_pro_class.html#ad84930f3c26ac3692cc885be197d39c7", null ], [ "begin", "class_sinric_pro_class.html#a57722dec8f1f987f57c8fff9eed66765", null ], [ "handle", "class_sinric_pro_class.html#a37c2d0658e498b1bf878f8a3d9a7c5b4", null ], + [ "onConnected", "class_sinric_pro_class.html#ac33a355adfc413d4ff36974d735115bd", null ], + [ "onDisconnected", "class_sinric_pro_class.html#a654bb017ca55b448d55bb36e0346f38a", null ], [ "operator[]", "class_sinric_pro_class.html#a5df2137b8d06e894c917fd28c35c31a4", null ], [ "restoreDeviceStates", "class_sinric_pro_class.html#a27a9bb7f1e8bde0f39398649493b6f93", null ] ]; \ No newline at end of file diff --git a/docs/functions.html b/docs/functions.html index be78195..05c160c 100644 --- a/docs/functions.html +++ b/docs/functions.html @@ -184,6 +184,9 @@

- c -

@@ -191,6 +194,9 @@

- d -

@@ -267,9 +273,15 @@

- o -