From f9524177a291fd721e1002e1232bed63b89c82c1 Mon Sep 17 00:00:00 2001 From: sivar2311 Date: Mon, 25 Nov 2024 05:23:57 +0100 Subject: [PATCH 01/13] fixed missing includes --- src/SinricProModuleCommandHandler.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/SinricProModuleCommandHandler.h b/src/SinricProModuleCommandHandler.h index fd0d347..fecfce3 100644 --- a/src/SinricProModuleCommandHandler.h +++ b/src/SinricProModuleCommandHandler.h @@ -8,8 +8,10 @@ #pragma once #include "SinricProRequest.h" - +#include "SinricProStrings.h" #include "SinricProNamespace.h" +#include "SinricProDebug.h" + namespace SINRICPRO_NAMESPACE { FSTR(OTA, otaUpdateAvailable); // "otaUpdateAvailable" From cb5e66efb2c75633a18e103998459afa47af1464 Mon Sep 17 00:00:00 2001 From: sivar2311 Date: Mon, 25 Nov 2024 05:29:41 +0100 Subject: [PATCH 02/13] implemented signature function for devices --- src/SinricPro.h | 73 +++++++++++++++++++++------------------- src/SinricProDevice.h | 7 +++- src/SinricProInterface.h | 1 + 3 files changed, 46 insertions(+), 35 deletions(-) diff --git a/src/SinricPro.h b/src/SinricPro.h index 567da20..2e3e169 100644 --- a/src/SinricPro.h +++ b/src/SinricPro.h @@ -10,6 +10,7 @@ #include "SinricProDeviceInterface.h" #include "SinricProInterface.h" #include "SinricProMessageid.h" +#include "SinricProModuleCommandHandler.h" #include "SinricProNamespace.h" #include "SinricProQueue.h" #include "SinricProSignature.h" @@ -17,7 +18,6 @@ #include "SinricProUDP.h" #include "SinricProWebsocket.h" #include "Timestamp.h" -#include "SinricProModuleCommandHandler.h" namespace SINRICPRO_NAMESPACE { /** @@ -57,7 +57,7 @@ using OTAUpdateCallbackHandler = std::function @@ -117,7 +118,7 @@ class SinricProClass : public SinricProInterface { JsonDocument prepareResponse(JsonDocument& requestMessage); JsonDocument prepareEvent(String deviceId, const char* action, const char* cause) override; - void sendMessage(JsonDocument& jsonMessage) override; + void sendMessage(JsonDocument& jsonMessage) override; private: void handleReceiveQueue(); @@ -301,7 +302,7 @@ void SinricProClass::handle() { JsonDocument SinricProClass::prepareRequest(String deviceId, const char* action) { JsonDocument requestMessage; - JsonObject header = requestMessage[FSTR_SINRICPRO_header].to(); + JsonObject header = requestMessage[FSTR_SINRICPRO_header].to(); header[FSTR_SINRICPRO_payloadVersion] = 2; header[FSTR_SINRICPRO_signatureVersion] = 1; @@ -332,20 +333,20 @@ void SinricProClass::handleModuleRequest(JsonDocument& requestMessage, interface #endif JsonDocument responseMessage = prepareResponse(requestMessage); - - String action = requestMessage[FSTR_SINRICPRO_payload][FSTR_SINRICPRO_action] | ""; - JsonObject request_value = requestMessage[FSTR_SINRICPRO_payload][FSTR_SINRICPRO_value]; - JsonObject response_value = responseMessage[FSTR_SINRICPRO_payload][FSTR_SINRICPRO_value]; - SinricProRequest request{ action, "", request_value, response_value}; + + String action = requestMessage[FSTR_SINRICPRO_payload][FSTR_SINRICPRO_action] | ""; + JsonObject request_value = requestMessage[FSTR_SINRICPRO_payload][FSTR_SINRICPRO_value]; + JsonObject response_value = responseMessage[FSTR_SINRICPRO_payload][FSTR_SINRICPRO_value]; + SinricProRequest request{action, "", request_value, response_value}; bool success = _moduleCommandHandler.handleRequest(request); - + responseMessage[FSTR_SINRICPRO_payload][FSTR_SINRICPRO_success] = success; responseMessage[FSTR_SINRICPRO_payload].remove(FSTR_SINRICPRO_deviceId); if (!success) { if (responseMessageStr.length() > 0) { responseMessage[FSTR_SINRICPRO_payload][FSTR_SINRICPRO_message] = responseMessageStr; - responseMessageStr = ""; + responseMessageStr = ""; } else { responseMessage[FSTR_SINRICPRO_payload][FSTR_SINRICPRO_message] = "Module did not handle \"" + action + "\""; } @@ -424,13 +425,13 @@ void SinricProClass::handleReceiveQueue() { DEBUG_SINRIC("[SinricPro.handleReceiveQueue()]: Signature is valid. Processing message...\r\n"); extractTimestamp(jsonMessage); if (messageType == FSTR_SINRICPRO_response) handleResponse(jsonMessage); - if (messageType == FSTR_SINRICPRO_request) { + if (messageType == FSTR_SINRICPRO_request) { String scope = jsonMessage[FSTR_SINRICPRO_payload][FSTR_SINRICPRO_scope] | FSTR_SINRICPRO_device; if (strcmp(FSTR_SINRICPRO_module, scope.c_str()) == 0) { handleModuleRequest(jsonMessage, rawMessage->getInterface()); } else { handleDeviceRequest(jsonMessage, rawMessage->getInterface()); - } + } }; } else { DEBUG_SINRIC("[SinricPro.handleReceiveQueue()]: Signature is invalid! \r\n"); @@ -505,7 +506,7 @@ bool SinricProClass::isConnected() { /** * @brief Set callback function for OTA (Over-The-Air) updates. - * + * * This method registers a callback function that will be called when an OTA update is available. * The callback should handle the process of downloading and applying the update. * @@ -519,7 +520,7 @@ void SinricProClass::onOTAUpdate(OTAUpdateCallbackHandler cb) { /** * @brief Set callback function for setting a module setting. - * + * * This method registers a callback function that will be called when a request to change * a module setting is received. * @return void @@ -538,7 +539,7 @@ void SinricProClass::onSetSetting(SetSettingCallbackHandler cb) { * when the SinricPro system needs to report the device's health status. * * @param cb A function pointer of type ReportHealthCallbackHandler. - * This callback should populate a String with health information and return a boolean + * This callback should populate a String with health information and return a boolean * indicating success or failure of the health reporting process. * @return void * @see ReportHealthCallbackHandler for the definition of the callback function type. @@ -660,17 +661,21 @@ void SinricProClass::setResponseMessage(String&& message) { } /** - * @brief Get the current timestamp + * @brief * - * @return unsigned long current timestamp (unix epoch time) + * return unsigned long current timestamp(unix epoch time) * / */ unsigned long SinricProClass::getTimestamp() { return timestamp.getTimestamp(); } +String SinricProClass::sign(const String& message) { + return HMACbase64(message, appSecret); +} + JsonDocument SinricProClass::prepareResponse(JsonDocument& requestMessage) { JsonDocument responseMessage; - JsonObject header = responseMessage[FSTR_SINRICPRO_header].to(); + JsonObject header = responseMessage[FSTR_SINRICPRO_header].to(); header[FSTR_SINRICPRO_payloadVersion] = 2; header[FSTR_SINRICPRO_signatureVersion] = 1; @@ -691,7 +696,7 @@ JsonDocument SinricProClass::prepareResponse(JsonDocument& requestMessage) { JsonDocument SinricProClass::prepareEvent(String deviceId, const char* action, const char* cause) { JsonDocument eventMessage; - JsonObject header = eventMessage[FSTR_SINRICPRO_header].to(); + JsonObject header = eventMessage[FSTR_SINRICPRO_header].to(); header[FSTR_SINRICPRO_payloadVersion] = 2; header[FSTR_SINRICPRO_signatureVersion] = 1; diff --git a/src/SinricProDevice.h b/src/SinricProDevice.h index 0499562..6678f81 100644 --- a/src/SinricProDevice.h +++ b/src/SinricProDevice.h @@ -33,8 +33,9 @@ class SinricProDevice : public SinricProDeviceInterface { void registerRequestHandler(const SinricProRequestHandler &requestHandler); unsigned long getTimestamp(); + String sign(const String& message); virtual bool sendEvent(JsonDocument &event); - virtual JsonDocument prepareEvent(const char *action, const char *cause); + virtual JsonDocument prepareEvent(const char *action, const char *cause); virtual String getProductType(); virtual void begin(SinricProInterface *eventSender); @@ -74,6 +75,10 @@ JsonDocument SinricProDevice::prepareEvent(const char* action, const char* cause return JsonDocument(); } +String SinricProDevice::sign(const String& message) { + if (eventSender) return eventSender->sign(message); + return ""; +} bool SinricProDevice::sendEvent(JsonDocument& event) { if (!SinricPro.isConnected()) { diff --git a/src/SinricProInterface.h b/src/SinricProInterface.h index 2de9216..c5ea60c 100644 --- a/src/SinricProInterface.h +++ b/src/SinricProInterface.h @@ -17,6 +17,7 @@ class SinricProInterface { friend class SinricProDevice; protected: virtual void sendMessage(JsonDocument& jsonEvent); + virtual String sign(const String& message); virtual JsonDocument prepareEvent(String deviceId, const char* action, const char* cause); virtual unsigned long getTimestamp(); virtual bool isConnected(); From 40a0d699d5e429e83cacbff675635f7614b1a69f Mon Sep 17 00:00:00 2001 From: sivar2311 Date: Mon, 25 Nov 2024 05:30:48 +0100 Subject: [PATCH 03/13] added SINRICPRO_CAMERA_URL --- src/SinricProConfig.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/SinricProConfig.h b/src/SinricProConfig.h index 646db76..8a8aca3 100644 --- a/src/SinricProConfig.h +++ b/src/SinricProConfig.h @@ -25,13 +25,30 @@ #define WEBSOCKET_SSL #endif +#ifndef SINRICPRO_SERVER_URL #define SINRICPRO_SERVER_URL "ws.sinric.pro" +#endif + +#ifndef SINRICPRO_SERVER_PORT #define SINRICPRO_SERVER_PORT 80 +#endif + +#ifndef SINRICPRO_SERVER_SSL_PORT #define SINRICPRO_SERVER_SSL_PORT 443 +#endif + +#ifndef SINRICPRO_CAMERA_URL +#define SINRICPRO_CAMERA_URL "camera.sinric.pro" +#endif // UDP Configuration +#ifndef UDP_MUTLICAST_IP #define UDP_MULTICAST_IP IPAddress(224,9,9,9) +#endif + +#ifndef UDP_MULTICAST_PORT #define UDP_MULTICAST_PORT 3333 +#endif // WebSocket Configuration #ifdef DEBUG_WIFI_ISSUE @@ -43,6 +60,14 @@ #define WEBSOCKET_RETRY_COUNT 2 // EventLimiter Configuration +#ifndef EVENT_LIMIT_STATE #define EVENT_LIMIT_STATE 1000 +#endif + +#ifndef EVENT_LIMIT_SENSOR_STATE #define EVENT_LIMIT_SENSOR_STATE EVENT_LIMIT_STATE +#endif + +#ifndef EVENT_LIMIT_SENSOR_VALUE #define EVENT_LIMIT_SENSOR_VALUE 60000 +#endif From f44b034db07e3601a2d83bef8c51d8cc090cb7de Mon Sep 17 00:00:00 2001 From: sivar2311 Date: Mon, 25 Nov 2024 05:31:21 +0100 Subject: [PATCH 04/13] Implemented CameraController --- src/Capabilities/CameraController.h | 83 +++++++++++++++++++++++++++++ src/SinricProCamera.h | 5 +- 2 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 src/Capabilities/CameraController.h diff --git a/src/Capabilities/CameraController.h b/src/Capabilities/CameraController.h new file mode 100644 index 0000000..a69fbf6 --- /dev/null +++ b/src/Capabilities/CameraController.h @@ -0,0 +1,83 @@ +#pragma once + +#include "../EventLimiter.h" +#include "../SinricProNamespace.h" +#include "../SinricProRequest.h" +#include "../SinricProStrings.h" +#include +#include + +namespace SINRICPRO_NAMESPACE { + +FSTR(CAMERA, getSnapshot); // "getSnapshot" + +using SnapshotCallback = std::function; + +template +class CameraController { + public: + CameraController(); + void onSnapshot(SnapshotCallback cb); + int uploadImage(uint8_t* buffer, size_t len); + + protected: + bool handleCameraController(SinricProRequest &request); + + private: + SnapshotCallback getSnapshotCallback = nullptr; +}; + +template +CameraController::CameraController() { + T *device = static_cast(this); + device->registerRequestHandler(std::bind(&CameraController::handleCameraController, this, std::placeholders::_1)); +} + +template +void CameraController::onSnapshot(SnapshotCallback cb) { + getSnapshotCallback = cb; +} + +template +bool CameraController::handleCameraController(SinricProRequest &request) { + T *device = static_cast(this); + + bool success = false; + + if (request.action == FSTR_CAMERA_getSnapshot) { + if (getSnapshotCallback) { + success = getSnapshotCallback(device->deviceId); + } + } + + return success; +} + +template +int CameraController::uploadImage(uint8_t* buffer, size_t len) { + T *device = static_cast(this); + + if (!buffer) return -1; + + WiFiClientSecure client; + client.setInsecure(); + + HTTPClient http; + if (!http.begin(client, SINRICPRO_CAMERA_URL, 443, "/snapshot", true)) return -1; + + const String& deviceId = device->getDeviceId(); + String timestamp = String(device->getTimestamp()); + String signature = device->sign(deviceId+timestamp); + + http.addHeader("deviceid", deviceId); + http.addHeader("timestamp", timestamp); + http.addHeader("signature", signature); + + int resCode = http.POST(buffer, len); + http.PUT(buffer, len); + http.end(); + + return resCode; +} + +} // namespace SINRICPRO_NAMESPACE \ No newline at end of file diff --git a/src/SinricProCamera.h b/src/SinricProCamera.h index af87fd1..cc85494 100644 --- a/src/SinricProCamera.h +++ b/src/SinricProCamera.h @@ -11,6 +11,7 @@ #include "Capabilities/SettingController.h" #include "Capabilities/PushNotification.h" #include "Capabilities/PowerStateController.h" +#include "Capabilities/CameraController.h" #include "SinricProNamespace.h" namespace SINRICPRO_NAMESPACE { @@ -23,10 +24,12 @@ namespace SINRICPRO_NAMESPACE { class SinricProCamera : public SinricProDevice, public SettingController, public PushNotification, - public PowerStateController { + public PowerStateController, + public CameraController { friend class SettingController; friend class PushNotification; friend class PowerStateController; + friend class CameraController; public: SinricProCamera(const String &deviceId) : SinricProDevice(deviceId, "CAMERA") {} }; From 473040358979a4e478bb88e2a945b36ab6f99bc7 Mon Sep 17 00:00:00 2001 From: sivar2311 Date: Mon, 25 Nov 2024 05:32:46 +0100 Subject: [PATCH 05/13] Bump version to 3.4.0 --- changelog.md | 3 +++ library.json | 2 +- library.properties | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/changelog.md b/changelog.md index de04657..47bd0b3 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,8 @@ # Changelog +## Version 3.4.0 + - Support Image upload on camera devices + ## Version 3.3.1 - Support SmartButton. diff --git a/library.json b/library.json index 8e5b45c..d03ce87 100644 --- a/library.json +++ b/library.json @@ -13,7 +13,7 @@ "maintainer": true } ], - "version": "3.3.1", + "version": "3.4.0", "frameworks": "arduino", "platforms": [ "espressif8266", diff --git a/library.properties b/library.properties index 5bf0048..223c1ee 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=SinricPro -version=3.3.1 +version=3.4.0 author=Boris Jaeger maintainer=Boris Jaeger sentence=Library for https://sinric.pro - simple way to connect your device to alexa From 5c640e50c5efda2ffd983e81fb6344db0c7060c7 Mon Sep 17 00:00:00 2001 From: sivar2311 Date: Tue, 26 Nov 2024 05:19:04 +0100 Subject: [PATCH 06/13] removed unnecessary http.PUT --- src/Capabilities/CameraController.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Capabilities/CameraController.h b/src/Capabilities/CameraController.h index a69fbf6..97f093a 100644 --- a/src/Capabilities/CameraController.h +++ b/src/Capabilities/CameraController.h @@ -74,7 +74,6 @@ int CameraController::uploadImage(uint8_t* buffer, size_t len) { http.addHeader("signature", signature); int resCode = http.POST(buffer, len); - http.PUT(buffer, len); http.end(); return resCode; From 7712e8239630c1df70e823dd84938587f0b1caba Mon Sep 17 00:00:00 2001 From: sivar2311 Date: Tue, 26 Nov 2024 05:22:25 +0100 Subject: [PATCH 07/13] renamed upladImage to sendSnapshot --- src/Capabilities/CameraController.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Capabilities/CameraController.h b/src/Capabilities/CameraController.h index 97f093a..a02c917 100644 --- a/src/Capabilities/CameraController.h +++ b/src/Capabilities/CameraController.h @@ -18,7 +18,7 @@ class CameraController { public: CameraController(); void onSnapshot(SnapshotCallback cb); - int uploadImage(uint8_t* buffer, size_t len); + int sendSnapshot(uint8_t* buffer, size_t len); protected: bool handleCameraController(SinricProRequest &request); @@ -54,7 +54,7 @@ bool CameraController::handleCameraController(SinricProRequest &request) { } template -int CameraController::uploadImage(uint8_t* buffer, size_t len) { +int CameraController::sendSnapshot(uint8_t* buffer, size_t len) { T *device = static_cast(this); if (!buffer) return -1; From 3a6d562818d92f467827bbfc3e14df794a436ab6 Mon Sep 17 00:00:00 2001 From: sivar2311 Date: Thu, 28 Nov 2024 06:46:50 +0100 Subject: [PATCH 08/13] fixed: version --- src/SinricProVersion.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/SinricProVersion.h b/src/SinricProVersion.h index 59024ce..60f49f7 100644 --- a/src/SinricProVersion.h +++ b/src/SinricProVersion.h @@ -5,8 +5,8 @@ // Version Configuration #define SINRICPRO_VERSION_MAJOR 3 -#define SINRICPRO_VERSION_MINOR 3 -#define SINRICPRO_VERSION_REVISION 1 +#define SINRICPRO_VERSION_MINOR 4 +#define SINRICPRO_VERSION_REVISION 0 #define SINRICPRO_VERSION STR(SINRICPRO_VERSION_MAJOR) "." STR(SINRICPRO_VERSION_MINOR) "." STR(SINRICPRO_VERSION_REVISION) #define SINRICPRO_VERSION_STR "SinricPro (v" SINRICPRO_VERSION ")" #define SINRICPRO_VERISON_INT SINRICPRO_VERSION_MAJOR * 1000000 + SINRICPRO_VERSION_MINOR * 1000 + SINRICPRO_VERSION_REVISION \ No newline at end of file From 536ec6cc01604ba1f497bc7eb32679ae09d7d93b Mon Sep 17 00:00:00 2001 From: sivar2311 Date: Thu, 28 Nov 2024 06:47:17 +0100 Subject: [PATCH 09/13] fixed interface classes --- src/SinricProDeviceInterface.h | 18 +++++++++--------- src/SinricProInterface.h | 18 +++++++++--------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/SinricProDeviceInterface.h b/src/SinricProDeviceInterface.h index 25740c2..0eba94f 100644 --- a/src/SinricProDeviceInterface.h +++ b/src/SinricProDeviceInterface.h @@ -1,19 +1,19 @@ #pragma once #include "SinricProInterface.h" -#include "SinricProRequest.h" - #include "SinricProNamespace.h" +#include "SinricProRequest.h" namespace SINRICPRO_NAMESPACE { class SinricProDeviceInterface { - friend class SinricProClass; + friend class SinricProClass; + protected: - virtual bool handleRequest(SinricProRequest &request) = 0; - virtual String getDeviceId() = 0; - virtual String getProductType() = 0; - virtual void begin(SinricProInterface* eventSender) = 0; - virtual unsigned long getTimestamp(); + virtual bool handleRequest(SinricProRequest& request) = 0; + virtual String getDeviceId() = 0; + virtual String getProductType() = 0; + virtual void begin(SinricProInterface* eventSender) = 0; + virtual unsigned long getTimestamp() = 0; }; -} // SINRICPRO_NAMESPACE \ No newline at end of file +} // namespace SINRICPRO_NAMESPACE \ No newline at end of file diff --git a/src/SinricProInterface.h b/src/SinricProInterface.h index c5ea60c..38436e5 100644 --- a/src/SinricProInterface.h +++ b/src/SinricProInterface.h @@ -8,19 +8,19 @@ #pragma once #include "ArduinoJson.h" -#include "SinricProQueue.h" - #include "SinricProNamespace.h" +#include "SinricProQueue.h" namespace SINRICPRO_NAMESPACE { class SinricProInterface { - friend class SinricProDevice; + friend class SinricProDevice; + protected: - virtual void sendMessage(JsonDocument& jsonEvent); - virtual String sign(const String& message); - virtual JsonDocument prepareEvent(String deviceId, const char* action, const char* cause); - virtual unsigned long getTimestamp(); - virtual bool isConnected(); + virtual void sendMessage(JsonDocument& jsonEvent) = 0; + virtual String sign(const String& message) = 0; + virtual JsonDocument prepareEvent(String deviceId, const char* action, const char* cause) = 0; + virtual unsigned long getTimestamp() = 0; + virtual bool isConnected() = 0; }; -} // SINRICPRO_NAMESPACE \ No newline at end of file +} // namespace SINRICPRO_NAMESPACE \ No newline at end of file From 7e1e13e0261eb3fa893601e5bdffac01efe868b7 Mon Sep 17 00:00:00 2001 From: sivar2311 Date: Fri, 29 Nov 2024 05:28:30 +0100 Subject: [PATCH 10/13] removed containsKey() containsKey() is deprecated since ArduinoJson 7.2 --- src/Capabilities/ChannelController.h | 4 ++-- src/Capabilities/ThermostatController.h | 2 +- src/SinricPro.h | 2 +- src/SinricProSignature.cpp | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Capabilities/ChannelController.h b/src/Capabilities/ChannelController.h index 96bafbc..847906c 100644 --- a/src/Capabilities/ChannelController.h +++ b/src/Capabilities/ChannelController.h @@ -157,13 +157,13 @@ bool ChannelController::handleChannelController(SinricProRequest &request) { if (request.action == FSTR_CHANNEL_changeChannel) { - if (changeChannelCallback && request.request_value[FSTR_CHANNEL_channel].containsKey(FSTR_CHANNEL_name)) { + if (changeChannelCallback && request.request_value[FSTR_CHANNEL_channel][FSTR_CHANNEL_name].is()) { String channelName = request.request_value[FSTR_CHANNEL_channel][FSTR_CHANNEL_name] | ""; success = changeChannelCallback(device->deviceId, channelName); request.response_value[FSTR_CHANNEL_channel][FSTR_CHANNEL_name] = channelName; } - if (changeChannelNumberCallback && request.request_value[FSTR_CHANNEL_channel].containsKey(FSTR_CHANNEL_number)) { + if (changeChannelNumberCallback && request.request_value[FSTR_CHANNEL_channel][FSTR_CHANNEL_number].is()) { String channelName(""); int channelNumber = request.request_value[FSTR_CHANNEL_channel][FSTR_CHANNEL_number]; success = changeChannelNumberCallback(device->deviceId, channelNumber, channelName); diff --git a/src/Capabilities/ThermostatController.h b/src/Capabilities/ThermostatController.h index c7e8da7..6ac5b44 100644 --- a/src/Capabilities/ThermostatController.h +++ b/src/Capabilities/ThermostatController.h @@ -181,7 +181,7 @@ bool ThermostatController::handleThermostatController(SinricProRequest &reque if (request.action == FSTR_THERMOSTAT_targetTemperature && targetTemperatureCallback) { float temperature; - if (request.request_value.containsKey(FSTR_THERMOSTAT_temperature)) { + if (request.request_value[FSTR_THERMOSTAT_temperature].is()) { temperature = request.request_value[FSTR_THERMOSTAT_temperature]; } else { temperature = 1; diff --git a/src/SinricPro.h b/src/SinricPro.h index 2e3e169..9cb567a 100644 --- a/src/SinricPro.h +++ b/src/SinricPro.h @@ -685,7 +685,7 @@ JsonDocument SinricProClass::prepareResponse(JsonDocument& requestMessage) { payload[FSTR_SINRICPRO_scope] = requestMessage[FSTR_SINRICPRO_payload][FSTR_SINRICPRO_scope]; payload[FSTR_SINRICPRO_createdAt] = 0; payload[FSTR_SINRICPRO_deviceId] = requestMessage[FSTR_SINRICPRO_payload][FSTR_SINRICPRO_deviceId]; - if (requestMessage[FSTR_SINRICPRO_payload].containsKey(FSTR_SINRICPRO_instanceId)) payload[FSTR_SINRICPRO_instanceId] = requestMessage[FSTR_SINRICPRO_payload][FSTR_SINRICPRO_instanceId]; + if (requestMessage[FSTR_SINRICPRO_payload][FSTR_SINRICPRO_instanceId].is()) payload[FSTR_SINRICPRO_instanceId] = requestMessage[FSTR_SINRICPRO_payload][FSTR_SINRICPRO_instanceId]; payload[FSTR_SINRICPRO_message] = FSTR_SINRICPRO_OK; payload[FSTR_SINRICPRO_replyToken] = requestMessage[FSTR_SINRICPRO_payload][FSTR_SINRICPRO_replyToken]; payload[FSTR_SINRICPRO_success] = false; diff --git a/src/SinricProSignature.cpp b/src/SinricProSignature.cpp index be8d06d..3d2bc0a 100644 --- a/src/SinricProSignature.cpp +++ b/src/SinricProSignature.cpp @@ -71,7 +71,7 @@ String calculateSignature(const char* key, String payload) { } String signMessage(String key, JsonDocument &jsonMessage) { - if (!jsonMessage.containsKey("signature")) jsonMessage["signature"].to(); + if (!jsonMessage["signature"].is()) jsonMessage["signature"].to(); jsonMessage["signature"]["HMAC"] = calculateSignature(key.c_str(), jsonMessage["payload"]); String signedMessageString; serializeJson(jsonMessage, signedMessageString); From 30035b42cfc9da95115ce7e7a3e9920f76884bfa Mon Sep 17 00:00:00 2001 From: sivar2311 Date: Fri, 29 Nov 2024 05:36:28 +0100 Subject: [PATCH 11/13] Update changelog --- changelog.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/changelog.md b/changelog.md index 47bd0b3..d5216b8 100644 --- a/changelog.md +++ b/changelog.md @@ -1,7 +1,12 @@ # Changelog ## Version 3.4.0 + New: - Support Image upload on camera devices + + Fixed: + - Removed calls to `containsKey` - deprecated since ArduinoJSON 7.2 + - Missing includes ## Version 3.3.1 - Support SmartButton. From f5f32acf19a90beb10b5b2b8ec66048fe8b67472 Mon Sep 17 00:00:00 2001 From: sivar2311 Date: Fri, 29 Nov 2024 06:01:20 +0100 Subject: [PATCH 12/13] Added definition for camera upload path --- src/SinricProConfig.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/SinricProConfig.h b/src/SinricProConfig.h index 8a8aca3..c50d005 100644 --- a/src/SinricProConfig.h +++ b/src/SinricProConfig.h @@ -41,6 +41,10 @@ #define SINRICPRO_CAMERA_URL "camera.sinric.pro" #endif +#ifndef SINRICPRO_CAMERA_PATH +#define SINRICPRO_CAMERA_PATH "/snapshot" +#endif + // UDP Configuration #ifndef UDP_MUTLICAST_IP #define UDP_MULTICAST_IP IPAddress(224,9,9,9) From 444d0b4e96b9e42b4b780514924e50d18877917d Mon Sep 17 00:00:00 2001 From: sivar2311 Date: Fri, 29 Nov 2024 06:02:00 +0100 Subject: [PATCH 13/13] Changed: CameraController is now using defined Strings from SinricProStrings.h --- src/Capabilities/CameraController.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Capabilities/CameraController.h b/src/Capabilities/CameraController.h index a02c917..bda0288 100644 --- a/src/Capabilities/CameraController.h +++ b/src/Capabilities/CameraController.h @@ -63,15 +63,15 @@ int CameraController::sendSnapshot(uint8_t* buffer, size_t len) { client.setInsecure(); HTTPClient http; - if (!http.begin(client, SINRICPRO_CAMERA_URL, 443, "/snapshot", true)) return -1; + if (!http.begin(client, SINRICPRO_CAMERA_URL, 443, SINRICPRO_CAMERA_PATH, true)) return -1; const String& deviceId = device->getDeviceId(); String timestamp = String(device->getTimestamp()); String signature = device->sign(deviceId+timestamp); - http.addHeader("deviceid", deviceId); - http.addHeader("timestamp", timestamp); - http.addHeader("signature", signature); + http.addHeader(FSTR_SINRICPRO_deviceId, deviceId); + http.addHeader(FSTR_SINRICPRO_timestamp, timestamp); + http.addHeader(FSTR_SINRICPRO_signature, signature); int resCode = http.POST(buffer, len); http.end();