PHP:逐步接收POST数据(arduino esp8266 car gps tracker project)

I found this nice example on building a gps-sd-wifi project.

MartijnBraam/car-tracker

The problem is in github the php file is not included.

How should I read the data coming from an ESP8266 (or equivalent) using this code as the sender...

I would like to get all the data and be able to save it to a file, or redirect it to mysql.

Thank you

void uploadTrack(char* name){
  File log = SD.open(name);
  WiFiClient client;
  int tracker = ESP.getChipId();
  String trackerId = String(tracker);
  Serial.printf("Uploading %s
", name);
  if(client.connect("tracker.brixit.nl", 80)){
    Serial.println("Sending headers");
    String length = String(log.size());
    String headers = String("POST /upload.php HTTP/1.0
")+
      "Host: tracker.brixit.nl
" +
      "Connection: close
" + 
      "Content-Type: text/csv
" + 
      "Content-Length: " + length + "
" +
      "X-Tracker: " + trackerId + "
" +
      "X-Secret: " + secret + "
" + 
      "X-Track: " + name + "
" +
      "
";
    client.print(headers);
    Serial.println("Sending data");

    char buffer[1470];
    while(true){
      int bytes = log.read(buffer,1470);
      if(bytes < 1){
        break;
      }
      client.write_P(buffer, bytes);
      delay(0);
    }
    Serial.println("Upload done");
    client.stop();
  }


}
dpo69086
dpo69086 谢谢waza-ari,我只是设法让它在半小时前工作。我今晚将发布我的工作代码。感谢您的帮助。
一年多之前 回复
dongyi6269
dongyi6269 这正是我的观点。在启动while循环之前打开连接,然后一致地发送数据,在while循环之后关闭连接。当这将退出是未知的,因为只要数据到来它将继续发送(在相同的POST连接中)。否则,它看起来像一个标准的POST请求,就像使用PHP处理表单输入一样。可以是任何其他语言,只要可以处理HTTP请求。
一年多之前 回复
doufei2328
doufei2328 'progressive'部分是您可以在代码中看到的while循环。也许'进步'不是描述它的正确词。但基本上问题是,如何编写PHP来接收来自上面代码的数据
一年多之前 回复
douzou8074
douzou8074 你是什​​么意思逐步?通常PHP有一个“max_execution_time”,默认情况下为30秒。即使这当然可以改变,我认为在客户端上收集一些数据可能会更好,并在多个请求中以块的形式发送数据。
一年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐