【发布时间】:2017-02-10 11:25:10
【问题描述】:
我从一个网站获得此代码,我将其用作从连接到我的 Arduino Mega 的 SIM800L 发送 SMS 消息的指南。
#include <Sim800l.h>
#include <SoftwareSerial.h>
Sim800l Sim800l; //declare the library
char* text;
char* number;
bool error;
void setup(){
Sim800l.begin();
text="Testing Sms";
number="+542926556644";
error=Sim800l.sendSms(number,text);
// OR
//error=Sim800l.sendSms("+540111111111","the text go here");
}
void loop(){
//do nothing
}
我在中间添加了一些代码,以便它可以通过串行连接在我的 Python GUI 中接收来自用户的字符串输入。
#include <Sim800l.h>
#include <SoftwareSerial.h>
Sim800l Sim800l; //declare the library
char* text;
char* number;
bool error;
String data;
void setup(){
Serial.begin(9600);
}
void loop(){
if (Serial.available() > 0)
{
data = Serial.readString();
Serial.print(data);
sendmess();
}
}
void sendmess()
{
Sim800l.begin();
text="Power Outage occured in area of account #: ";
number="+639164384650";
error=Sim800l.sendSms(number,text);
// OR
//error=Sim800l.sendSms("+540111111111","the text go here");
}
我正在尝试将serial.readString() 中的数据连接到text 的末尾。 + 和 %s 等常规方法不起作用。
在 Arduino IDE 中出现此错误:
error: cannot convert ‘StringSumHelper’ to ‘char*’ in assignment
如果我是正确的,char* 是一个指向地址的指针。有没有将串口监视器中的字符串添加到文本中?
【问题讨论】:
-
Arduino 有一个
String类,它拥有一个concat()方法,text可以简单地声明为String以利用此功能比接受的答案中的代码少得多。如果 concatenation 不能满足您的需求,那么String也有一个addition operator。