Skip to content

Commit a5cefe6

Browse files
committed
Merge branch 'dev-2.9.0'
2 parents f5e5d1e + 86abb97 commit a5cefe6

File tree

796 files changed

+35665
-11718
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

796 files changed

+35665
-11718
lines changed

Doxyfile

Lines changed: 175 additions & 80 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11

2-
# SinricPro (ESP8266 / ESP32 SDK) {#mainpage}
2+
# SinricPro (ESP8266 / ESP32 SDK)
3+
4+
## Note
5+
1. Use the latest ESP Arduino Core!
6+
2. Use the latest WebSocktes library!
37

48
## Installation
59

@@ -23,7 +27,7 @@
2327

2428
## Dependencies
2529
[ArduinoJson](https://github.com/bblanchon/ArduinoJson) by Benoit Blanchon (minimum Version 6.12.0)
26-
[WebSockets](https://github.com/Links2004/arduinoWebSockets) by Markus Sattler (minimum Version 2.2.0)
30+
[WebSockets](https://github.com/Links2004/arduinoWebSockets) by Markus Sattler (minimum Version 2.3.2)
2731

2832
---
2933

@@ -38,26 +42,28 @@ See [examples](https://github.com/sinricpro/esp8266-esp32-sdk/tree/master/exampl
3842
---
3943

4044
## Usage
41-
#### Include SinricPro-Library (SinricPro.h) and SinricPro-Device-Libraries (eg. SinricProSwitch.h)
45+
### Include SinricPro-Library (SinricPro.h) and SinricPro-Device-Libraries (eg. SinricProSwitch.h)
4246
```C++
4347
#include <SinricPro.h>
4448
#include <SinricProSwitch.h>
4549
```
46-
#### Define your credentials from SinricPro-Portal (portal.sinric.pro)
50+
51+
### Define your credentials from SinricPro-Portal (portal.sinric.pro)
4752
```C++
4853
#define APP_KEY "YOUR-APP-KEY" // Should look like "de0bxxxx-1x3x-4x3x-ax2x-5dabxxxxxxxx"
4954
#define APP_SECRET "YOUR-APP-SECRET" // Should look like "5f36xxxx-x3x7-4x3x-xexe-e86724a9xxxx-4c4axxxx-3x3x-x5xe-x9x3-333d65xxxxxx"
5055
#define SWITCH_ID "YOUR-DEVICE-ID" // Should look like "5dc1564130xxxxxxxxxxxxxx"
5156
```
5257
53-
#### Define callback routine(s)
58+
### Define callback routine(s)
5459
```C++
5560
bool onPowerState(const String &deviceId, bool &state) {
5661
Serial.printf("device %s turned %s\r\n", deviceId.c_str(), state?"on":"off");
5762
return true; // indicate that callback handled correctly
5863
}
5964
```
60-
#### In setup()
65+
66+
### In setup()
6167
```C++
6268
// create and add a switch to SinricPro
6369
SinricProSwitch& mySwitch = SinricPro[SWITCH_ID];
@@ -68,7 +74,7 @@ bool onPowerState(const String &deviceId, bool &state) {
6874

6975
```
7076

71-
#### In loop()
77+
### In loop()
7278
```C++
7379
SinricPro.handle();
7480
```

changelog.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
# Changelog
2+
## Version 2.9.0
3+
New:
4+
- support custom devices
5+
- check for minimum websockets version
6+
7+
Fixed:
8+
- MultiRelays example
9+
210
## Version 2.8.1
311
- New Example: MultiRelays_advance (see examples/Relay)
412
- Moved existing relay example to new folder (examples/Relay)

doc-examples/callbacks.cpp

Lines changed: 71 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ bool onPowerState(const String &deviceId, bool &state) {
1616
}
1717
//! [onPowerState]
1818

19+
//! [onToggleState]
20+
bool onToggleState(const String &deviceId, const String &instance, bool &state) {
21+
Serial.printf("Device %s state \"%s\" turned %s\r\n", deviceId.c_str(), instance.c_str(), state ? "on" : "off");
22+
return true; // request handled properly
23+
}
24+
//! [onToggleState]
25+
1926
//! [onPowerLevel]
2027
bool onPowerLevel(const String &deviceId, int &powerLevel) {
2128
Serial.printf("Device %s powerlevel %d\r\n", deviceId.c_str(), powerLevel);
@@ -91,22 +98,40 @@ bool onDecreaseColorTemperature(const String &deviceId, int &colorTemperature) {
9198

9299
//! [onRangeValue]
93100
bool onRangeValue(const String &deviceId, int &rangeValue) {
94-
Serial.printf("Device %s range value has been set to %d\r\n", rangeValue);
101+
Serial.printf("Device %s range value has been set to %d\r\n", deviceId.c_str(), rangeValue);
95102
return true; // request handled properly
96103
}
97104
//! [onRangeValue]
98105

106+
//! [onRangeValueGeneric]
107+
bool onRangeValue(const String &deviceId, const String &instance, int &rangeValue) {
108+
Serial.printf("Device %s range value for %s has been set to %d\r\n", deviceId.c_str(), instance.c_str(), rangeValue);
109+
return true; // request handled properly
110+
}
111+
//! [onRangeValueGeneric]
112+
99113
//! [onAdjustRangeValue]
100114
int globalRangeValue;
101115

102116
bool onAdjustRangeValue(const String &deviceId, int &rangeValueDelta) {
103117
globalRangeValue += rangeValue; // calculate absolute rangeValue
104-
Serial.printf("Device %s range value has been changed about %i to %d\r\n", rangeValueDelta, globalRangeValue);
118+
Serial.printf("Device %s range value has been changed about %i to %d\r\n", deviceId.c_str(), rangeValueDelta, globalRangeValue);
105119
rangeValueDelta = globalRangeValue; // return absolute rangeValue
106120
return true; // request handled properly
107121
}
108122
//! [onAdjustRangeValue]
109123

124+
//! [onAdjustRangeValueGeneric]
125+
int globalRangeValue;
126+
127+
bool onAdjustRangeValue(const String &deviceId, const String& instance, int &rangeValueDelta) {
128+
globalRangeValue += rangeValueDelta; // calculate absolute rangeValue
129+
Serial.printf("Device %s range value for %s has been changed about %i to %d\r\n", deviceId.c_str(), instance.c_str(), rangeValueDelta, globalRangeValue);
130+
rangeValueDelta = globalRangeValue; // return absolute rangeValue
131+
return true; // request handled properly
132+
}
133+
//! [onAdjustRangeValueGeneric]
134+
110135
//! [onTargetTemperature]
111136
bool onTargetTemperature(const String &deviceId, float &targetTemp) {
112137
Serial.printf("Device %s target temperature set to %f\r\n", deviceId.c_str(), targetTemp);
@@ -160,61 +185,39 @@ bool onMute(const String &deviceId, bool &mute) {
160185

161186
//! [onMediaControl]
162187
bool onMediaControl(const String &deviceId, String &control) {
163-
Serial.printf("Device %s: %s\r\n", deviceId.c_str(), control);
188+
Serial.printf("Device %s: %s\r\n", deviceId.c_str(), control.c_str());
164189
return true; // request handled properly
165190
}
166191
//! [onMediaControl]
167192

168193
//! [onSetBands]
194+
std::map<String, int> equalizerBands;
195+
169196
bool onSetBands(const String &deviceId, String &bands, int &level) {
170197
Serial.printf("Device %s bands %s set to %d\r\n", deviceId.c_str(), bands.c_str(), level);
198+
equalizerBands[bands] = level;
171199
return true; // request handled properly
172200
}
173201
//! [onSetBands]
174202

175203
//! [onAdjustBands]
176-
int globalBass;
177-
int globalMidrange;
178-
int globalTrebble;
204+
std::map<String, int> equalizerBands;
179205

180206
bool onAdjustBands(const String &deviceId, String &bands, int &levelDelta) {
181-
if (bands == "BASS") {
182-
globalBass += levelDelta; // calculate absolute bass level
183-
levelDelta = globalBass; // return absolute bass level
184-
}
185-
if (bands == "MIDRANGE") {
186-
globalMidrange += levelDelta; // calculate absolute midrange level
187-
levelDelta = globalMidrange; // return absolute midrange level
188-
}
189-
if (bands == "TREBBLE") {
190-
globalMidrange += levelDelta; // calculate absolute trebble level
191-
levelDelta = globalMidrange; // return absolute trebble level
192-
}
193-
Serial.printf("Device %s bands set to\r\n - BASS: %d\r\n - MIDRANGE: %d\r\n - TREBBLE: %d\r\n", deviceId.c_str(), globalBass, globalMidrange, globalTrebble);
207+
equalizerBands[bands] += levelDelta; // calculate absolute bands level
208+
Serial.printf("Device %s bands %s changed about %d to %d\r\n", deviceId.c_str(), bands.c_str(), levelDelta, equalizerBands[bands]);
209+
levelDelta = equalizerBands[bands]; // return absolute bands level
194210
return true; // request handled properly
195211
}
196212
//! [onAdjustBands]
197213

198214

199215
//! [onResetBands]
200-
int globalBass;
201-
int globalMidrange;
202-
int globalTrebble;
203-
204-
bool onAdjustBands(const String &deviceId, String &bands, int &level) {
205-
if (bands == "BASS") {
206-
globalBass = 0; // reset bass level to 0
207-
level = globalBass; // return bass level
208-
}
209-
if (bands == "MIDRANGE") {
210-
globalMidrange = 0; // reset midrange level to 0
211-
level = globalMidrange; // return midrange level
212-
}
213-
if (bands == "TREBBLE") {
214-
globalMidrange = 0; // reset trebble level to 0
215-
level = globalMidrange; // return trebble level
216-
}
217-
Serial.printf("Device %s bands reset to\r\n - BASS: %d\r\n - MIDRANGE: %d\r\n - TREBBLE: %d\r\n", deviceId.c_str(), globalBass, globalMidrange, globalTrebble);
216+
std::map<String, int> equalizerBands;
217+
218+
bool onResetBands(const String &deviceId, String &bands, int &level) {
219+
equalizerBands[bands] = 0; // reset bands level to 0
220+
Serial.printf("Device %s bands %s reset to %d\r\n", deviceId.c_str(), bands.c_str(), equalizerBands[bands]);
218221
return true; // request handled properly
219222
}
220223
//! [onResetBands]
@@ -227,6 +230,13 @@ bool onSetMode(const String &deviceId, String &mode) {
227230
}
228231
//! [onSetMode]
229232

233+
//! [onSetModeGeneric]
234+
bool onSetMode(const String &deviceId, const String &instance, String &mode) {
235+
Serial.printf("Device %s mode %s set to %s\r\n", deviceId.c_str(), instance.c_str(), mode);
236+
return true; // request handled properly
237+
}
238+
//! [onSetModeGeneric]
239+
230240
//! [onChangeChannel]
231241
// channelNames used to convert channelNumber into channelName
232242
// please put in your TV channel names
@@ -402,3 +412,27 @@ bool onDoorState(const String &deviceId, bool &doorState) {
402412
}
403413
//! [onDoorState]
404414

415+
//! [onKeystroke]
416+
bool onKeystroke(const String& deviceId, String &keystroke) {
417+
Serial.printf("Device %s, key %s pressed\r\n", deviceId.c_str(), keystroke.c_str());
418+
return true;
419+
}
420+
//! [onKeystroke]
421+
422+
//! [onSetPercentage]
423+
bool onSetPercentage(const String &deviceId, int &percentage) {
424+
Serial.printf("Device %s percentage %d\r\n", deviceId.c_str(), percentage);
425+
return true; // request handled properly
426+
}
427+
//! [onSetPercentage]
428+
429+
//! [onAdjustPercentage]
430+
int absolutePercentage;
431+
432+
bool onAdjustPercentage(const String &deviceId, int &percentageDelta) {
433+
absolutePercentage += percentageDelta; // calculate absolute percentage
434+
Serial.printf("Device %s percentage changed about %i to %d\r\n", deviceId.c_str(), percentageDelta, absolutePercentage);
435+
percentageDelta = absolutePercentage; // return absolute percentage
436+
return true; // request handled properly
437+
}
438+
//! [onAdjustPercentage]

doc-examples/documentation.dox

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
* @defgroup SinricPro SinricPro
3+
* @brief Main instance of SinricProClass
4+
*
5+
* @defgroup Devices Devices
6+
* @brief Available devices
7+
*
8+
* @defgroup Capabilities Capabilities
9+
* @brief Capabilities
10+
*
11+
**/

0 commit comments

Comments
 (0)