I have designed a small project in which i have two sensor nodes(stm32) with each sensing temp, humidity and soil moisture and actuating the relay based on some threshold of moisture value. These sensor nodes are transmitting sensed data to base station(Rpi) through zigbee and UART. Also the Rpi can send some integer value based on which sensor nodes will change their transmission rate (delay between two transmission). Now I want to implement this system on an RTOS based system. My question is what should be different tasks (should I give different tasks for each temp, humidity and moisture or only one task for all sensors)? What priority i should assign to the different tasks?
I'd suggest to keep the task priority at the same level unless you have a task that really needs to be prioritised (shouldn't be the case in this application). Splitting your tasks(code) into different threads(RTOS tasks) has two main benefits
- Parallelisation (of course if you have just 1 core this is just pseudo parallel) can help to smooth your system. E.g. if you have some time consuming calculations and a display showing some live values it makes sense to split these tasks into separate threads to have the display updated frequently.
- Program Structure (Maintainablitly) that means if you have a large system performing various tasks it's really helpful to completely separate them (e.g. calculations, communications, display)
But having different tasks has also a downside. One is the context switch that consumes process time that means if you have too many tasks your processor is spending more time in switching between the separate tasks than actually perform the task. The other is predictability due to parallelisation compared to a strict sequential code.
So to come back to your specific example I'd not create more than two tasks. One handling the sensor data of all sensors and do whatever has to be done with it and the other task handling the communication to have these two things separated.