How Load A .txt File From a Website in Wemos D1

Hello, I Want Load a string from a .txt file from a website.

I mean something like this

String MyText = LoadString(“Good/New/matn.txt”);

But it's not working.

Please Help Me

But it's not working.

Bummer.

Please Help Me

How can we? You completely spaced when it came to posting your code.

Is there any way to do this? load a file from web link and put it in value?

this is my link:

http://umeent.ir/myText.txt

and I want to put this into a value then check it like this:

a= string(http://umeent.ir/myText.txt);

if(a==0)
{

//do something

}

Is there any way to do this? load a file from web link and put it in value?

You can make a GET request. The server running the specified script will return the data that the script generated.

If the script knows which file to open, and knows how to open the file and read the contents, and output the data from the file, the server will make that data available to you.

The client.connected(), client.available() and client.read() methods are used in the proper combination to read the server response. If you collect the server response in a NULL terminated char array, you can use strcmp() to compare that string to some other value. If they match, do whatever needs doing.

#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <WiFiUdp.h>

const char* ssid = “URS”;
const char* password = “Qwertyuiop!995”;

void setup () {
pinMode(LED_BUILTIN, OUTPUT);
Serial.begin(115200);
WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {

delay(1000);
Serial.print(“Connecting…”);

}

}

void loop() {

if (WiFi.status() == WL_CONNECTED) {

HTTPClient http;

http.begin(“http://umeent.ir/myText”);

int httpCode = http.GET();

if (httpCode > 0) {

String payload = http.getString();

Serial.println(payload);

}

http.end();

}
delay(5000);
}

this is my code but it returns me 0 in serial. I use it on wemos D1

Try using the full filename including the .txt (http://umeent.ir/myText.txt)

I tried but it not working. it works on ESP8266 Module but not working on Wemos D1

badrobatx:
I tried but it not working. it works on ESP8266 Module but not working on Wemos D1

This does not make sense as AFAIK they both use the same ESP8266 MCU.

When I run the below code on a Wemos D1 Mini it works for me.

#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
//#include <ESP8266mDNS.h>
//#include <WiFiUdp.h>

const char* ssid = "****";
const char* password = "********";

void setup () {
  Serial.begin(115200);
  Serial.println(F("\n\nSetup Begin."));
  
  pinMode(LED_BUILTIN, OUTPUT);
  
  Serial.print(F("Connecting To WiFi..."));
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  while (WiFi.waitForConnectResult() != WL_CONNECTED) {
    Serial.println(F("Connection Failed! "));
    delay(60000);                                           // Wait 60 seconds before attempting reconnect
    ESP.restart();
  }
  Serial.println(F("Connected."));
  
  Serial.println(F("Setup End."));
}

void loop() {
  Serial.println(F("Loop Begin."));
  
  if (WiFi.status() == WL_CONNECTED) 
  {
    HTTPClient http;
    
    Serial.print("[HTTP] begin...\n");
    if(http.begin("http://umeent.ir/myText.txt")) 
    {
      Serial.print("[HTTP] GET...\n");
      int httpCode = http.GET();
      
      if (httpCode > 0) {
        Serial.printf("[HTTP] GET... code: %d\n", httpCode);
        
        // file found at server
        if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY) 
        {
          String payload = http.getString();
          Serial.println(payload);
        }
      } 
      else 
      {
        Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
      }
      
      http.end();
    } 
    else
    {
      Serial.printf("[HTTP} Unable to connect\n");
    }
  }
  
  Serial.println(F("Loop End."));
  
  delay(10000);
}

And result in serial monitor

Setup Begin.
Connecting To WiFi…Connected.
Setup End.
Loop Begin.
[HTTP] begin…
[HTTP] GET…
[HTTP] GET… code: 200
32
Loop End.