Skip to content

Commit 6dd97ac

Browse files
committed
Merge branch '2.7.6'
2 parents 8e1bf98 + b88b306 commit 6dd97ac

File tree

11 files changed

+218
-353
lines changed

11 files changed

+218
-353
lines changed

changelog.md

+9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
# Changelog
2+
## Version 2.7.6
3+
- Internal changes
4+
removed QueueList.h and use std::queue instead
5+
6+
## Version 2.7.5
7+
- New Examples
8+
- Examples / Light / RGB_LED_Stripe_5050
9+
- Examples / Switch / Relay
10+
211
## Version 2.7.4
312
- New
413
- Speaker & TV `onAdjustVolume` callback changed:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
/*
2+
* If you encounter any issues:
3+
* - check the readme.md at https://github.com/sinricpro/esp8266-esp32-sdk/blob/master/README.md
4+
* - ensure all dependent libraries are installed
5+
* - see https://github.com/sinricpro/esp8266-esp32-sdk/blob/master/README.md#arduinoide
6+
* - see https://github.com/sinricpro/esp8266-esp32-sdk/blob/master/README.md#dependencies
7+
* - open serial monitor and check whats happening
8+
* - check full user documentation at https://sinricpro.github.io/esp8266-esp32-sdk
9+
* - visit https://github.com/sinricpro/esp8266-esp32-sdk/issues and check for existing issues or open a new one
10+
*/
11+
12+
// Uncomment the following line to enable serial debug output
13+
//#define ENABLE_DEBUG
14+
15+
#ifdef ENABLE_DEBUG
16+
#define DEBUG_ESP_PORT Serial
17+
#define NODEBUG_WEBSOCKETS
18+
#define NDEBUG
19+
#endif
20+
21+
#include <Arduino.h>
22+
#ifdef ESP8266
23+
#include <ESP8266WiFi.h>
24+
#endif
25+
#ifdef ESP32
26+
#include <WiFi.h>
27+
#endif
28+
29+
#include "SinricPro.h"
30+
#include "SinricProLight.h"
31+
32+
#define WIFI_SSID "YOUR-WIFI-SSID"
33+
#define WIFI_PASS "YOUR-WIFI-PASS"
34+
#define APP_KEY "YOUR-APPKEY" // Should look like "de0bxxxx-1x3x-4x3x-ax2x-5dabxxxxxxxx"
35+
#define APP_SECRET "YOUR-APPSECRET" // Should look like "5f36xxxx-x3x7-4x3x-xexe-e86724a9xxxx-4c4axxxx-3x3x-x5xe-x9x3-333d65xxxxxx"
36+
#define LIGHT_ID "YOUR-DEVICEID" // Should look like "5dc1564130xxxxxxxxxxxxxx"
37+
#define BAUD_RATE 9600 // Change baudrate to your need for serial log
38+
39+
#define BLUE_PIN D5 // PIN for BLUE Mosfet - change this to your need (D5 = GPIO14 on ESP8266)
40+
#define RED_PIN D6 // PIN for RED Mosfet - change this to your need (D6 = GPIO12 on ESP8266)
41+
#define GREEN_PIN D7 // PIN for GREEN Mosfet - change this to your need (D7 = GPIO13 on ESP8266)
42+
43+
struct { // Stores current device state with following initial values:
44+
bool powerState = false; // initial state is off
45+
int brightness = 100; // initial brightness is set to 100
46+
struct {
47+
byte r = 255; // color
48+
byte g = 255; // is set
49+
byte b = 255; // to white
50+
} color;
51+
} device_state;
52+
53+
// setStripe: sets the mosfets values corresponding to values stored in device_state
54+
void setStripe() {
55+
int rValue = map(device_state.color.r * device_state.brightness, 0, 255 * 100, 0, 1023); // calculate red value and map between 0 and 1023 for analogWrite
56+
int gValue = map(device_state.color.g * device_state.brightness, 0, 255 * 100, 0, 1023); // calculate green value and map between 0 and 1023 for analogWrite
57+
int bValue = map(device_state.color.b * device_state.brightness, 0, 255 * 100, 0, 1023); // calculate blue value and map between 0 and 1023 for analogWrite
58+
59+
if (device_state.powerState == false) { // turn off?
60+
digitalWrite(RED_PIN, LOW); // set
61+
digitalWrite(GREEN_PIN, LOW); // mosfets
62+
digitalWrite(BLUE_PIN, LOW); // low
63+
} else {
64+
analogWrite(RED_PIN, rValue); // write red value to pin
65+
analogWrite(GREEN_PIN, gValue); // write green value to pin
66+
analogWrite(BLUE_PIN, bValue); // write blue value to pin
67+
}
68+
}
69+
70+
bool onPowerState(const String &deviceId, bool &state) {
71+
device_state.powerState = state; // store the new power state
72+
setStripe(); // update the mosfets
73+
return true;
74+
}
75+
76+
bool onBrightness(const String &deviceId, int &brightness) {
77+
device_state.brightness = brightness; // store new brightness level
78+
setStripe(); // update the mosfets
79+
return true;
80+
}
81+
82+
bool onAdjustBrightness(const String &deviceId, int &brightnessDelta) {
83+
device_state.brightness += brightnessDelta; // calculate and store new absolute brightness
84+
brightnessDelta = device_state.brightness; // return absolute brightness
85+
setStripe(); // update the mosfets
86+
return true;
87+
}
88+
89+
bool onColor(const String &deviceId, byte &r, byte &g, byte &b) {
90+
device_state.color.r = r; // store new red value
91+
device_state.color.g = g; // store new green value
92+
device_state.color.b = b; // store new blue value
93+
setStripe(); // update the mosfets
94+
return true;
95+
}
96+
97+
void setup() {
98+
pinMode(RED_PIN, OUTPUT); // set red-mosfet pin as output
99+
pinMode(GREEN_PIN, OUTPUT); // set green-mosfet pin as output
100+
pinMode(BLUE_PIN, OUTPUT); // set blue-mosfet pin as output
101+
102+
Serial.begin(BAUD_RATE); // setup serial
103+
104+
WiFi.begin(WIFI_SSID, WIFI_PASS); // connect wifi
105+
106+
SinricProLight &myLight = SinricPro[LIGHT_ID]; // create light device
107+
myLight.onPowerState(onPowerState); // set PowerState callback
108+
myLight.onBrightness(onBrightness); // set Brightness callback
109+
myLight.onAdjustBrightness(onAdjustBrightness); // set AdjustBrightness callback
110+
myLight.onColor(onColor); // set Color callback
111+
112+
SinricPro.begin(APP_KEY, APP_SECRET); // start SinricPro
113+
}
114+
115+
void loop() {
116+
SinricPro.handle(); // handle SinricPro communication
117+
}
Loading

examples/Switch/Relay/Relay.ino

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* If you encounter any issues:
3+
* - check the readme.md at https://github.com/sinricpro/esp8266-esp32-sdk/blob/master/README.md
4+
* - ensure all dependent libraries are installed
5+
* - see https://github.com/sinricpro/esp8266-esp32-sdk/blob/master/README.md#arduinoide
6+
* - see https://github.com/sinricpro/esp8266-esp32-sdk/blob/master/README.md#dependencies
7+
* - open serial monitor and check whats happening
8+
* - check full user documentation at https://sinricpro.github.io/esp8266-esp32-sdk
9+
* - visit https://github.com/sinricpro/esp8266-esp32-sdk/issues and check for existing issues or open a new one
10+
*/
11+
12+
// Uncomment the following line to enable serial debug output
13+
//#define ENABLE_DEBUG
14+
15+
#ifdef ENABLE_DEBUG
16+
#define DEBUG_ESP_PORT Serial
17+
#define NODEBUG_WEBSOCKETS
18+
#define NDEBUG
19+
#endif
20+
21+
#include <Arduino.h>
22+
#ifdef ESP8266
23+
#include <ESP8266WiFi.h>
24+
#endif
25+
#ifdef ESP32
26+
#include <WiFi.h>
27+
#endif
28+
29+
#include "SinricPro.h"
30+
#include "SinricProSwitch.h"
31+
32+
#define WIFI_SSID "YOUR-WIFI-SSID"
33+
#define WIFI_PASS "YOUR-WIFI-PASS"
34+
#define APP_KEY "YOUR-APP-KEY" // Should look like "de0bxxxx-1x3x-4x3x-ax2x-5dabxxxxxxxx"
35+
#define APP_SECRET "YOUR-APP-SECRET" // Should look like "5f36xxxx-x3x7-4x3x-xexe-e86724a9xxxx-4c4axxxx-3x3x-x5xe-x9x3-333d65xxxxxx"
36+
#define SWITCH_ID "YOUR-DEVICE-ID" // Should look like "5dc1564130xxxxxxxxxxxxxx"
37+
#define BAUD_RATE 9600 // Change baudrate to your need
38+
39+
#define RELAY_PIN D5 // Pin where the relay is connected (D5 = GPIO 14 on ESP8266)
40+
41+
bool onPowerState(const String &deviceId, bool &state) {
42+
digitalWrite(RELAY_PIN, state); // set pin state
43+
return true; // request handled properly
44+
}
45+
46+
void setup() {
47+
pinMode(RELAY_PIN, OUTPUT); // set relay-pin to output mode
48+
WiFi.begin(WIFI_SSID, WIFI_PASS); // start wifi
49+
50+
SinricProSwitch& mySwitch = SinricPro[SWITCH_ID]; // create new switch device
51+
mySwitch.onPowerState(onPowerState); // apply onPowerState callback
52+
SinricPro.begin(APP_KEY, APP_SECRET); // start SinricPro
53+
}
54+
55+
void loop() {
56+
SinricPro.handle(); // handle SinricPro commands
57+
}

examples/Switch/WeMosD1_mini_relay_shield/WeMosD1_mini_relay_shield.ino

-103
This file was deleted.

library.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"maintainer": true
1414
}
1515
],
16-
"version": "2.7.4",
16+
"version": "2.7.6",
1717
"frameworks": "arduino",
1818
"platforms": [
1919
"espressif8266",

library.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=SinricPro
2-
version=2.7.4
2+
version=2.7.6
33
author=Boris Jaeger <[email protected]>
44
maintainer=Boris Jaeger <[email protected]>
55
sentence=Library for https://sinric.pro - simple way to connect your device to alexa

src/SinricPro.h

+8-7
Original file line numberDiff line numberDiff line change
@@ -324,11 +324,12 @@ void SinricProClass::handleRequest(DynamicJsonDocument& requestMessage, interfac
324324
}
325325

326326
void SinricProClass::handleReceiveQueue() {
327-
if (receiveQueue.count() == 0) return;
327+
if (receiveQueue.size() == 0) return;
328328

329-
DEBUG_SINRIC("[SinricPro.handleReceiveQueue()]: %i message(s) in receiveQueue\r\n", receiveQueue.count());
330-
while (receiveQueue.count() > 0) {
331-
SinricProMessage* rawMessage = receiveQueue.pop();
329+
DEBUG_SINRIC("[SinricPro.handleReceiveQueue()]: %i message(s) in receiveQueue\r\n", receiveQueue.size());
330+
while (receiveQueue.size() > 0) {
331+
SinricProMessage* rawMessage = receiveQueue.front();
332+
receiveQueue.pop();
332333
DynamicJsonDocument jsonMessage(1024);
333334
deserializeJson(jsonMessage, rawMessage->getMessage());
334335

@@ -357,11 +358,11 @@ void SinricProClass::handleReceiveQueue() {
357358
void SinricProClass::handleSendQueue() {
358359
if (!isConnected()) return;
359360
if (!baseTimestamp) return;
360-
while (sendQueue.count() > 0) {
361-
DEBUG_SINRIC("[SinricPro:handleSendQueue()]: %i message(s) in sendQueue\r\n", sendQueue.count());
361+
while (sendQueue.size() > 0) {
362+
DEBUG_SINRIC("[SinricPro:handleSendQueue()]: %i message(s) in sendQueue\r\n", sendQueue.size());
362363
DEBUG_SINRIC("[SinricPro:handleSendQueue()]: Sending message...\r\n");
363364

364-
SinricProMessage* rawMessage = sendQueue.pop();
365+
SinricProMessage* rawMessage = sendQueue.front(); sendQueue.pop();
365366

366367
DynamicJsonDocument jsonMessage(1024);
367368
deserializeJson(jsonMessage, rawMessage->getMessage());

src/SinricProConfig.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
// Version Configuration
2626
#define SINRICPRO_VERSION_MAJOR 2
2727
#define SINRICPRO_VERSION_MINOR 7
28-
#define SINRICPRO_VERSION_REVISION 4
28+
#define SINRICPRO_VERSION_REVISION 6
2929
#define SINRICPRO_VERSION STR(SINRICPRO_VERSION_MAJOR) "." STR(SINRICPRO_VERSION_MINOR) "." STR(SINRICPRO_VERSION_REVISION)
3030
#define SINRICPRO_VERSION_STR "SinricPro (v" SINRICPRO_VERSION ")"
3131

0 commit comments

Comments
 (0)