Hi @emelianov
Thanks for your help so far. The loop is working fine and I am able to read the registers I wanted.
I am trying to integrate the write_reg loop with callback mqtt function in a way that when the callback contains "update", the modbus write register loop is executed. I am not able to write more than one register in the loop. Is this because the callback function is executed in the setup() loop? If i run callback in the main loop then it keeps on writing to the registers indefinitely - not what i wanted. I just want to write in registers when i send update command through mqtt.
Could you recommend any step that i can take to resolve the issue? This is the part of the main program causing issue.
Serial.println("Modbus write register request received....");
if (!mb.slave()){
mb.writeHreg(1, WR[w], &writereg[w]);
w++;
if (w >= 6)
w = 0;
Serial.print("write register..........................:");
Serial.println(WR[w]);
Serial.println(writereg[w]);
}
mb.task();
yield();
}