get scene status on bootup
This commit is contained in:
parent
070364018e
commit
8c47d1c0d3
1 changed files with 29 additions and 8 deletions
37
src/main.cpp
37
src/main.cpp
|
@ -79,6 +79,9 @@ void handleWebSocketEvent(WStype_t type, uint8_t * payload, size_t length) {
|
|||
// Find out if we need authentication
|
||||
#ifdef OBS_PASS
|
||||
webSocket.sendTXT("{\"request-type\":\"GetAuthRequired\",\"message-id\":\"1\"}");
|
||||
#else
|
||||
webSocket.sendTXT("{\"request-type\":\"GetCurrentScene\",\"message-id\":\"3\"}");
|
||||
webSocket.sendTXT("{\"request-type\":\"GetPreviewScene\",\"message-id\":\"4\"}");
|
||||
#endif
|
||||
break;
|
||||
|
||||
|
@ -137,6 +140,8 @@ void handleWebSocketEvent(WStype_t type, uint8_t * payload, size_t length) {
|
|||
} else if (doc.containsKey("message-id") && doc["message-id"] == "2") {
|
||||
if (strcmp(doc["status"], "ok") == 0) {
|
||||
Serial.println("[OBS] authentication successful");
|
||||
webSocket.sendTXT("{\"request-type\":\"GetCurrentScene\",\"message-id\":\"3\"}");
|
||||
webSocket.sendTXT("{\"request-type\":\"GetPreviewScene\",\"message-id\":\"4\"}");
|
||||
} else {
|
||||
Serial.println("[OBS] authentication FAILED");
|
||||
set_error();
|
||||
|
@ -144,7 +149,7 @@ void handleWebSocketEvent(WStype_t type, uint8_t * payload, size_t length) {
|
|||
break;
|
||||
}
|
||||
#endif
|
||||
if (doc.containsKey("update-type")) {
|
||||
if (doc.containsKey("sources")) {
|
||||
bool my_source_in_current_event = false;
|
||||
|
||||
for (uint8_t i = 0; i < doc["sources"].size(); i++) {
|
||||
|
@ -154,24 +159,28 @@ void handleWebSocketEvent(WStype_t type, uint8_t * payload, size_t length) {
|
|||
}
|
||||
}
|
||||
|
||||
if (strcmp(doc["update-type"], "SwitchScenes") == 0) {
|
||||
if ((doc.containsKey("update-type") &&strcmp(doc["update-type"], "SwitchScenes") == 0) || (doc.containsKey("message-id") && strcmp(doc["message-id"], "3") == 0)) {
|
||||
Serial.println("[OBS] program event");
|
||||
if (my_source_in_current_event) {
|
||||
is_currently_live = true;
|
||||
} else {
|
||||
is_currently_live = false;
|
||||
}
|
||||
} else if (strcmp(doc["update-type"], "PreviewSceneChanged") == 0) {
|
||||
} else if ((doc.containsKey("update-type") &&strcmp(doc["update-type"], "PreviewSceneChanged") == 0) || (doc.containsKey("message-id") && strcmp(doc["message-id"], "4") == 0)) {
|
||||
Serial.println("[OBS] preview event");
|
||||
if (my_source_in_current_event) {
|
||||
is_currently_preview = true;
|
||||
} else {
|
||||
is_currently_preview = false;
|
||||
}
|
||||
} else if (strcmp(doc["update-type"], "Exiting") == 0) {
|
||||
Serial.println("[OBS] quit");
|
||||
is_currently_preview = false;
|
||||
is_currently_live = false;
|
||||
} else if (strcmp(doc["update-type"], "StudioModeSwitched") == 0 && doc["new-state"] == false) {
|
||||
is_currently_preview = false;
|
||||
}
|
||||
} else if (strcmp(doc["update-type"], "StudioModeSwitched") == 0 && !doc["new-state"]) {
|
||||
Serial.println("[OBS] studio mode disabled");
|
||||
is_currently_preview = false;
|
||||
}
|
||||
|
||||
if (is_currently_live) {
|
||||
|
@ -187,6 +196,14 @@ void handleWebSocketEvent(WStype_t type, uint8_t * payload, size_t length) {
|
|||
case WStype_PONG:
|
||||
Serial.println("[WS] ping/pong");
|
||||
break;
|
||||
|
||||
case WStype_BIN:
|
||||
case WStype_ERROR:
|
||||
case WStype_FRAGMENT_TEXT_START:
|
||||
case WStype_FRAGMENT_BIN_START:
|
||||
case WStype_FRAGMENT:
|
||||
case WStype_FRAGMENT_FIN:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -199,12 +216,14 @@ void setup() {
|
|||
FastLED.setBrightness(LED_BRIGHTNESS);
|
||||
|
||||
set_error();
|
||||
delay(500);
|
||||
delay(100);
|
||||
set_idle();
|
||||
delay(500);
|
||||
delay(100);
|
||||
set_error();
|
||||
delay(500);
|
||||
delay(100);
|
||||
set_idle();
|
||||
delay(100);
|
||||
set_error();
|
||||
|
||||
Serial.printf("[Tally] connecting to wifi ssid: %s\n", WIFI_SSID);
|
||||
|
||||
|
@ -219,6 +238,8 @@ void setup() {
|
|||
Serial.print("[Tally] connected to wifi, ip address ");
|
||||
Serial.println(WiFi.localIP());
|
||||
|
||||
set_idle();
|
||||
|
||||
Serial.println("[Tally] connecting to OBS");
|
||||
webSocket.begin(OBS_HOST, OBS_PORT, "/");
|
||||
webSocket.onEvent(handleWebSocketEvent);
|
||||
|
|
Loading…
Reference in a new issue