在Arduino中串联char和string

时间:2019-04-07 22:16:55

标签: c++ c arduino

我正在使用Arduino开发板和提供的示例。试图收到一条我收到的要在液晶显示屏上显示的消息。我正在努力弄清楚如何使用一些预构建的代码。

我得到错误:从'const unsigned char *'到'const char *的无效转换

我尝试修改payload参数类型,但它破坏了对MessageCallback的其他引用。

arduino开发板文档中的

Screen.print()定义: int打印(无符号int行,const char,bool包装)

代码:

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;
}

2 个答案:

答案 0 :(得分:0)

如果仅更改为char screenMsg[100];,则应该可以使用。

仅此而已,打印功能将不会更改您提供的字符串

  

const char s

表示。

答案 1 :(得分:0)

Strcat的参数为(char *, const char *)。您可以通过执行“ char*”将“有效载荷”投射到strcat(screenMsg, (char*)payload);中。阅读Strcat two unsigned char in C

相关问题