I need to convert the char* topic and the byte* payload into something I can do if-statements on. I know my topics names are always four characters (digits) long. And the payloads are either ints or floats depending on the topic name.
How do I convert the char* into an int? How do I conditionally convert the byte* payload into a float?
For the char* to int, I think I would use the atoi(buffer) function, but the buffer is usually a char buffer [ x ] , where x is definite. I don't know what to do with a char*. If I'm always subscribing to the 4-character topic name (1111, 2222, 3333, etc), I can assume char* is 4 characters, but how do I pass char* to atoi() function?
I don't know what to do with byte* to convert it into float. I think the unsigned int length is the size of the payload byte*? But what to do with it?
It might be easier to just treat the topic pointer like an array ( use the subscript operator '[]' to access elements ), and do a strcmp() (compare ) of the string to your saved name. If you really use numbers, you can minus the character '0' off each topic character and you will be left the integer value.
but how do I pass char* to atoi() function?
Every reference I have ever seen for atoi has had an example in it...