Can I set this sensor parameters via MQTT callback?

Hi,

The sensor in question is the Sensiron SCD30 CO2 sensor, I am using the Adafruit library. Here is a link to the sketch to avoid an overly long post:

My question is, should it be fine to set a sensor parameter via a MQTT callback function, or any function in fact, that is normally set in setup?

e.g.

void MQTTcallback()
{
Some topic filtering code here....
Save incoming to variable `value`

   if (!scd30.forceRecalibrationWithReference(value)){
     Serial.println("Failed to force recalibration with reference");
     while(1) { delay(10); }
   }
  Serial.print("Forced Recalibration reference: ");
  Serial.print(scd30.getForcedCalibrationReference());
  Serial.println(" ppm");
}

Thanks for any advice!

I would not have other operations in the MQTT callback run. The only code processing to be done in the callback is receive payload, receive topic, signal main that a message has arrived for parsing.

Serial.prints in the callback mess with interrupts. Delay in an interrupt is all kinds of whacked out.

But, yes I can pass sensor setting s in the MQTT payload and send those parameters to a sensor.

1 Like

Ah thanks, I do normally pass to a function but for simplicity did show it this way, did not know it was an issue though.

So in principle it should be fine, good news.
Thanks!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.