【问题标题】:Error in http syntax error in arduino codearduino 代码中的 http 语法错误
【发布时间】:2023-03-30 12:03:01
【问题描述】:

下面的函数描述了一组使用 gps 模块的 adruino shield 和 uno board 的值。

我收到一些错误,可能是语法错误。请忽略指出错误的行。我不希望人们看到大型编码感到害怕。

void send_HTTP(){

uint8_t answer=0;
// Initializes HTTP service
answer = sendATcommand("AT+HTTPINIT", "OK", 10000);
if (answer == 1)
{
    // Sets CID parameter
    answer = sendATcommand("AT+HTTPPARA=\"CID\",1", "OK", 5000);
    if (answer == 1)
    {
        // Sets url 
        sprintf(aux_str, "AT+HTTPPARA=\"URL\",\"http://%s/demo_sim908.php?", url);// line number :459
        Serial.print(aux_str);
        sprintf(frame, "visor=false&latitude=%s&longitude=%s&altitude=%s&time=%s&satellites=%s&speedOTG=%s&course=%s",       
        latitude, longitude, altitude, date, satellites, speedOTG, course);   // line number : 460
        Serial.print(frame);
        answer = sendATcommand("\"", "OK", 5000);
        if (answer == 1)
        {
            // Starts GET action
            answer = sendATcommand("AT+HTTPACTION=0", "+HTTPACTION:0,200", 30000);
            if (answer == 1)
            {

                Serial.println(F("Done!"));
            }
            else
            {
                Serial.println(F("Error getting url"));
            }

        }
        else
        {
            Serial.println(F("Error setting the url"));
        }
    }
    else
    {
        Serial.println(F("Error setting the CID"));
    }    
}
else
{
    Serial.println(F("Error initializating"));
}

sendATcommand("AT+HTTPTERM", "OK", 5000);

}

我收到以下错误。

Arduino:1.7.5(Windows 8.1),板:“Arduino Uno”

sketch_aug22e.ino:459:13:错误:缺少终止“字符

sketch_aug22e.ino:在函数'void send_HTTP()'中:

sketch_aug22e.ino:460:34: 错误:在 ';' 之前需要 ')'令牌

编译错误。

此报告将包含更多信息 “在编译期间显示详细输出” 在文件 > 首选项中启用。

【问题讨论】:

  • 这只是一个 arduino 错误,因为存在双引号引起的问题
  • 我呈现了下面提到的其他选项,但其中任何一个都有效

标签: http network-programming arduino httpwebrequest gsm


【解决方案1】:

你在第 459 行有奇数个引号:

sprintf(aux_str, "AT+HTTPPARA=\"URL\",\"http://%s/demo_sim908.php?", url);

这让编译器感到困惑。

如果不确切知道你想做什么就很难说,但如果你打印 3 个单独的字符串,那么你可能不想“ESC”第三个字符串 - 例如:

sprintf(aux_str, "AT+HTTPPARA=\"URL\"", "http://%s/demo_sim908.php?", url);

或者,如果您只是想打印两个字符串,而 http 之前的“逗号”只是字符串的一部分,那么您可能只需要关闭那个“ESCed”网址:

sprintf(aux_str, "AT+HTTPPARA=\"URL\",http://%s/demo_sim908.php?\", url);

【讨论】:

  • 错误仍然出现在哪一行?您能否也显示确切的编译器错误消息,未经编辑。
  • 我尝试了不同的方式,通过更改引号替换不同的方式,我得到了答案。无论如何感谢您的宝贵帮助
  • 我想我改用了这个: sprintf(aux_str, "AT+HTTPPARA=\"URL\",\"http:/" "/%s/demo_sim908.php?", url); :
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-03-24
相关资源
最近更新 更多