#include #include const char* ssid = "YOUR WIFI ID"; const char* password = "WIFI password"; const char* serverName = "https://app-fab-api-1.onrender.com/api/v1/emotions"; // Define the pin where the touch sensor is connected const int touchPin1 = D0; // GPIO pin const int touchPin2 = D1; // GPIO pin const int touchPin3 = D3; // GPIO pin const int touchPin4 = D4; // GPIO pin const int touchPin5 = D5; // GPIO pin void setup() { Serial.begin(115200); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.println("Connecting to WiFi.."); } Serial.println("Connected to the WiFi network"); // Configure the touch sensor pin as an input pinMode(touchPin1, INPUT); pinMode(touchPin2, INPUT); pinMode(touchPin3, INPUT); pinMode(touchPin4, INPUT); pinMode(touchPin5, INPUT); } void loop() { // Read the state of the touch sensor int touchState1 = digitalRead(touchPin1); int touchState2 = digitalRead(touchPin2); int touchState3 = digitalRead(touchPin3); int touchState4 = digitalRead(touchPin4); int touchState5 = digitalRead(touchPin5); // Print the raw state to the serial monitor // Check if the sensor is touched if (touchState1 == HIGH) { // If the sensor is touched, send 1 Serial.println("Sensor 1 touched!"); // send the emotion sendEmotion(1); } if (touchState2 == HIGH){ // If the sensor is touched, send 1 Serial.println("Sensor 2 touched!"); // send the emotion sendEmotion(2); } if (touchState3 == HIGH){ // If the sensor is touched, send 1 Serial.println("Sensor 3 touched!"); // send the emotion sendEmotion(3); } if (touchState4 == HIGH){ // If the sensor is touched, send 1 Serial.println("Sensor 4 touched!"); // send the emotion sendEmotion(4); } if (touchState5 == HIGH){ // If the sensor is touched, send 1 Serial.println("Sensor 5 touched!"); // send the emotion sendEmotion(5); } else { // If the sensor is not touched, print this message Serial.println("Sensor not touched."); } // Delay a bit to avoid spamming messages delay(500); } void sendEmotion(int emotion) { if (WiFi.status() == WL_CONNECTED) { HTTPClient http; http.begin(serverName); http.addHeader("Content-Type", "application/json"); String httpRequestData = "{\"emotion\":" + String(emotion) + "}"; Serial.println("Sending POST request to server..."); int httpResponseCode = http.POST(httpRequestData); if (httpResponseCode > 0) { String response = http.getString(); Serial.println(httpResponseCode); Serial.println(response); } else { Serial.print("Error on sending POST: "); Serial.println(httpResponseCode); } http.end(); } else { Serial.println("WiFi Disconnected"); } }