diff --git a/ESP8266.cpp b/ESP8266.cpp index c3605d7..3c1604b 100644 --- a/ESP8266.cpp +++ b/ESP8266.cpp @@ -807,6 +807,20 @@ bool ESP8266::markPuzzleIncomplete(char *puzzle) { return true; } +bool ESP8266::resetAllPuzzles() { + char *request = "ALL RST"; + char resp[8] = {0}; + int i=0; + for (; i<3; i++) { + if (sendRequest(request, resp)) { + if (resp[0] != '\0' && strcmp(resp, "INVALID")) break; + } + } + // Return false if we send 3 requests with invalid responses + if (i == 3) return false; + return true; +} + bool ESP8266::sendRequest(char *request, char *resp) { if (!createTCP(HOST_NAME, HOST_PORT)) { releaseTCP(); diff --git a/ESP8266.h b/ESP8266.h index a3eb930..437ffbd 100644 --- a/ESP8266.h +++ b/ESP8266.h @@ -403,6 +403,7 @@ class ESP8266 { bool getPuzzleStatus(char *puzzle); bool markPuzzleDone(char *puzzle); bool markPuzzleIncomplete(char *puzzle); + bool resetAllPuzzles(); private: @@ -474,7 +475,6 @@ class ESP8266 { bool sATCIPSERVER(uint8_t mode, uint32_t port = 333); bool sATCIPSTO(uint32_t timeout); bool sendRequest(char *request, char *buffer); - void ESP8266::mySend(const uint8_t *buffer, uint32_t len); /* diff --git a/ESP8266EscapeRoom.ino b/ESP8266EscapeRoom.ino index 696e084..b136dba 100644 --- a/ESP8266EscapeRoom.ino +++ b/ESP8266EscapeRoom.ino @@ -48,17 +48,35 @@ void loop(void) // MRS = Morse code // TIM = Time machine // GRS = Gears - Serial.println("Mark books done:"); + Serial.print("Mark books done: "); Serial.println(wifi.markPuzzleDone("BKS")); delay(50); - Serial.println("Books status:"); + Serial.print("Books status: "); Serial.println(wifi.getPuzzleStatus("BKS")); delay(50); - Serial.println("Mark books incomplete:"); + Serial.print("Mark books incomplete: "); Serial.println(wifi.markPuzzleIncomplete("BKS")); delay(50); - Serial.println("Books status:"); + Serial.print("Books status: "); Serial.println(wifi.getPuzzleStatus("BKS")); delay(5000); + + // Reset all puzzles + Serial.print("Resetting all: "); + Serial.println(wifi.resetAllPuzzles()); + delay(50); + // Check them + Serial.print("Books status: "); + Serial.println(wifi.getPuzzleStatus("BKS")); + delay(50); + Serial.print("Morse status: "); + Serial.println(wifi.getPuzzleStatus("MRS")); + delay(50); + Serial.print("Time machine status: "); + Serial.println(wifi.getPuzzleStatus("TIM")); + delay(50); + Serial.print("Gears status: "); + Serial.println(wifi.getPuzzleStatus("GRS")); + delay(5000); } diff --git a/escape-room-server.py b/escape-room-server.py index 4e6807b..66d973d 100644 --- a/escape-room-server.py +++ b/escape-room-server.py @@ -60,7 +60,15 @@ def puzzle_get(puzzle): def puzzle_reset(puzzle): + if puzzle == "ALL": + print("RESETTING ALL PUZZLES") + for feed in list(PUZZLE_FEEDS.keys()): + aio.send(PUZZLE_FEEDS[feed], "0 RST") + status[feed] = "0 RST" + return "ALL RST" + print("reset", puzzle) + data = aio.receive(PUZZLE_FEEDS[puzzle]) data = data.value.split() aio.send(PUZZLE_FEEDS[puzzle], str(data[0]) + " RST") @@ -95,7 +103,7 @@ def puzzle_reset(puzzle): data = conn.recv(16).decode() try: puzzle, command = data.split() - if puzzle not in PUZZLE_FEEDS or command not in COMMAND_FUNCTIONS: + if (puzzle not in PUZZLE_FEEDS and puzzle != "ALL") or command not in COMMAND_FUNCTIONS: print("Invalid command received:", data) conn.send("INVALID".encode()) conn.close()