Robofun 機器人論壇

 找回密碼
 申請會員
搜索
熱搜: 活動 交友 discuz
查看: 2406|回復: 1

我想問一下各位大大

[複製鏈接]
發表於 2019-3-20 21:56:56 | 顯示全部樓層 |閱讀模式

      我使用了Arduino UNO去連接ESP2866 ESP-01 Wifi module,然後就傳送了一個php檔的文件去一個自製的伺服器。
      我嘗試使用AT指令去連接TCP,雖然在傳輸資料到TCP的時候成功了,但是當我使用Arduino Sketch來寫AT程式時(在下面),在傳送及連接TCP數據時,不知道為什麼它一時成功一時失敗。

     我想請問一下各位大大 如果小的想解決這個問題
我需要做什麼? 用不用加什麼設備? > . <
或者要穩定ESP-8266 ESP-01 Wifi module的電壓?

謝謝大家了哦~

這個是我編寫的程式,請各位大大過目一下:
#include <SoftwareSerial.h>
#define RX 2
#define TX 3
int fsrAnalogPin = 0;
String AP = "Test";       // CHANGE ME
String PASS = "testtest"; // CHANGE ME
String HOST = "...";
String PORT = "80";
int countTrueCommand;
int countTimeCommand;
boolean found = false;
int fsrReading;
int fsrReading2;
int fsrReading3;
int Seats1 = 0;
int Seats2 = 0;
int Seats3 = 0;
int result = 0;
SoftwareSerial esp8266(RX,TX);
  
void setup() {
  Serial.begin(9600);
  esp8266.begin(115200);
  sendCommand("AT+RST",5,"OK");
  sendCommand("AT+RESTORE",15,"OK");
  sendCommand("AT",5,"OK");
  sendCommand("AT+CWMODE=1",5,"OK");
  sendCommand("AT+CWJAP_CUR=\""+ AP +"\",\""+ PASS +"\"",20,"OK");
}
void loop() {
  fsrReading = analogRead(fsrAnalogPin);  
  if (fsrReading > 1)
{
  Seats1 = 0;
}
    else
    {
  Seats1 = 1;
}
if (fsrReading2 > 0)
{
  Seats2 = 0;
}
    else
    {
  Seats2 = 1;
}
if (fsrReading3 > 0)
{
  Seats3 = 0;
}
    else
    {
  Seats3 = 1;
}
result = Seats1 + Seats2 + Seats3 ;
String stringOne = "GET /~it-comp1/submit_sum.php?a1=" ;
String stringTwo = "&a2=" ;
String stringThree = "&plate=LV8402" ;
String getData = stringOne + result + stringTwo + 0 + stringThree ;
sendCommand("AT+CIPSTART=\"TCP\",\""+ HOST +"\","+ PORT,15,"OK");
sendCommand("AT+CIPSEND=" +String(getData.length()+4),4,">");
esp8266.println(getData);delay(1500);countTrueCommand++;
sendCommand("AT+CIPCLOSE=0",5,"OK");
result = 0 ;
delay(1000);
}

void sendCommand(String command, int maxTime, char readReplay[]) {
  Serial.print(countTrueCommand);
  Serial.print(". at command => ");
  Serial.print(command);
  Serial.print(" ");
  while(countTimeCommand < (maxTime*1))
  {
    esp8266.println(command);//at+cipsend
    if(esp8266.find(readReplay))//ok
    {
      found = true;
      break;
    }
  
    countTimeCommand++;
  }
  
  if(found == true)
  {
    Serial.println("OYI");
    countTrueCommand++;
    countTimeCommand = 0;
  }
  
  if(found == false)
  {
    Serial.println("Fail");
    countTrueCommand = 0;
    countTimeCommand = 0;
  }
  
  found = false;
}
在這裏我再次多謝大家哦~

發表於 2019-3-21 06:30:53 | 顯示全部樓層

應該是長度算錯造成
改成這樣試試看
getData.length()+2
您需要登錄後才可以回帖 登錄 | 申請會員

本版積分規則

小黑屋|手機版|Archiver|機器人論壇 from 2005.07

GMT+8, 2024-3-29 23:18 , Processed in 0.188822 second(s), 6 queries , Apc On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回復 返回頂部 返回列表