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 0000000..5c84d93 Binary files /dev/null and b/yaml parse test/QRFace.png differ diff --git a/yaml parse test/corruptFace.png b/yaml parse test/corruptFace.png new file mode 100644 index 0000000..e907c91 Binary files /dev/null and b/yaml parse test/corruptFace.png differ 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