Skip to content

Commit 01bbbf7

Browse files
committed
Update to Version 2.1.0
1 parent 4585bcd commit 01bbbf7

File tree

7 files changed

+108
-32
lines changed

7 files changed

+108
-32
lines changed

README.md

Lines changed: 72 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

22
# SinricPro (ESP8266 / ESP32 SDK)
3+
## Version 2.1.0
34
## Installation
45

56
### VS Code & PlatformIO:
@@ -18,10 +19,13 @@
1819

1920
---
2021

21-
### Examples
22-
[Switch](https://github.com/sinricpro/esp8266-esp32-sdk/tree/master/examples/switch)
23-
[Doorbell](https://github.com/sinricpro/esp8266-esp32-sdk/tree/master/examples/doorbell)
22+
## Examples
23+
|PlatformIO|Arduino|
24+
|--|--|
25+
|[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)|
26+
|[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)|
2427

28+
---
2529

2630
## Dependencies
2731
[ArduinoJson](https://github.com/bblanchon/ArduinoJson) (Version 6.12.0)
@@ -37,13 +41,13 @@
3741
```
3842
#### Define your credentials from SinricPro-Portal (portal.sinric.pro)
3943
```C++
40-
#define socketAuthToken "your-socket-auth-token"
41-
#define signingKey "your-signing-key"
42-
#define myDeviceId "your-device-id"
44+
#define SOCKET_AUTH_TOKEN "your-socket-auth-token"
45+
#define SIGNING_KEY "your-signing-key"
46+
#define SWITCH_ID "your-switch-device-id"
4347
```
4448
*Note:*
45-
socketAuthToken may be named "APP KEY" in portal.sinric.pro
46-
signingKey may be named "APP SECRET" in portal.sinric.pro
49+
SOCKET_AUTH_TOKEN may be named "APP KEY" in portal.sinric.pro
50+
SIGNING_KEY may be named "APP SECRET" in portal.sinric.pro
4751
#### Define callback routine(s)
4852
```C++
4953
bool onPowerState(const String deviceId, bool &state) {
@@ -53,30 +57,60 @@ bool onPowerState(const String deviceId, bool &state) {
5357
```
5458
#### In setup()
5559
```C++
56-
SinricPro.begin(socketAuthToken, signingKey);
57-
// create a switch
58-
SinricProSwitch mySwitch(myDeviceId);
60+
// create and add a switch to SinricPro
61+
SinricProSwitch& mySwitch = SinricPro.add<SinricProSwitch>(SWITCH_ID);
5962
// set callback function
6063
mySwitch.onPowerState(onPowerState);
6164
// add switch to SinricPro
6265
SinricPro.add(mySwitch);
66+
// startup SinricPro
67+
SinricPro.begin(SOCKET_AUTH_TOKEN, SIGNING_KEY);
68+
6369
```
6470
6571
#### In loop()
6672
```C++
6773
SinricPro.handle();
6874
```
6975

76+
---
77+
## How to add a device?
78+
Syntax is
79+
```C++
80+
DeviceType& myDevice = SinricPro.add<DeviceType>(DEVICE_ID);
81+
```
82+
Example
83+
```C++
84+
SinricProSwitch& mySwitch = SinricPro.add<SinricProSwitch>("5daf50cff082f27422a6f5b8");
85+
```
7086

71-
87+
---
88+
## How to retrieve a device for sending an event?
89+
Syntax is
90+
```C++
91+
DeviceType& myDevice = SinricPro[DEVICE_ID];
92+
```
93+
Example 1
94+
```C++
95+
SinricProDoorbell& myDoorbell = SinricPro["5daf50cff082f27422a6f5b8"];
96+
myDoorbell.sendDoorbellEvent();
97+
```
98+
99+
Example 2 (alternatively)
100+
```C++
101+
SinricPro["5daf50cff082f27422a6f5b8"].as<SinricProDoorbell>().sendDoorbellEvent();
102+
```
72103

73104

105+
---
74106

75107
# Devices
76108
[Switch](#switch) | [Dimmable Switch](#dimmable-switch) | [Light](#light) | [TV](#tv) | [Speaker](#speaker) | [Thermostat](#thermostat) | [Fan (US)](#fan-us) | [Fan (non US)](#fan-non-us) | [Lock](#lock) | [Doorbell](#doorbell) | [TemperatureSensor](#temperaturesensor) | [MotionSensor](#motionsensor) | [ContactSensor](#contactsensor) | [Window AC Unit](#window-ac-unit)
77109

78110
---
79111
## Switch
112+
Defined in [SinricProSwitch.h](/src/SinricProSwitch.h)
113+
80114
Callbacks
81115
- [onPowerState](#onpowerstate)
82116

@@ -86,6 +120,8 @@ Events
86120
---
87121

88122
## Dimmable Switch
123+
Defined in [SinricProDimSwitch.h](/src/SinricProDimSwitch.h)
124+
89125
Callbacks
90126
- [onPowerState](#onpowerstate)
91127
- [onPowerLevel](#onpowerlevel)
@@ -97,6 +133,8 @@ Events
97133
---
98134

99135
## Light
136+
Defined in [SinricProLight.h](/src/SinricProLight.h)
137+
100138
Callbacks
101139
- [onPowerState](#onpowerstate)
102140
- [onBrightness](#onbrightness)
@@ -114,6 +152,8 @@ Events
114152
---
115153
116154
## TV
155+
Defined in [SinricProTV.h](/src/SinricProTV.h)
156+
117157
Callbacks
118158
- [onPowerState](#onpowerstate)
119159
- [onChangeChannel](#onchangechannel)
@@ -134,6 +174,8 @@ Events
134174
---
135175

136176
## Speaker
177+
Defined in [SinricProSpeaker.h](/src/SinricProSpeaker.h)
178+
137179
Callbacks
138180
- [onPowerState](#onpowerstate)
139181
- [onSetVolume](#onsetvolume)
@@ -155,6 +197,8 @@ Events
155197
---
156198

157199
## Thermostat
200+
Defined in [SinricProThermostat.h](/src/SinricProThermostat.h)
201+
158202
Callbacks
159203
- [onPowerState](#onpowerstate)
160204
- [onTargetTemperature](#ontargettemperature)
@@ -169,6 +213,8 @@ Events
169213

170214
---
171215
## Fan (US)
216+
Defined in [SinricProFanUS.h](/src/SinricProFanUS.h)
217+
172218
Callbacks
173219
- [onPowerState](#onpowerstate)
174220
- [onRangeValue](#onrangevalue)
@@ -180,6 +226,8 @@ Events
180226

181227
---
182228
## Fan (non US)
229+
Defined in [SinricProFan.h](/src/SinricProFan.h)
230+
183231
Callbacks
184232
- [onPowerState](#onpowerstate)
185233
- [onPowerLevel](#onpowerlevel)
@@ -191,27 +239,35 @@ Events
191239
---
192240

193241
## Lock
242+
Defined in [SinricProLock.h](/src/SinricProLock.h)
243+
194244
Callbacks
195245
- [onLockState](#onlockstate)
196246

197247
Events
198248
- [sendLockStateEvent](#sendlockstateevent)
199249
---
200250
## Doorbell
251+
Defined in [SinricProDoorbell.h](/src/SinricProDoorbell.h)
252+
201253
Callbacks
202254
- [onPowerState](#onpowerstate)
203255

204256
Events
205257
- [sendDoorbellEvent](#senddoorbellevent)
206258
---
207259
## Temperaturesensor
260+
Defined in [SinricProTemperatureSensor.h](/src/SinricProTemperaturesensor.h)
261+
208262
Callbacks
209263
- [onPowerState](#onpowerstate)
210264

211265
Events
212266
- [sendTemperatureEvent](#sendtemperatureevent)
213267
---
214268
## MotionSensor
269+
Defined in [SinricProMotionsensor.h](/src/SinricProMotionsensor.h)
270+
215271
Callbacks
216272
- [onPowerState](#onpowerstate)
217273

@@ -221,6 +277,8 @@ Events
221277
---
222278

223279
## ContactSensor
280+
Defined in [SinricProContactsensor.h](/src/SinricProContactsensor.h)
281+
224282
Callbacks
225283
- [onPowerState](#onpowerstate)
226284

@@ -230,6 +288,8 @@ Events
230288
---
231289

232290
## Window AC Unit
291+
Defined in [SinricProWindowAC.h](/src/SinricProWindowAC.h)
292+
233293
Callbacks
234294
- [onPowerState](#onpowerstate)
235295
- [onTargetTemperature](#ontargettemperature)

examples/doorbell/doorbell.ino

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,10 @@
2222

2323
#define DOORBELL_ID "YOUR-DEVICE-ID"
2424

25-
2625
// change this to your button PIN
2726
// on NodeMCU D3 / GPIO-0 is flash button PIN so you can use the builtin flash button
2827
#define BUTTON_PIN 0
2928

30-
// define SinricPro Doorbell Device
31-
SinricProDoorbell myDoorbell(DOORBELL_ID);
3229

3330
// checkButtonpress
3431
// reads if BUTTON_PIN gets LOW and send Event
@@ -39,6 +36,11 @@ void checkButtonPress() {
3936
if (actualMillis-lastBtnPress > 500) {
4037
if (digitalRead(BUTTON_PIN)==LOW) {
4138
lastBtnPress = actualMillis;
39+
40+
// get Doorbell device back
41+
SinricProDoorbell& myDoorbell = SinricPro[DOORBELL_ID];
42+
43+
// send doorbell event
4244
myDoorbell.sendDoorbellEvent();
4345
}
4446
}
@@ -59,8 +61,8 @@ void setupWiFi() {
5961

6062
// setup function for SinricPro
6163
void setupSinricPro() {
62-
// add device to SinricPro
63-
SinricPro.add(myDoorbell);
64+
// add doorbell device to SinricPro
65+
SinricPro.add<SinricProDoorbell>(DOORBELL_ID);
6466
// setup SinricPro
6567
SinricPro.begin(SOCKET_AUTH_TOKEN, SIGNING_KEY);
6668
}

examples/switch/switch.ino

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424

2525
#define BTN_FLASH 0
2626

27-
SinricProSwitch mySwitch(SWITCH_ID);
2827
bool myPowerState = false;
2928
unsigned long lastBtnPress = 0;
3029

@@ -57,8 +56,13 @@ void handleButtonPress() {
5756
myPowerState = true;
5857
}
5958
digitalWrite(LED_BUILTIN, myPowerState?LOW:HIGH); // if myPowerState indicates device turned on: turn on led (builtin led uses inverted logic: LOW = LED ON / HIGH = LED OFF)
60-
Serial.printf("Device %s turned %s (manually via flashbutton)\r\n", mySwitch.getDeviceId(), myPowerState?"on":"off");
59+
60+
// get Switch device back
61+
SinricProSwitch& mySwitch = SinricPro[SWITCH_ID];
62+
// send powerstate event
6163
mySwitch.sendPowerStateEvent(myPowerState); // send the new powerState to SinricPro server
64+
Serial.printf("Device %s turned %s (manually via flashbutton)\r\n", mySwitch.getDeviceId(), myPowerState?"on":"off");
65+
6266
lastBtnPress = actualMillis; // update last button press variable
6367
}
6468
}
@@ -78,10 +82,12 @@ void setupWiFi() {
7882

7983
// setup function for SinricPro
8084
void setupSinricPro() {
85+
// add device to SinricPro
86+
SinricProSwitch& mySwitch = SinricPro.add<SinricProSwitch>(SWITCH_ID);
87+
8188
// set callback function to device
8289
mySwitch.onPowerState(onPowerState);
83-
// add device to SinricPro
84-
SinricPro.add(mySwitch);
90+
8591
// setup SinricPro
8692
SinricPro.begin(SOCKET_AUTH_TOKEN, SIGNING_KEY);
8793
}

library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"maintainer": true
1414
}
1515
],
16-
"version": "2.0.5",
16+
"version": "2.1.0",
1717
"frameworks": "arduino",
1818
"platforms": [
1919
"espressif8266",

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=SinricPro
2-
version=2.0.5
2+
version=2.1.0
33
author=Boris Jaeger <[email protected]>
44
maintainer=Boris Jaeger <[email protected]>
55
sentence=An Arduino SDK for https://sinric.pro

pio-examples/doorbell/src/doorbell.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,10 @@
2222

2323
#define DOORBELL_ID "YOUR-DEVICE-ID"
2424

25-
2625
// change this to your button PIN
2726
// on NodeMCU D3 / GPIO-0 is flash button PIN so you can use the builtin flash button
2827
#define BUTTON_PIN 0
2928

30-
// define SinricPro Doorbell Device
31-
SinricProDoorbell myDoorbell(DOORBELL_ID);
3229

3330
// checkButtonpress
3431
// reads if BUTTON_PIN gets LOW and send Event
@@ -39,6 +36,11 @@ void checkButtonPress() {
3936
if (actualMillis-lastBtnPress > 500) {
4037
if (digitalRead(BUTTON_PIN)==LOW) {
4138
lastBtnPress = actualMillis;
39+
40+
// get Doorbell device back
41+
SinricProDoorbell& myDoorbell = SinricPro[DOORBELL_ID];
42+
43+
// send doorbell event
4244
myDoorbell.sendDoorbellEvent();
4345
}
4446
}
@@ -59,8 +61,8 @@ void setupWiFi() {
5961

6062
// setup function for SinricPro
6163
void setupSinricPro() {
62-
// add device to SinricPro
63-
SinricPro.add(myDoorbell);
64+
// add doorbell device to SinricPro
65+
SinricPro.add<SinricProDoorbell>(DOORBELL_ID);
6466
// setup SinricPro
6567
SinricPro.begin(SOCKET_AUTH_TOKEN, SIGNING_KEY);
6668
}

pio-examples/switch/src/switch.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424

2525
#define BTN_FLASH 0
2626

27-
SinricProSwitch mySwitch(SWITCH_ID);
2827
bool myPowerState = false;
2928
unsigned long lastBtnPress = 0;
3029

@@ -57,8 +56,13 @@ void handleButtonPress() {
5756
myPowerState = true;
5857
}
5958
digitalWrite(LED_BUILTIN, myPowerState?LOW:HIGH); // if myPowerState indicates device turned on: turn on led (builtin led uses inverted logic: LOW = LED ON / HIGH = LED OFF)
60-
Serial.printf("Device %s turned %s (manually via flashbutton)\r\n", mySwitch.getDeviceId(), myPowerState?"on":"off");
59+
60+
// get Switch device back
61+
SinricProSwitch& mySwitch = SinricPro[SWITCH_ID];
62+
// send powerstate event
6163
mySwitch.sendPowerStateEvent(myPowerState); // send the new powerState to SinricPro server
64+
Serial.printf("Device %s turned %s (manually via flashbutton)\r\n", mySwitch.getDeviceId(), myPowerState?"on":"off");
65+
6266
lastBtnPress = actualMillis; // update last button press variable
6367
}
6468
}
@@ -78,10 +82,12 @@ void setupWiFi() {
7882

7983
// setup function for SinricPro
8084
void setupSinricPro() {
85+
// add device to SinricPro
86+
SinricProSwitch& mySwitch = SinricPro.add<SinricProSwitch>(SWITCH_ID);
87+
8188
// set callback function to device
8289
mySwitch.onPowerState(onPowerState);
83-
// add device to SinricPro
84-
SinricPro.add(mySwitch);
90+
8591
// setup SinricPro
8692
SinricPro.begin(SOCKET_AUTH_TOKEN, SIGNING_KEY);
8793
}

0 commit comments

Comments
 (0)