CANNOT SEND COMMAND TO ESP32

CANNOT SEND COMMAND TO ESP32

  1. const { Analysis, Device } = require('@tago-io/sdk');
    const axios = require('axios'); // Import axios library

    async function startAnalysis(context, scope) {
        console.log('Analysis started, preparing command...');
         
        // Command to send to the device
        const command = {
                command: 'waterpumpON'
        };


        console.log('Command prepared:', command);

            const deviceIP = '192.168.1.245'; // Replace with your ESP32 device's IP address
            const port = 80; // Replace with the port number of your ESP32 HTTP server

            try {
                console.log('Sending command to device...');
                const response = await axios.post(`http://${deviceIP}:${port}`, command);
                console.log('Command sent to turn on water pump');
                console.log('Response:', response.data);
            } catch (error) {
                console.error('Error sending command:', error.message);
            }
        }

    module.exports = new Analysis(startAnalysis);

What do i have to do i am stuck please please please help. If someone can help fix this i will paypal u



Adruino code:

  1. void setupWebServer() {
  2.   server.on("/command", HTTP_POST, [](AsyncWebServerRequest *request){
  3.     String command = request->arg("command");
  4.     // Print the received command to the serial monitor
  5.     Serial.print("Received command: ");
  6.     Serial.println(command);
  7.     
  8.     if (command == "waterpumpON") {
  9.       digitalWrite(RELAY_PIN, LOW);
  10.       request->send(200, "text/plain", "Water pump turned ON");
  11.     } else if (command == "waterpumpOFF") {
  12.       digitalWrite(RELAY_PIN, HIGH);
  13.       request->send(200, "text/plain", "Water pump turned OFF");
  14.     } else {
  15.       request->send(400, "text/plain", "Invalid command");
  16.     }
  17.   });
  18.   server.begin();
  19.   Serial.println("HTTP server started");
  20.   Serial.println("Server started on IP: " + WiFi.localIP().toString());

  21. }

I am stuck i will paypal u i just need help please please please PLEASE PLEASE