How to act on MQTT data

Posts: 1
Joined: Tue Oct 27, 2020 8:17 pm

How to act on MQTT data

Postby loves80z » Wed Oct 28, 2020 1:43 am

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.

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) {

Who is online

Users browsing this forum: axellin, Google [Bot] and 41 guests