Take the 2-minute tour ×
Arduino Stack Exchange is a question and answer site for developers of open-source hardware and software that is compatible with Arduino. It's 100% free, no registration required.

I really need all the help I can get... It's been a week now and I'm still not able to solve the problem.

I have text file on a server. The whole address is www.example.com/test.txt I want to read the file using a GET request every 3-5 secs and parse it for further actions. But the arduino codes that I've tried till now use software serial and it keeps misbehaving. Sometimes it skips a few serial-print commands and loops back sometimes it reads the file 3-4 times and then hangs. Basically I'm getting the response only a few times but then it stops working properly.

I want to solve this...I need a working arduino code to work with ESP8266 so that I can successfully poll a text file from server without any problems.

Here is my current code -

 #include<SoftwareSerial.h>

    #define led 13
    SoftwareSerial esp(11, 12);
    String domain = "www.example.com";
    String request = "GET /test.txt HTTP/1.0\r\n\r\n";


    void SerialDo(String command, float time, bool debug) {
      delay(100);
      esp.print(command);

      int i = millis();
      while (millis() - i < (time * 1000)) {
        while ( (esp.available())) {
          if (debug) {
            Serial.print((char)esp.read());
          }
        }
      }

      Serial.flush();
    }

    void setup() {
      // put your setup code here, to run once:
      digitalWrite(led, OUTPUT);
      Serial.begin(9600);
      esp.begin(9600);
      esp.setTimeout(3000);
      digitalWrite(led, LOW);
      Serial.println("Hello");
      //delay(2000);
      SerialDo("AT+RST\r\n", 5, true);
      Serial.flush();
      SerialDo("AT+CWMODE=1\r\n", 0.5, true);

      delay(1000);
      //SerialDo("AT+CWLAP\r\n", 5, true);
      SerialDo("AT+CWJAP=\"Sherlock\",\"Watson@11\"\r\n", 10, true);
      SerialDo("AT+CIPMUX=0\r\n", 0.5, true);

    }

    void loop() {


      delay(1000);
      Serial.print("loop\r\n");

      SerialDo("AT+CIPMUX=0\r\n", 0.5, true);
      SerialDo("AT+CIPSTART=\"TCP\",\"" + domain + "\",80\r\n", 1.5, true);
      esp.flush();

      esp.print("AT+CIPSEND=" + String(request.length()) + "\r\n");
      delay(100);
      esp.print(request);

      String t = "";
      int i = millis();
      while (millis() - i < 1500) {
        while ((esp.available() > 0)) {
          if (true) {
            char c = (char)esp.read();
            t += c;
            Serial.print(c);
          }
        }
      }

      esp.print("AT+CIPCLOSE\r\n");

      if (t.indexOf("hello world") > -1) {
        digitalWrite(led, !digitalRead(led));
      }
  }
share|improve this question

1 Answer 1

It seems that you're trying to do the same thing:

https://www.youtube.com/watch?v=q02f4sPghSo

Maybe it will help, I'm tryin' to do that (a POST), only that I don't have the server on a text file.

share|improve this answer
    
Welcome to Arduino SE. Link-only answers are generally discouraged because it relies on the link's destination staying online. Could you expand your answer to include some of the essential information please? Thanks. –  Peter R. Bloomfield May 20 at 1:26

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.