I'm playing with an Arduino board and the samples provided. Trying to get a message I received to be displayed on the LCD. I'm struggling to figure out how to work with some of the pre-built code.
I get the error: invalid conversion from 'const unsigned char*' to 'const char*
I tried modify the payload
parameter type but it breaks other references to MessageCallback.
Screen.print() definition in the documentation for the arduino board: int print(unsigned int line, const char s, bool wrap)
Code:
static int MessageCallback(const unsigned char *payload)
{
int result = 200;
const char screenMsg[100];
strcpy(screenMsg,"Set Temp: ");
strcat(screenMsg,payload);
Screen.print(1, screenMsg, true);
return result;
}
If you just change to char screenMsg[100];
it should work.
The print function will not change the string you provide to it, is all that
const char s
means.
Strcat's arguments are (char *, const char *)
. You can cast "payload" to a char*
by doing " strcat(screenMsg, (char*)payload);
". Read Strcat two unsigned char in C .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.