“从空转换为非标量类型字符串”的含义是什么?

问题描述 投票:-2回答:2

我想通过短信使用sim900a模块和arduino uno将gps坐标发送到特定号码,当他们从短信请求“SEND GPS”时,这里编写代码但是当我编译代码时我得到“错误:从'void'转换非标量类型'字符串'请求“.....请任何帮助表示赞赏...提前谢谢你

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);
    }
c++ arduino-uno
2个回答
0
投票

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


0
投票

void loop()

{

while(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模块

延迟(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);

延迟(100);

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

延迟(1000);

_buffer = _readSerial();

}

}

}

© www.soinside.com 2019 - 2024. All rights reserved.