“从void到非标量类型字符串的转换”是什么意思?

时间:2019-04-12 06:11:14

标签: c++ arduino-uno

我想使用sim900a模块和arduino uno通过sms将gps坐标发送到特定号码,例如“ SEND GPS”之类的sms发出的请求,并在此处编写代码,但是当我编译该代码时,我收到“错误: 'void'为非标量类型'String'请求” .....请提供任何帮助...在此先谢谢您

void loop() {

    RecieveMessage();

    if (sim.available() > 0)
    {
        Serial.write(sim.read());
    }

    if(sim.read()=="SEND GPS")
    {
        SendMessage();
    }

}

void RecieveMessage()
{
    Serial.println ("SIM800L Read an SMS");
    sim.println("AT+CNMI=2,2,0,0,0");
    Serial.write ("Unread Message done");
}

void SendMessage()
{
    //Serial.println ("Sending Message");
    sim.println("AT+CMGF=1");
    sim.println("AT+CMGS=\"" + number + "\"\r");
    while (sgps.available())
    {
        int c = sgps.read();
        if (gps.encode(c))
        {
            float slat,slon;
            String loc=gps.f_get_position(&slat, &slon);
        }

        String SMS = String("http://maps.google.com/maps?q=loc:")+String(loc);
        sim.println(SMS);
        sim.println((char)26);
    }

2 个答案:

答案 0 :(得分:0)

gps.f_get_position返回void,但您将其分配给String。只需删除String loc=

答案 1 :(得分:0)

void loop()

{

同时(sgps.available())

{

int c = sgps.read();

if (gps.encode(c))
{

  float slat,slon;
  gps.f_get_position(&slat, &slon);
  Serial.print("Latitude :");
  Serial.println(slat, 6);
  Serial.print("Longitude:");
  Serial.println(slon, 6);

String loc = String(slat,6)+“” + String(slon,6);

Serial.println(“发送消息”);

sim.println(“ AT + CMGF = 1”); //将GSM模块设置为文本模式

delay(1000);

Serial.println ("Set SMS Number");

sim.println("AT+CMGS=\"" + number + "\"\r"); //Mobile phone number to send message

 delay(1000);

String SMS = String(“ https://www.google.com/maps/”)+ String(slat,6)+“,” + String(slon,6);

sim.println(SMS);

delay(100);

sim.println((char)26); // CTRL + Z的ASCII码

delay(1000);

_buffer = _readSerial();

}

}

}