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);