How to stop a sensor from ThingSpeak

Noora_cube on 24 Jan 2022 (Edited on 11 Feb 2022)
Latest activity Edit by Noora_cube on 11 Feb 2022

Hi, this is my first question here... hope not to bother you all. Is it possible to stop a sensor from collecting data by using ThingSpeak/MQTT broker/MQTT protocol? How? I'm working with a MAX30102 for oxigen and bpm detection and I need to stop the sensor from ThingSpeak or at least this is what I was asked to do. At the moment I can't figure out how to do this except by using the APIkey and the HTTP protocol but my task was to only use MQTT protocol. Hope someone can help me finding a new point of view about this topic/problem.

EDIT: I solved the problem. I used another client, MQTTx to be precise, in order to send messages in a field of control. So, at the beginning I had just two fields (BPM and SpO2), then I added a third field of control. The board WeMos, connected to the sensor MH-ET LIVE MAX30102 was used to process the sensor's data and send them to Thingspeak every 15 seconds wherease the client desktop MQTTx was also connected to ThingSpeak's broker and enbled for both publish and subscribe and I used it to send messages of ON and OFF, literally, as payload for the control field. This messages were passed to the callBack function and the payload was checked in order to change the state of my code, nested in a switch system. Thamk's for the help to you all :) If you're interested to the code and the settings just let me know.

Christopher Stapels
Christopher Stapels on 26 Jan 2022

I cant think of a way to stop the channel ingestion using MQTT, but you could add a flag in a second field about whether that data is good or bad, then filter the data based on that flag.

For example: topic /channels/12345/publish % good data field1=20.3&field2=1 field1=30.2&field2=1 field1=16.9&field2=1 % data written when supposed to be off field1=20.3&field2=0 field1=10.3&field2=0

Can you describe anything more about the project?

Noora_cube
Noora_cube on 27 Jan 2022

Thank you for the answer :) Anyway, about the project: I'm using a WeMos board with ESP8266 and a sensor, MAX30102, to detect heart rate and blood oxigenation. For this project I have to connect the board to ThingSpeak and send data detected by the sensor every 15 seconds to ThingSpeak using the MQTT broker. In order to do this I created one channel with two fields (bpm and SpO2) because I need to visualize data on the main channel view (with the classic graphs). My problem is that I need to stop the sensor from collecting data using the MQTT protocol. I need to find a way to communicate to the sensor "stop collecting data or at least stop sending them to ThingSpeak" and this has to be done with MQTT protocol. But I can't figure out how to do this. I mean, in every moment I should be able to disable (and after enable again) the sensor and I can't set a timer to do this because it must be the user to chose. Your solution is good but if I set a fieldX=valueNotGood and use a publish this valueNotGood will be showed on the graph, I think, and this is not good. I've thought about sending a numeric code via browser (and some lines of code to handle this code and stop the sensor after receiving it) using APIkey but this would be HTPP protocol and not MQTT as I was asked for.

Vinod
Vinod on 27 Jan 2022

Take a look at this example. You can apply a similar technique for your application.