From bf7d8037c7fff5d1ba4517e7ae3e4586b39da385 Mon Sep 17 00:00:00 2001 From: zzzz Date: Fri, 14 Jun 2024 14:59:44 +0200 Subject: [PATCH] add dumb method for change of steeping time --- src/main.cpp | 59 +++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 51 insertions(+), 8 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index b458e5b..fb099de 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -284,7 +284,8 @@ void loop() String payload = teaNet.bundleSteepingTimeChange(currentTea.m_steepingSeconds); Serial.println(payload); smartDisplay.playTeaAnimationPartOne(32, "", "Loading...", "", ""); - JSONVar res = teaNet.httpsPOSTRequest(shuttleServer + "/tea-steeping-time/" + currentTea.m_id, payload); + JSONVar res = teaNet.httpsPOSTRequest(shuttleServer + "/tea-steeping-time-log/" + currentTea.m_id, payload); + JSONVar res2 = teaNet.httpsPOSTRequest(shuttleServer + "/tea-steeping-time/" + currentTea.m_id, payload); // catch possible failure if (res == JSON.parse("{}")) { @@ -292,6 +293,12 @@ void loop() delay(500); break; } + if (res2 == JSON.parse("{}")) + { + smartDisplay.printMsg("TRY AGAIN"); + delay(500); + break; + } state = State::WAIT_FOR_RFID_SCAN; smartStrip.reset(); break; @@ -306,7 +313,8 @@ void loop() String payload = teaNet.bundleSteepingTimeChange(currentTea.m_steepingSeconds); Serial.println(payload); smartDisplay.playTeaAnimationPartOne(32, "", "Loading...", "", ""); - JSONVar res = teaNet.httpsPOSTRequest(shuttleServer + "/tea-steeping-time/" + currentTea.m_id, payload); + JSONVar res = teaNet.httpsPOSTRequest(shuttleServer + "/tea-steeping-time-log/" + currentTea.m_id, payload); + JSONVar res2 = teaNet.httpsPOSTRequest(shuttleServer + "/tea-steeping-time/" + currentTea.m_id, payload); // catch possible failure if (res == JSON.parse("{}")) { @@ -314,6 +322,12 @@ void loop() delay(500); break; } + if (res2 == JSON.parse("{}")) + { + smartDisplay.printMsg("TRY AGAIN"); + delay(500); + break; + } currentTea.m_rfidCode = uid; smartDisplay.resetDisplay(); @@ -328,7 +342,8 @@ void loop() String payload = teaNet.bundleSteepingTimeChange(currentTea.m_steepingSeconds); Serial.println(payload); smartDisplay.playTeaAnimationPartOne(32, "Accepted!", "(perfect)", "", "saving..."); - JSONVar res = teaNet.httpsPOSTRequest(shuttleServer + "/tea-steeping-time/" + currentTea.m_id, payload); + JSONVar res = teaNet.httpsPOSTRequest(shuttleServer + "/tea-steeping-time-log/" + currentTea.m_id, payload); + JSONVar res2 = teaNet.httpsPOSTRequest(shuttleServer + "/tea-steeping-time/" + currentTea.m_id, payload); // catch possible failure if (res == JSON.parse("{}")) { @@ -336,6 +351,12 @@ void loop() delay(1000); break; } + if (res2 == JSON.parse("{}")) + { + smartDisplay.printMsg("TRY AGAIN"); + delay(500); + break; + } state = State::WAIT_FOR_RFID_SCAN; smartDisplay.playTeaAnimationPartTwo(32, "", "Done!", "", ""); smartStrip.reset(); @@ -343,12 +364,18 @@ void loop() if (buttonLeft.isJustPressed()) { // decrease steeping time for next brew // TODO: this should be smarter - currentTea.m_steepingSeconds -= 10; String payload = teaNet.bundleSteepingTimeChange(currentTea.m_steepingSeconds); Serial.println(payload); smartDisplay.playTeaAnimationPartOne(32, "Accepted!", "(shorter)", "", "saving..."); - JSONVar res = teaNet.httpsPOSTRequest(shuttleServer + "/tea-steeping-time/" + currentTea.m_id, payload); + // log old steeping time + JSONVar res = teaNet.httpsPOSTRequest(shuttleServer + "/tea-steeping-time-log/" + currentTea.m_id, payload); + + // now update steeping time for next use + currentTea.m_steepingSeconds += 10; + String payload = teaNet.bundleSteepingTimeChange(currentTea.m_steepingSeconds); + JSONVar res2 = teaNet.httpsPOSTRequest(shuttleServer + "/tea-steeping-time/" + currentTea.m_id, payload); + // catch possible failure if (res == JSON.parse("{}")) { @@ -356,6 +383,12 @@ void loop() delay(1000); break; } + if (res2 == JSON.parse("{}")) + { + smartDisplay.printMsg("TRY AGAIN"); + delay(500); + break; + } state = State::WAIT_FOR_RFID_SCAN; smartDisplay.playTeaAnimationPartTwo(32, "", "Done!", "", ""); smartStrip.reset(); @@ -363,13 +396,17 @@ void loop() if (buttonRight.isJustPressed()) { // increase steeping time for next brew // TODO: this should be smarter - currentTea.m_steepingSeconds += 10; - String payload = teaNet.bundleSteepingTimeChange(currentTea.m_steepingSeconds); Serial.println(payload); smartDisplay.playTeaAnimationPartOne(32, "Accepted!", "(longer)", "", "saving..."); - JSONVar res = teaNet.httpsPOSTRequest(shuttleServer + "/tea-steeping-time/" + currentTea.m_id, payload); + JSONVar res = teaNet.httpsPOSTRequest(shuttleServer + "/tea-steeping-time-log/" + currentTea.m_id, payload); + + // now update steeping time for next use + currentTea.m_steepingSeconds -= 10; + String payload = teaNet.bundleSteepingTimeChange(currentTea.m_steepingSeconds); + JSONVar res2 = teaNet.httpsPOSTRequest(shuttleServer + "/tea-steeping-time/" + currentTea.m_id, payload); + // catch possible failure if (res == JSON.parse("{}")) { @@ -377,6 +414,12 @@ void loop() delay(1000); break; } + if (res2 == JSON.parse("{}")) + { + smartDisplay.printMsg("TRY AGAIN"); + delay(500); + break; + } state = State::WAIT_FOR_RFID_SCAN; smartDisplay.playTeaAnimationPartTwo(32, "", "Done!", "", ""); smartStrip.reset();