const { Analysis, Device } = require('@tago-io/sdk');const axios = require('axios'); // Import axios libraryasync 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:
-
void setupWebServer() {
-
server.on(“/command”, HTTP_POST, (AsyncWebServerRequest *request){
-
String command = request->arg("command"); -
// Print the received command to the serial monitor -
Serial.print("Received command: "); -
Serial.println(command); -
if (command == "waterpumpON") { -
digitalWrite(RELAY\_PIN, LOW); -
request->send(200, "text/plain", "Water pump turned ON"); -
} else if (command == "waterpumpOFF") { -
digitalWrite(RELAY\_PIN, HIGH); -
request->send(200, "text/plain", "Water pump turned OFF"); -
} else { -
request->send(400, "text/plain", "Invalid command"); -
} -
});
-
server.begin();
-
Serial.println(“HTTP server started”);
-
Serial.println("Server started on IP: " + WiFi.localIP().toString());
-
}
I am stuck i will paypal u i just need help please please please PLEASE PLEASE