Returning data from AT+CIPSTART from Arduino
Posted: Fri Mar 22, 2019 2:44 am
I'm trying to get data from a GET request when I do this directly using the serial monitor (from Arduino ) everything is working as expected. However, when I try and do the same thing from the Arduino everything is great apart from getting a response from what I have sent. I have tried different things to get all the response but it just looks like it gives up part way through getting the request!
Note: Everything between the # I have changed for the resons
Serial Monitor Input:
Serial Monitor Output:
Arduino Program:
Arduino Output:
Note: Everything between the # I have changed for the resons
Serial Monitor Input:
Code: Select all
AT+RST
AT+CWMODE_CUR=3
AT+CIPSTA_CUR="192.168.1.160","192.168.1.1","255.255.255.0"
AT+CIPSTAMAC_CUR="80:7D:3A:33:6C:53"
AT+CWJAP_CUR="#MYWIFI#","#MYWIFIPASS#"
AT+CIPSTART="TCP","#99.999.99.999#",80
AT+CIPSEND=101
GET /api/#Method# HTTP/1.1
Host:#hostname#
Connection:close
*HIT ENTER KEY*
Serial Monitor Output:
Code: Select all
AT+RST
OK
ets Jan 8 2013,rst cause:2, boot mode:(3,7)
load 0x40100000, len 2592, room 16
tail 0
chksum 0xf3
load 0x3ffe8000, len 764, room 8
tail 4
chksum 0x92
load 0x3ffe82fc, len 676, room 4
tail 0
chksum 0x22
csum 0x22
2nd boot version : 1.7(5d6f877)
SPI Speed : 40MHz
SPI Mode : QIO
SPI Flash Size & Map: 16Mbit(1024KB+1024KB)
jump to run user1 @ 1000
⸮⸮⸮⸮o⸮;⸮⸮g|⸮l⸮⸮lc⸮⸮|s⸮d⸮g⸮⸮g⸮
ready
AT+CWMODE_CUR=3
OK
AT+CIPSTA_CUR="192.168.1.160","192.168.1.1","255.255.255.0"
OK
AT+CIPSTAMAC_CUR="80:7D:3A:33:6C:53"
OK
AT+CWJAP_CUR="#MYWIFI#","#MYWIFIPASS#"
WIFI CONNECTED
WIFI GOT IP
OK
AT+CIPSTART="TCP","#99.999.99.999#",80
CONNECT
OK
AT+CIPSEND=101
OK
>
Recv 101 bytes
SEND OK
+IPD,223:HTTP/1.1 200 OK
Content-Length: 36
Content-Type: text/plain; charset=utf-8
Server: Microsoft-IIS/10.0
X-Powered-By: ASP.NET
Date: Fri, 22 Mar 2019 07:21:54 GMT
Connection: close
Its working baby 3/22/2019 - 7:21 AMCLOSED
Arduino Program:
Code: Select all
#include <SoftwareSerial.h>
#define RX 10
#define TX 11
SoftwareSerial esp8266(RX,TX);
String wifiSSID = "#MYWIFI#";
String wifiPass = "#MYWIFIPASS#";
String hostIp = "#99.999.99.999#";
String port = "80";
int countTrueCommand;
int countTimeCommand;
int wifiStep = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Starting...");
esp8266.begin(115200);
delay(2000);
}
void loop() {
switch(wifiStep)
{
case 0:
//Basic AT check
//sendBasicCommand("AT",5,"OK", 1);
wifiStep = 1;
break;
case 1:
//Reset
sendBasicCommand("AT+RST",10,"OK", 2);
//wifiStep = 2;
break;
case 2:
//Set Mode
sendBasicCommand("AT+CWMODE_CUR=1",5,"OK", 3);
break;
case 3:
//Set IP address range
sendBasicCommand("AT+CIPSTA_CUR=\"192.168.1.160\",\"192.168.1.1\",\"255.255.255.0\"",5,"OK", 4);
break;
case 4:
//Set Mac address
sendBasicCommand("AT+CIPSTAMAC_CUR=\"80:7D:3A:33:6C:53\"",5,"OK", 5);
break;
case 5:
//Connect to router
sendBasicCommand("AT+CWJAP_CUR=\""+ wifiSSID + "\",\"" + wifiPass + "\"",15,"OK", 6);
break;
case 6:
//Create Connection Connection
sendBasicCommand("AT+CIPSTART=\"TCP\",\"" + hostIp + "\"," + port + "",5,"OK", 7);
break;
case 7:
//Setup call
sendBasicCommand("AT+CIPSEND=101", 5, ">", 8);
delay(500);
break;
case 8:
//Call API
Serial.println("CallingAPI");
callBuildApi();
delay(5000);
wifiStep = 9;
break;
case 9:
//Close Connection
//sendBasicCommand("AT+CIPCLOSE",5,"OK", 6);
wifiStep = 6;
delay(5000);
break;
default:
wifiStep = 0;
break;
}
delay(500);
}
void sendBasicCommand(String command, int maxTime, char readReplay[], int nextStep) {
Serial.print("command ");
Serial.print(command);
boolean found = false;
while(countTimeCommand < (maxTime*1))
{
char data = esp8266.read();
esp8266.println(command);
if(esp8266.find(readReplay))
{
found = true;
break;
}
countTimeCommand++;
}
if(found == true)
{
Serial.print(" (good)");
countTrueCommand++;
countTimeCommand = 0;
if(nextStep != -1){
wifiStep = nextStep;
}
}
if(found == false)
{
Serial.print(" (fail)!!!!!!!!!");
countTrueCommand = 0;
//if failed then reset the wifi status to 0 so start the process again from the beginning
wifiStep = 0;
}
Serial.println("");
}
void callBuildApi(){
esp8266.println("GET /api/LastestBuildInfo HTTP/1.1");
esp8266.println("Host:#HOST#");
esp8266.println("Connection:close");
esp8266.println("");
while (esp8266.available() > 0)
{
esp8266.read();
delay(1);
}
String data = esp8266.readStringUntil("CLOSE");
Serial.println(data);
}
Arduino Output:
Code: Select all
command AT+RST (good)
command AT+CWMODE_CUR=1 (good)
command AT+CIPSTA_CUR="192.168.1.160","192.168.1.1","255.255.255.0" (good)
command AT+CIPSTAMAC_CUR="80:7D:3A:33:6C:53" (good)
command AT+CWJAP_CUR="#MYWIFI#","#MYWIFIPASS#" (good)
command AT+CIPSTART="TCP","#99.999.99.999#",80 (good)
command AT+CIPSEND=101 (good)
CallingAPI
SEND OK
+IPD,223:HTTP/1.1 200 OK
Content-Length: 36
Content-Tytcfeo
BT,9Mo
0M