However it is still acting weird. i would appreciate if somebody could test my code out please....
#define BUFFER 1024 // size of the buffer
#define SSID "YourSSID"
#define PASS "YourPassword"
#define DST_IP "173.254.30.60"
char buffer[BUFFER];
#define DEBUG Serial // Send debug messages to serial monitor
#define ESP8266 Serial1 // Use Serial1 to talk to ESP8266 (Mwga)
// By default we are looking for OK\r\n
char OK[] = "OK\r\n";
void setup() {
delay(1000);
ESP8266.begin(115200);
DEBUG.begin(115200);
DEBUG.println("Starting...");
initESP8266();
}
byte waitForResponse(int timeout, char* term=OK) {
unsigned long t=millis();
bool found=false;
int i=0;
int len=strlen(term);
// wait for at most timeout milliseconds
// or if OK\r\n is found
while(millis()<(t+timeout)) {
if(ESP8266.available()) {
buffer[i++]=ESP8266.read();
if(i>=len) {
if(strncmp(buffer+i-len, term, len)==0) {
found=true;
break;
}
}
}
}
buffer[i]=0;
DEBUG.println(buffer);
delay(100);
return found;
}
void initESP8266() {
// reset module
ESP8266.println("AT+RST");
waitForResponse(10000);
// set mode 1 (client)
ESP8266.println("AT+CWMODE=3");
waitForResponse(5000);
// Join the Access Point
ESP8266.print("AT+CWJAP=\"");
ESP8266.print(SSID);
ESP8266.print("\",\"");
ESP8266.print(PASS);
ESP8266.println("\"");
waitForResponse(10000);
ESP8266.println("AT+CIPMUX=0"); // Single connection
waitForResponse(5000);
ESP8266.println("AT+CIPMODE=0"); // Normal mode
waitForResponse(5000);
DEBUG.println("============================");
}
void getTheTime() {
String cmd = "AT+CIPSTART=\"TCP\",\"";
cmd += DST_IP;
cmd += "\",80";
ESP8266.println(cmd); //send command to device
waitForResponse(10000);
cmd = "GET /Test.txt HTTP/1.0\r\n\r\n"; //construct http GET request
cmd += "Host: thearduinoguy.org\r\n\r\n"; //test file on my web
ESP8266.print("AT+CIPSEND=");
ESP8266.println(cmd.length()); //esp8266 needs to know message length of incoming messa
waitForResponse(10000);
ESP8266.println(cmd);
waitForResponse(10000);
DEBUG.println("------------------------------");
}
void loop() {
delay(30000); // Check for time once a minute
getTheTime();
}
At the moment this code is simply a test to see the responses back from the unit. I am simply interested in the date/time string back from the http header to use to set a clock.
Thanks,
Mike