From 96143d01890d0a188923697fe109e4fb6078637c Mon Sep 17 00:00:00 2001 From: Roy-vl Date: Mon, 24 Jun 2024 20:44:44 +0200 Subject: [PATCH] Added corrupt and QR code faces and .png and in the yaml. --- .../mqtt_single_multifunction button.ino | 132 ++++++++++++++++++ ESP/mqtt_test/mqtt_test.ino | 2 +- yaml parse test/QRFace.png | Bin 0 -> 799 bytes yaml parse test/corruptFace.png | Bin 0 -> 327 bytes yaml parse test/testAnimationYaml.yaml | 35 ++++- 5 files changed, 167 insertions(+), 2 deletions(-) create mode 100644 ESP/mqtt_single_multifunction button/mqtt_single_multifunction button.ino create mode 100644 yaml parse test/QRFace.png create mode 100644 yaml parse test/corruptFace.png diff --git a/ESP/mqtt_single_multifunction button/mqtt_single_multifunction button.ino b/ESP/mqtt_single_multifunction button/mqtt_single_multifunction button.ino new file mode 100644 index 0000000..c7fddbf --- /dev/null +++ b/ESP/mqtt_single_multifunction button/mqtt_single_multifunction button.ino @@ -0,0 +1,132 @@ +#include +#include +#include "Button2.h" + +const int mainTriggerPin = 25; // GPIO pins to check for shorting and wake-up + +Button2 mainTriggerButton; + +const char* ssid = "ProotAP"; +const char* password = "prootproot!"; +const char* mqttServer = "192.168.10.1"; +const int mqttPort = 1883; +const char* mqttTopic = "test"; + + +WiFiClient wifiClient; +PubSubClient mqttClient(wifiClient); + +TaskHandle_t mqttTaskHandle = NULL; + + + +void setupWiFi() { + WiFi.begin(ssid, password); + while (WiFi.status() != WL_CONNECTED) { + delay(1000); + Serial.println("Connecting to WiFi..."); + } + Serial.println("Connected to WiFi"); +} + +void callback(char* topic, byte* payload, unsigned int length) { + // This function is called when a message is received from the MQTT server + // Add your desired code here to handle the received message +} + +void reconnectMQTT() { + while (!mqttClient.connected()) { + Serial.println("Connecting to MQTT server..."); + if (mqttClient.connect("ESP32Client")) { + Serial.println("Connected to MQTT server"); + mqttClient.subscribe(mqttTopic); + } else { + Serial.print("MQTT connection failed, rc="); + Serial.print(mqttClient.state()); + Serial.println(" Retrying in 5 seconds..."); + delay(5000); + } + } +} + + +void setup() { + Serial.begin(115200); + delay(50); + + setupWiFi(); + mqttClient.setServer(mqttServer, mqttPort); + mqttClient.setCallback(callback); + + + mainTriggerButton.begin(mainTriggerPin); + mainTriggerButton.setDebounceTime(2); + mainTriggerButton.setLongClickTime(250); + mainTriggerButton.setClickHandler(mainTriggerHandler); + mainTriggerButton.setLongClickHandler(mainTriggerHandler); // this will only be called upon release + // mainTriggerButton.setLongClickDetectedHandler(mainTriggerHandler); // this will only be called upon detection + mainTriggerButton.setDoubleClickHandler(mainTriggerHandler); + mainTriggerButton.setTripleClickHandler(mainTriggerHandler); + + + //xTaskCreatePinnedToCore( + // mqttTask, // Task function + // "mqttTask", // Task name + // 4096, // Stack size (bytes) + // NULL, // Task parameter + // 1, // Task priority + // &mqttTaskHandle, // Task handle + // 1 // Task core (0 or 1) + //); +} + +int lastInput = 0; +String message = ""; + +void mainTriggerHandler(Button2& btn) { + switch (btn.getType()) { + case single_click: + Serial.print("single "); + if (lastInput < 5){ + lastInput = lastInput + 1; + } else { + lastInput = 1; + } + message = "Butn_000" + String(lastInput) + "_0001"; + mqttClient.publish(mqttTopic, message.c_str()); + break; + case double_click: + Serial.print("double "); + message = "Butn_0003_0001"; + lastInput = 3; + mqttClient.publish(mqttTopic, message.c_str()); + break; + case triple_click: + Serial.print("triple "); + message = "Butn_0002_0001"; + lastInput = 2; + mqttClient.publish(mqttTopic, message.c_str()); + break; + case long_click: + Serial.print("long"); + message = "Butn_0004_0001"; + lastInput = 4; + mqttClient.publish(mqttTopic, message.c_str()); + break; + } + Serial.print("click"); + Serial.print(" ("); + Serial.print(btn.getNumberOfClicks()); + Serial.println(")"); + Serial.println("sent: " + message); +} + +void loop() { + if (!mqttClient.connected()) { + reconnectMQTT(); + } + + mainTriggerButton.loop(); + + mqttClient.loop(); +} diff --git a/ESP/mqtt_test/mqtt_test.ino b/ESP/mqtt_test/mqtt_test.ino index ecac6e0..0c4ee1d 100644 --- a/ESP/mqtt_test/mqtt_test.ino +++ b/ESP/mqtt_test/mqtt_test.ino @@ -4,7 +4,7 @@ const char* ssid = "ProotAP"; const char* password = "prootproot!"; -const char* mqttServer = "10.1.1.15"; +const char* mqttServer = "192.168.10.1"; const int mqttPort = 1883; const char* mqttTopic = "test"; diff --git a/yaml parse test/QRFace.png b/yaml parse test/QRFace.png new file mode 100644 index 0000000000000000000000000000000000000000..5c84d9302d121b8f50c8079e47d1a40e79ca924f GIT binary patch literal 799 zcmV+)1K|9LP)Px#1ZP1_K>z@;j|==^1poj5OHfQyMF0Q*|KR}t|NsA#00II62?+@S0RjI0{{8*^ z`uh3^2nhWA{09dI0|NsK3k&=E`vnCB_V)G$1_lZW3i$Z=_xJY%1O)#82>JQ>1V*Dc z00009a7bBm000ie000ie0hKEb8vpr_kYq| z*@98Jg;0|I+IJ2yadfO}S(Z)zd75t^{%!{U8wd!aS-yAT?Jl>bOv(Adk~5R0va@~b z5eQg7_wGc;9X=Q{v8pNY@KXv`s=J)j!IuTZc#Y_qB}}i3nKGW4_(1A$7uMuG5Z1oW z6Qc#uIY(H6==dW*6Ipg15D;Tsi0*s5GwuQ^u~F9jFRBMD0g*sbH<+OhbVc+p2b+wk zV%A2SOvl4ZwyNnBJ>>xbm$&}s5nMor5qO_9=AWXcH#2<7ca;`f&GkjFPHhk7o0 z2o?y4_9>XebeJ$}k3d2qND+hcg>~R@j?o4Px?uAeTq6~IGpNzzwP7;>$9EDSKpBy@ zg51X|qAw7TmeqmJ0SU*Z!=#0JaI0upkY|!_TM+NW!u| zeVKrSXjfqyvR?xV?g!(*>223U71xEet zH=+@DfRyt~_8gdMuLI#Jp6j~qG&kPjEbztf!vM3#{iuIw4p;YjMKAk*r5nKcmi`y8 de$>ARqTlfk7Td%o#cluq002ovPDHLkV1m~cT~`1A literal 0 HcmV?d00001 diff --git a/yaml parse test/corruptFace.png b/yaml parse test/corruptFace.png new file mode 100644 index 0000000000000000000000000000000000000000..e907c912e90bc790d2b60e857e39928a04ef5af3 GIT binary patch literal 327 zcmeAS@N?(olHy`uVBq!ia0vp^4M42G!VDxecyh&n6k~CayA#8@b22Z19F}xPUq=Rp zjs4tz5?O(Ko&cW^S0Md=3d8@04F4H8ro~sR0`fTvJR*x382FBWFymBhK53xf5letiaQ9{v*={$0?jTmH+Ra>Yo(AbtCBBt$Cjs^vdPiSnjJZxyBo@wM?AL zpy%Y%;5dOxfn~K{2t(q5vkmW#mc4oT(oC!2howWP|2^~c4`0qkcLY0Fg?~E9G$lYL z*6HI3HkLE{${TMntYOrv{J&#=U3iiH%_8WMtE_aUw|w-_(dlR4dNH}~UY#Y=2PU&60&8vw Sd@%s}hr!d;&t;ucLK6UfQ+Vb8 literal 0 HcmV?d00001 diff --git a/yaml parse test/testAnimationYaml.yaml b/yaml parse test/testAnimationYaml.yaml index 359d737..9990fc3 100644 --- a/yaml parse test/testAnimationYaml.yaml +++ b/yaml parse test/testAnimationYaml.yaml @@ -63,6 +63,39 @@ animations: source_file: dizzyFace.png duration: 1 + - name: set corrupt + description: Animation to be corrupt + loop_count: 1 + + trigger: Butn_0006_0001 + + overrideable: true + + graphics: + - type: transition + to_file: corruptFace.png + duration: 10 + - type: image + source_file: corruptFace.png + duration: 1 + + - name: set QR + description: Animation to be confused + loop_count: 1 + + trigger: Butn_0007_0001 + + overrideable: true + + graphics: + - type: transition + to_file: QRFace.png + duration: 10 + - type: image + source_file: QRFace.png + duration: 1 + + - name: set angry description: Animation to be confused loop_count: 1 @@ -124,7 +157,7 @@ animations: description: Animation for a blink loop_count: 1 - trigger: blinkTimer #Button 2 pressed + trigger: blinkTimer # frigeer to be set by timer, not currently in use overrideable: true # blink can be interupted at any time