Copyright ©

Mongoose OS Forum

ATTENTION! This forum has moved to:

Do not post any new messages.

Read multiple values from UART over modbus (is setDispatcher the right method?)

ashwinkpashwinkp India
edited August 2018 in Mongoose OS


I have a master slave configuration (master being ESP32 running mongoose OS, and slaves being 10 devices) communicating over modbus protocol. I want to read data once per minute.
On Arduino, I used to send a datapacket on UART to the first device, sleep for a few milliseconds, and then read the output on the Rx buffer (so if i dont receive a response, I assume the slave is switched off). and repeat this for the remaining 9 devices.

Is is possible to do something similar on mOS. I was thinking that I would run a timer for 60 seconds, and within this I would write to the UART. It seems that the setDispatcher is only called after the entire timer code is run (so all the 10 responses are bunched together) - and i have no control over which response came for which request.

The other thing i try is to rewrite the setDispatcher code inside the main 60 second Timer block as a nested timer as shown below. But here again, I am unable to send multiple data requests. What is the correct way to go about reading from multiple devices in a serial fashion? Help will be greatly appreciated.

Timer.set(60000, true /* repeat */, function() {
 GPIO.write(pin,1); //trying to set the pin to sending mode
 let pkt=''; //pkt will contain the packet to send over UART
//.... Some code here to create the packet to send
 GPIO.write(pin,0); //reset the pin 

 Timer.set(1000,0,function(){   //this is a work around to wait for 1 second before reading the UART - basically the setDispatcher code
     let ra = UART.readAvail(uartNo);
    if (ra > 0) {
    let data =;
    print("Received UART data:", ra, "Bytes", data);



  • This is a great question. Did you find a way to get this to work?

    Anyone out there that could provide some advice?

Sign In or Register to comment.