#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <SoftwareSerial.h>
WiFiClient wificlient;
#define RX_PIN 13  // 接收引脚
#define TX_PIN 15  // 发送引脚
SoftwareSerial mySerial(RX_PIN, TX_PIN);
void setup() {
  Serial.begin(115200);
  mySerial.begin(19200);
  WiFi.begin("webserver", "www.nobiggie.cn");
  delay(500);
  WiFi.mode(WIFI_STA);
  Serial.println("FlashConnetWifi->connet");
  while (1) {
    delay(500);
    Serial.print(" . ");
    if (WiFi.status() == WL_CONNECTED) {
      Serial.println("FlashConnetWifi 闪存配置连接成功");
      break;
    }
  }
}

void loop() {
  if (mySerial.available()) {
    String receivedData = "";
    int i=1;
    while (mySerial.available()) {
      char c = mySerial.read();
      receivedData += c;
      i++;
    }

    if (i>10) {
      Serial.println("单号数据"+receivedData);
      String postStr="number="+receivedData;
      esp8266Post("http://192.168.7.254/api/scan",postStr);
    }
  }
}
String esp8266Post(String url, String postStr) {
  HTTPClient http;
  String response;
  http.begin(wificlient, url);
  http.setTimeout(3000);
  //需要传输的数据
  char dataBuff[postStr.length()];
  strcpy(dataBuff, postStr.c_str());
  //头信息，需要的反注释就可以
  //http.addHeader("Content-Type", "application/json;charset=utf-8");
  http.addHeader("Content-Type", "application/x-www-form-urlencoded");
  int httpCode = http.POST(dataBuff);
  if (httpCode == 200) {
    response = http.getString();
    return response;
  } else {
    return "";
  }
  http.end();
}