Hello. I am working with multiple ESP32 devices that constantly read sensor values, publish/receive MQTT messages and toggle GPIOs. I have implemented the code without using any RTOS, but wondering whether the RTOS would be beneficial here?
I am though little bit confused how would I implement RTOS since MQTT client requires a function
and the callback function:
I am though little bit confused how would I implement RTOS since MQTT client requires a function
Code:
client.setCallback(callback);
Code:
void callback(char* topic, byte* payload, unsigned int length) {
Serial.print("Message arrived [");
Serial.print(topic);
Serial.print("] ");
char message[length + 1];
strncpy (message, (char*)payload, length);
message[length] = '\0';
Serial.println(message);
if (strcmp(topic, ping_topic) == 0){
if (strncmp(message, "ON", 2) == 0){
digitalWrite(LED_YELLOW, 1);
Serial.println("red led_turned_on");
}
if (strncmp(message, "OFF", 3) == 0){
digitalWrite(LED_YELLOW, 0);
Serial.println("red led_turned_off");
}
}
if (strcmp(topic, status_topic) == 0){
if (strncmp(message, "GOOD_JOB", 8) == 0){
//toggle_led(LED_YELLOW, 15);
//toggle_led_strip(5);
}
}
if (strcmp(topic,number_to_pick_topic) == 0){ //if number_to_pick received, means the complecataion has been scanned and initiate the pick_to_light
number_to_pick = atoi(message);
Serial.print("number to pick = ");
Serial.println(number_to_pick);
//OLED_display(item_inside.quantity,number_to_pick);
}
if (strcmp(topic,ota_topic) == 0){
//start_OTA();
}
if (strcmp(topic,item_inside_topic) == 0){ //if number_to_pick received, means the complecataion has been scanned and initiate the pick_to_light
//parse_item_inside((char*)payload);
}
}
[code/]
Callback automatically gets called whenever I receive a message. Im not sure how would that be implemented in RTOS?
Have anyone implemented RTOS for wifi/mqtt funcionality?