johnny-five
johnny-five copied to clipboard
¿Remove device event?
I am connecting a NodeJS (express) application with an arduino 1. I have an analog sensor that reads the soil moisture, and I use the following code to read the value from the sensor:
var analogSensor10HS = new five.Sensor({
pin: "A2", //- attached to pin "A2"
freq: 2000,// - emits data events every xm
threshold: 0, // emits change events when the ADC value has changed by +x/-x
});
app.get("/humidity", function (req, res) {
if (req.query.read==true ) {
analogSensor10HS.on("change", ()=> {
console.log(analogSensor10HS.value)
})
}else{
**STOP DEVICE ON CHANGE EVENT**
}
})
If i access to http:localhost/humidity?read=true, the sensor starts printing values on the display. How can I remove the event to stop printing the values in the console when I access to http:localhost/humidity?read=false ?
Hi, you should use analogSensor10HS.removeAllListeners('change') to remove the event listener