Created
November 6, 2019 13:03
-
-
Save sivar2311/4f5873f72a692d1908be26caf2f67e7c to your computer and use it in GitHub Desktop.
template for multiple device configuration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
typedef struct { | |
byte group; // RC SWITCH Group ID | |
byte device; // RC SWITCH DeviceID | |
bool state; // RC SWITCH state (on/off) | |
} config_t; | |
// std:map to hold device configuration and actual device state | |
// could be stored on SPIFFS and configured via local webserver | |
// in this example it's configured static: | |
std::map<String, config_t> deviceConfig = { | |
// SinricPro deviceId , RC-Group, RC-Device | |
{"YOUR_DEVICE_ID_HERE_0001", {0b10000, 0b10000, false}}, | |
{"YOUR_DEVICE_ID_HERE_0002", {0b10000, 0b01000, false}}, | |
{"YOUR_DEVICE_ID_HERE_0003", {0b10000, 0b00100, false}}, | |
{"YOUR_DEVICE_ID_HERE_0004", {0b10000, 0b00010, false}}, | |
{"YOUR_DEVICE_ID_HERE_0005", {0b10000, 0b00001, false}}, | |
{"YOUR_DEVICE_ID_HERE_0006", {0b01000, 0b10000, false}}, | |
{"YOUR_DEVICE_ID_HERE_0007", {0b01000, 0b01000, false}}, | |
{"YOUR_DEVICE_ID_HERE_0008", {0b01000, 0b00100, false}}, | |
{"YOUR_DEVICE_ID_HERE_0009", {0b01000, 0b00010, false}}, | |
{"YOUR_DEVICE_ID_HERE_0010", {0b01000, 0b00001, false}} | |
}; | |
// callback function | |
bool onPowerState(String deviceId, bool &state) { | |
config_t config = deviceConfig[deviceId]; // get config for device | |
Serial.printf("%s, %d, %d: %s\r\n", deviceId.c_str(), config.group, config.device, state?"on":"off"); // output to serial | |
for (int i=0; i<3; i++) { // send corresponding data to RCLSwitch | |
RCLSwitch.write(config.group, config.device, state); | |
} | |
deviceConfig[deviceId].state = state; // update RC-Device state in config map | |
return true; | |
} | |
void setupSinricPro() { | |
for (auto& config : deviceConfig) { // loop through config map | |
const char* deviceId = config.first.c_str(); //get deviceID from config map | |
SinricProSwitch& mySwitch = SinricPro.add<SinricProSwitch>(deviceId); // add switch device | |
mySwitch.onPowerState(onPowerState); // set callback function | |
} | |
SinricPro.begin(SOCKET_AUTH_TOKEN, SIGNING_KEY); // fire up SinricPro | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment