Page 1 of 1

How to act on MQTT data

Posted: Wed Oct 28, 2020 1:43 am
by loves80z
I am making a 12 bank battery tender. It will charge the lowest voltage battery first. I would like to be able to intervene with MQTT and tell it what battery to charge next. I am not a programmer by trade, so I am sure it is my misunderstanding of the arrow operator. Can someone help me with how to do if then or case statements based on the message data. I have been trying for a while using different code, but am still unsuccessful. My thinking is when I receive data, I can notify the monitor that I have a message, then I will use code like 01on or 011 for battery 1 go into charge mode. The string compair compiles, but an "on" message doesn't result in the "hey" being printed. This is my test code for acting on an MQTT message. Can someone help me with a little code magic? Thank you.

case MQTT_EVENT_DATA:
ESP_LOGI(TAG, "MQTT_EVENT_DATA");
printf("TOPIC=%.*s\r\n", event->topic_len, event->topic);
printf("I just got a message and its:\n");
printf("DATA=%.*s\r\n", event->data_len, event->data);
if (strcmp(event->data, "on") == 0) {
printf("hey\n");
}