Skip to content

Commit

Permalink
Merge pull request #368 from sivar2311/master
Browse files Browse the repository at this point in the history
Upgrade to ArduinoJson 7.x
  • Loading branch information
sivar2311 authored Feb 16, 2024
2 parents b324295 + 2f30a49 commit 9620db8
Show file tree
Hide file tree
Showing 35 changed files with 104 additions and 199 deletions.
26 changes: 6 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,13 @@

[![Build](https://github.com/sinricpro/esp8266-esp32-sdk/actions/workflows/build-esp8266-esp32.yml/badge.svg)](https://github.com/sinricpro/esp8266-esp32-sdk/actions/workflows/build-esp8266-esp32.yml)

## Note
1. Use the latest ESP8226/ESP32/RP2040 Arduino Core!
2. Use the latest WebSocktes library!
3. Use the latest ArduinoJson library!

## 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](examples/platformio/platformio.ini) file from examples to ensure that all dependent libraries will installed automaticly.
3. Create a new Project
4. Use the [Library Manager](https://docs.platformio.org/en/latest/librarymanager/) to add the library to your project or add `sinricpro/SinricPro` manually to your `lib_deps` in `platformio.ini`.

![sinricpro library manager](https://raw.githubusercontent.com/sinricpro/images/master/platformio-install-sinricpro.png)

Expand All @@ -35,8 +30,8 @@
---

## Dependencies
[ArduinoJson](https://github.com/bblanchon/ArduinoJson) by Benoit Blanchon (minimum Version 6.12.0)
[WebSockets](https://github.com/Links2004/arduinoWebSockets) by Markus Sattler (minimum Version 2.4.0)
- [ArduinoJson](https://github.com/bblanchon/ArduinoJson) by Benoit Blanchon (minimum Version 7.0.3)
- [WebSockets](https://github.com/Links2004/arduinoWebSockets) by Markus Sattler (minimum Version 2.4.0)

---

Expand Down Expand Up @@ -98,28 +93,19 @@ Example
```C++
SinricProSwitch& mySwitch = SinricPro["YOUR-SWITCH-ID-HERE"];
```
*Example 2 (alternatively)*
```C++
SinricProSwitch& mySwitch = SinricPro.add<SinricProSwitch>("YOUR-SWITCH-ID-HERE");
```

---
## How to retrieve a device for sending an event?
Syntax is
```C++
DeviceType& myDevice = SinricPro[DEVICE_ID];
```
Example 1
Example
```C++
SinricProDoorbell& myDoorbell = SinricPro["YOUR-DOORBELL-ID-HERE"];
myDoorbell.sendDoorbellEvent();
```

*Example 2 (alternatively)*
```C++
SinricPro["YOUR-DOORBELL-ID-HERE"].as<SinricProDoorbell>().sendDoorbellEvent();
```

## How to send a push notification?
```C++
SinricProSwitch& mySwitch = SinricPro[SWITCH_ID];
Expand All @@ -128,7 +114,7 @@ mySwitch.sendPushNotification("Hello SinricPro!");

---

# Devices
## Devices
* Switch
* Dimmable Switch
* Light
Expand Down
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# Changelog
## Version 3.1.0
Upgrade:
- Upgrade to ArduinoJson 7

## Version 3.0.1
Fixed:
- SinricPro.isConnected() still returns true if the connection was lost
Expand Down
103 changes: 4 additions & 99 deletions examples/platformio/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,12 @@
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

[platformio]
; ============================================================
; chose environment:
; ESP8266
; ESP32
; ============================================================
default_envs = ESP8266
;default_envs = ESP32

[env]
; ============================================================
; Serial configuration
; choose upload speed, serial-monitor speed
; ============================================================
framework = arduino
upload_speed = 921600
;upload_port = COM11
monitor_speed = 115200
;monitor_port = COM11

lib_deps =
sinricpro/SinricPro

build_flags =
; set your debug output (default=Serial)
-D DEBUG_ESP_PORT=Serial
Expand All @@ -40,95 +24,16 @@ build_flags =
; comment the following line to enable SinricPro debugging
-D NODEBUG_SINRIC


[env:ESP8266]
platform = espressif8266
framework = arduino
; ============================================================
; Board configuration
; choose your board by uncommenting one of the following lines
; ============================================================
;board = gen4iod
;board = huzzah
;board = oak
;board = esp_wroom_02
;board = espduino
;board = espectro
;board = espino
;board = espresso_lite_v1
;board = espresso_lite_v2
;board = esp12e
;board = esp01_1m
;board = esp01
;board = esp07
;board = esp8285
;board = heltec_wifi_kit_8
;board = inventone
;board = nodemcu
board = nodemcuv2
;board = modwifi
;board = phoenix_v1
;board = phoenix_v2
;board = sparkfunBlynk
;board = thing
;board = thingdev
;board = esp210
;board = espinotee
;board = d1
;board = d1_mini
;board = d1_mini_lite
;board = d1_mini_pro
;board = wifi_slot
;board = wifiduino
;board = wifinfo
;board = wio_link
;board = wio_node
;board = xinabox_cw01
;board = esp32doit-devkit-v1
board = esp12e

[env:ESP32]
platform = espressif32
framework = arduino
; ============================================================
; Board configuration
; choose your board by uncommenting one of the following lines
; ============================================================
;board = esp32cam
;board = alksesp32
;board = featheresp32
;board = espea32
;board = bpi-bit
;board = d-duino-32
board = esp32doit-devkit-v1
;board = pocket_32
;board = fm-devkit
;board = pico32
;board = esp32-evb
;board = esp32-gateway
;board = esp32-pro
;board = esp32-poe
;board = oroca_edubot
;board = onehorse32dev
;board = lopy
;board = lopy4
;board = wesp32
;board = esp32thing
;board = sparkfun_lora_gateway_1-channel
;board = ttgo-lora32-v1
;board = ttgo-t-beam
;board = turta_iot_node
;board = lolin_d32
;board = lolin_d32_pro
;board = lolin32
;board = wemosbat
;board = widora-air
;board = xinabox_cw02
;board = iotbusio
;board = iotbusproteus
;board = nina_w10
board = esp32dev

[env:pico]
[env:RP2040]
platform = https://github.com/maxgerhardt/platform-raspberrypi.git
board = pico
framework = arduino
board_build.core = earlephilhower
24 changes: 17 additions & 7 deletions library.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,36 @@
"maintainer": true
}
],
"version": "3.0.1",
"version": "3.1.0",
"frameworks": "arduino",
"platforms": [
"espressif8266",
"espressif32",
"raspberrypi"
],
"dependencies":[
{
"dependencies": [
{
"name": "ArduinoJson",
"platforms":["espressif32","espressif8266"]
"version": "^7.0.3",
"platforms": [
"espressif32",
"espressif8266",
"raspberrypi"
]
},
{
"name": "WebSockets",
"platforms":["espressif32","espressif8266"]
"version": "^2.4.0",
"platforms": [
"espressif32",
"espressif8266",
"raspberrypi"
]
}
],
"examples":[
"examples": [
"examples/*/*.ino",
"examples/*/*/*.ino"
],
"license": "CC-BY-SA-4.0"
}
}
4 changes: 2 additions & 2 deletions library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=SinricPro
version=3.0.1
version=3.1.0
author=Boris Jaeger <[email protected]>
maintainer=Boris Jaeger <[email protected]>
sentence=Library for https://sinric.pro - simple way to connect your device to alexa
Expand All @@ -9,5 +9,5 @@ url=https://sinricpro.github.io/esp8266-esp32-sdk/index.html
architectures=esp8266,esp32,rp2040
repository=https://github.com/sinricpro/esp8266-esp32-sdk.git
license=CC-BY-SA
depends=ArduinoJson,WebSockets
depends=ArduinoJson@7.0.3,WebSockets@2.4.0
includes=SinricPro.h
2 changes: 1 addition & 1 deletion src/Capabilities/AirQualitySensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ bool AirQualitySensor<T>::sendAirQualityEvent(int pm1, int pm2_5, int pm10, Stri
if (event_limiter) return false;
T* device = static_cast<T*>(this);

DynamicJsonDocument eventMessage = device->prepareEvent(FSTR_AIRQUALITY_airQuality, cause.c_str());
JsonDocument eventMessage = device->prepareEvent(FSTR_AIRQUALITY_airQuality, cause.c_str());
JsonObject event_value = eventMessage[FSTR_SINRICPRO_payload][FSTR_SINRICPRO_value];

event_value[FSTR_AIRQUALITY_pm1] = pm1;
Expand Down
2 changes: 1 addition & 1 deletion src/Capabilities/BrightnessController.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ bool BrightnessController<T>::sendBrightnessEvent(int brightness, String cause)
if (event_limiter) return false;
T* device = static_cast<T*>(this);

DynamicJsonDocument eventMessage = device->prepareEvent(FSTR_BRIGHTNESS_setBrightness, cause.c_str());
JsonDocument eventMessage = device->prepareEvent(FSTR_BRIGHTNESS_setBrightness, cause.c_str());
JsonObject event_value = eventMessage[FSTR_SINRICPRO_payload][FSTR_SINRICPRO_value];
event_value[FSTR_BRIGHTNESS_brightness] = brightness;
return device->sendEvent(eventMessage);
Expand Down
2 changes: 1 addition & 1 deletion src/Capabilities/ChannelController.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ bool ChannelController<T>::sendChangeChannelEvent(String channelName, String cau
if (event_limiter) return false;
T* device = static_cast<T*>(this);

DynamicJsonDocument eventMessage = device->prepareEvent(FSTR_CHANNEL_changeChannel, cause.c_str());
JsonDocument eventMessage = device->prepareEvent(FSTR_CHANNEL_changeChannel, cause.c_str());
JsonObject event_value = eventMessage[FSTR_SINRICPRO_payload][FSTR_SINRICPRO_value];
event_value[FSTR_CHANNEL_channel][FSTR_CHANNEL_name] = channelName;
return device->sendEvent(eventMessage);
Expand Down
6 changes: 3 additions & 3 deletions src/Capabilities/ColorController.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ bool ColorController<T>::sendColorEvent(byte r, byte g, byte b, String cause) {
if (event_limiter) return false;
T* device = static_cast<T*>(this);

DynamicJsonDocument eventMessage = device->prepareEvent(FSTR_COLOR_setColor, cause.c_str());
JsonObject event_color = eventMessage[FSTR_SINRICPRO_payload][FSTR_SINRICPRO_value].createNestedObject(FSTR_COLOR_color);
JsonDocument eventMessage = device->prepareEvent(FSTR_COLOR_setColor, cause.c_str());
JsonObject event_color = eventMessage[FSTR_SINRICPRO_payload][FSTR_SINRICPRO_value][FSTR_COLOR_color].to<JsonObject>();
event_color[FSTR_COLOR_r] = r;
event_color[FSTR_COLOR_g] = g;
event_color[FSTR_COLOR_b] = b;
Expand All @@ -108,7 +108,7 @@ bool ColorController<T>::handleColorController(SinricProRequest &request) {
g = request.request_value[FSTR_COLOR_color][FSTR_COLOR_g];
b = request.request_value[FSTR_COLOR_color][FSTR_COLOR_b];
success = colorCallback(device->deviceId, r, g, b);
request.response_value.createNestedObject(FSTR_COLOR_color);
request.response_value[FSTR_COLOR_color].to<JsonObject>();
request.response_value[FSTR_COLOR_color][FSTR_COLOR_r] = r;
request.response_value[FSTR_COLOR_color][FSTR_COLOR_g] = g;
request.response_value[FSTR_COLOR_color][FSTR_COLOR_b] = b;
Expand Down
2 changes: 1 addition & 1 deletion src/Capabilities/ColorTemperatureController.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ bool ColorTemperatureController<T>::sendColorTemperatureEvent(int colorTemperatu
if (event_limiter) return false;
T* device = static_cast<T*>(this);

DynamicJsonDocument eventMessage = device->prepareEvent(FSTR_COLORTEMPERATURE_setColorTemperature, cause.c_str());
JsonDocument eventMessage = device->prepareEvent(FSTR_COLORTEMPERATURE_setColorTemperature, cause.c_str());
JsonObject event_value = eventMessage[FSTR_SINRICPRO_payload][FSTR_SINRICPRO_value];
event_value[FSTR_COLORTEMPERATURE_colorTemperature] = colorTemperature;
return device->sendEvent(eventMessage);
Expand Down
2 changes: 1 addition & 1 deletion src/Capabilities/ContactSensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ bool ContactSensor<T>::sendContactEvent(bool detected, String cause) {
if (event_limiter) return false;
T* device = static_cast<T*>(this);

DynamicJsonDocument eventMessage = device->prepareEvent(FSTR_CONTACT_setContactState, cause.c_str());
JsonDocument eventMessage = device->prepareEvent(FSTR_CONTACT_setContactState, cause.c_str());
JsonObject event_value = eventMessage[FSTR_SINRICPRO_payload][FSTR_SINRICPRO_value];
event_value[FSTR_CONTACT_state] = detected ? FSTR_CONTACT_closed : FSTR_CONTACT_open;
return device->sendEvent(eventMessage);
Expand Down
2 changes: 1 addition & 1 deletion src/Capabilities/DoorController.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ bool DoorController<T>::sendDoorStateEvent(bool state, String cause) {
if (event_limiter) return false;
T* device = static_cast<T*>(this);

DynamicJsonDocument eventMessage = device->prepareEvent(FSTR_DOOR_setMode, cause.c_str());
JsonDocument eventMessage = device->prepareEvent(FSTR_DOOR_setMode, cause.c_str());
JsonObject event_value = eventMessage[FSTR_SINRICPRO_payload][FSTR_SINRICPRO_value];
state ? event_value[FSTR_DOOR_mode] = FSTR_DOOR_Close : event_value[FSTR_DOOR_mode] = FSTR_DOOR_Open;
return device->sendEvent(eventMessage);
Expand Down
2 changes: 1 addition & 1 deletion src/Capabilities/Doorbell.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ bool Doorbell<T>::sendDoorbellEvent(String cause) {
if (event_limiter) return false;
T* device = static_cast<T*>(this);

DynamicJsonDocument eventMessage = device->prepareEvent(FSTR_DOORBELL_DoorbellPress, cause.c_str());
JsonDocument eventMessage = device->prepareEvent(FSTR_DOORBELL_DoorbellPress, cause.c_str());
JsonObject event_value = eventMessage[FSTR_SINRICPRO_payload][FSTR_SINRICPRO_value];
event_value[FSTR_DOORBELL_state] = FSTR_DOORBELL_pressed;
return device->sendEvent(eventMessage);
Expand Down
Loading

0 comments on commit 9620db8

Please sign in to comment.