PHP:逐步接收POST数据(arduino esp8266汽车gps跟踪器项目)

时间:2019-03-10 12:58:12

标签: php post arduino arduino-esp8266

我在构建gps-sd-wifi项目时发现了一个很好的例子。

MartijnBraam/car-tracker

问题出在github中,不包含php文件。

如何使用此代码作为发件人来读取ESP8266(或等效文件)的数据...

我想获取所有数据并将其保存到文件中,或将其重定向到mysql。

谢谢

void uploadTrack(char* name){
  File log = SD.open(name);
  WiFiClient client;
  int tracker = ESP.getChipId();
  String trackerId = String(tracker);
  Serial.printf("Uploading %s\n", 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\r\n")+
      "Host: tracker.brixit.nl\r\n" +
      "Connection: close\r\n" + 
      "Content-Type: text/csv\r\n" + 
      "Content-Length: " + length + "\r\n" +
      "X-Tracker: " + trackerId + "\r\n" +
      "X-Secret: " + secret + "\r\n" + 
      "X-Track: " + name + "\r\n" +
      "\r\n";
    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();
  }


}

0 个答案:

没有答案