B4R Question B4R complex multitask sketch structure

peacemaker

Expert
Licensed User
Longtime User
HI, All

Regular programming for "big brothers" with enough resources to have async multitask app structure - i have troubles to plan B4R sketch (mostly for ESP8266) for correct structure:
  • each interface\function to be in a separate module (for cross-project usage)
  • independent timers to have several autonomous functions (several interfaced sensors read\write and several different HTTP-requests...)
  • and all these are sensitive to the timing, have time to execute, non-guaranty result (Internet connection, speed), and placed in several subs
  • but here there is not event-driven coding
How to make MCU sketch structure, if it needs to combine all:
  • make 2 periodical HTTP requests
  • read 2-5 sensors with fixed timings
  • each sensor reading is to be also uploaded by HTTP-request
  • external commands for MCU from server (got via one periodical HTTP request) are to be executed also immediately after receiving
?

I see that one thread is for all, but no single loop sub here to make synchronously all these tasks.
Say, when i test with 2 sensors by simple timer sketch - both sensors are 99% correctly recognized, just very rare CRC-error. But when all this is inside big complex multitask sketch (with HTTP-requests and other timers) - 95% of CRC-errors from sensors, and only sometimes each sensor is read correctly.

What can be coding strategy in B4R ?
 
Last edited:

peacemaker

Expert
Licensed User
Longtime User
Try Esp32

1) Is it another situation comparing to ESP8266 within the same B4R ?
2) And here such workaround is not applicable, for device scale, and economics.

It seems in whole, the task to to make multitask sketch fully synchronous, with programmed each task order with all output variants, including timeslot (timeout timer) for running each subtask.
 
Last edited:
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
Yes, it was one Delay. Now removed, and nothing better. But simple timer sketch (just reading sensor) works OK.
Maybe some sensor initialization....but... the post question is anyway here - how correctly plan such complex sketch ?

Some RTC OS template maybe needed, with fixed tasks order execution... ?
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
Which protocol do sensors use?

Sensors are read by Modbus master protocol over RS485 bus. And it's working OK in simplest timer sketch.
I have added a WorkingFlag into HTTPJob module - no interference.

And now moreover - in my full complex sketch i have moved the sensor reading start just after "AppStart", without any other code and ..... sensor anyway gives CRC-error mostly :(
Mystics...
 
Last edited:
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
Ooops, solved...
Simplest timer sketch is reading 6 registers by Modbus protocol, but my full sketch was trying to read 8 registers.
If try to read even 18 registers, or 6 pcs - no CRC-error, but 8 pcs - gives CRC-error :rolleyes:
Sensor speed is just 9600 bauds.

It's very good that i have solved.
But the forum's thread is (was) about another question :)
How better to build the B4R sketch structure for complex sketches with many timers and many pseudo-async HTTP requests ?
 
Last edited:
Upvote 0
Top