Help with looping MQTT data from a sensor

Hello, I have cobbled together a semi working sketch of an ESP-01 and two MPU6050 sensors. The code was frankensteined from a few sketches on the web. Right now the module boots up, connects to wifi and waits for a “1” on a MQTT topic it subscribes to. Once a “1” is received it then sends the sensor data to a MQTT topic. This works. The problem is that it only sends the sensor data when a “1” is detected once. It will send the data each time a “1” is sent, but I want it to send the sensor data until a “0” is detected on the subscribed topic. I cant figure out how to loop it until that happens. I am not very experienced with coding ESPs or Arduinos, but I can cobble something together most of the time. Can you guys help me out? Where am I going wrong?

Sketch attached

dual-mpu-mqtt_activated.ino (8 KB)

If I understand the code correctly the problem is callback() is only called once after "1" is received, and that's where you send the sensor data. Instead you should set a global flag variable:

  if ((char)payload[0] == '1') {
    sendSensorData = true;
  } else {
    sendSensorData = false;

Then send the sensor data in loop() if the flag variable is set to true:

if(sendSensorData == true) {