logo elektroda
logo elektroda
X
logo elektroda

ESP8266 Arduino: Failed to read.txt file from server - 5 years ago it worked

klon111 1677 23
Best answers

How do I fix an ESP8266 Arduino sketch so it can download a .txt file from the server again?

Use HTTPS on port 443 instead of plain HTTP, because the site now expects a secure connection; one reply also verified a valid certificate for `https://klonikele.000webhostapp.com/` and suggested using the ESP8266 `HTTPSRequest` example with the fingerprint `5B FB D1 D4 49 D3 0F A9 C6 40 03 34 BA E0 24 05 AA D2 E2 01` [#18620563] If you are connecting to your own Raspberry Pi web server, make sure `http.begin()` includes the port number, otherwise the ESP8266 may report it cannot connect [#18630293] The thread also notes that the text file fetched from the server is read into a `String` variable [#18620563]
Generated by the language model.
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 18620105
    klon111
    Level 11  
    Posts: 140
    Rate: 23
    There is an error somewhere as I can't download data from the server.
    It used to be ok before 5 years ago.
    Please take a look.



    Code: C / C++
    Log in, to see the code
    .
  • ADVERTISEMENT
  • #2 18620508
    Anonymous
    Level 1  
  • #3 18620526
    klon111
    Level 11  
    Posts: 140
    Rate: 23
    and how to do it
  • #4 18620533
    Anonymous
    Level 1  
  • Helpful post
    #6 18620563
    Anonymous
    Level 1  
  • #7 18620616
    klon111
    Level 11  
    Posts: 140
    Rate: 23
    is ok thanks

    read online

    20:20:27.971 -> WiFi connected
    20:20:27.971 -> IP address:
    20:20:27.971 -> 192.168.2.2
    20:20:27.971 -> connecting to klonikele.000webhostapp.com
    20:20:27.971 -> Using fingerprint '5B FB D1 D4 49 D3 0F A9 C6 40 03 34 BA E0 24 05 AA D2 E2 01'
    20:20:29.499 -> requesting URL: /StanESP8266.txt
    20:20:29.669 -> request sent
    20:20:29.669 -> headers received
    20:20:44.673 -> esp8266/Arduino CI has failed
    20:20:44.673 -> reply was:
    20:20:44.673 -> ==========
    20:20:44.673 -> zzzza1a2a3a4a5a6a7a8a9 b1b2b3b4b5b6b7b8a9 c1c2c3c4c5c6c7c8c9 d1d2d3d4d5d6d7d8d9 .
    20:20:44.707 -> ==========
    20:20:44.707 -> closing connection
  • ADVERTISEMENT
  • #8 18623589
    klon111
    Level 11  
    Posts: 140
    Rate: 23
    I have another problem whether on
    Raspberry system OSMC installed PHP Version 7.0.33-0+deb9u6
    It is possible to read and write text via ESP
  • ADVERTISEMENT
  • #11 18626390
    Anonymous
    Level 1  
  • #13 18627576
    Anonymous
    Level 1  
  • #14 18628603
    klon111
    Level 11  
    Posts: 140
    Rate: 23
    ESP has saved 4 times and still does not want to
    from the browser is ok http://192.168.2.6/piwo.php?temp1=29,99
    and after throwing Serial.begin(115200);
    and changing the led pin from 4 to 1 it works fine


    on it does not save
    Code: C / C++
    Log in, to see the code



    this one is ok
    Code: C / C++
    Log in, to see the code
  • Helpful post
    #15 18629325
    Slawek K.
    Level 35  
    Posts: 3015
    Help: 259
    Rate: 1299
    Try this :

    Code: C / C++
    Log in, to see the code


    Greetings
  • ADVERTISEMENT
  • #16 18629928
    klon111
    Level 11  
    Posts: 140
    Rate: 23
    Works fine thanks , very clear code
    And how to read a.txt file into esp8266

    I browse through the library and cannot find

    Best regards and good health
  • #17 18629937
    Slawek K.
    Level 35  
    Posts: 3015
    Help: 259
    Rate: 1299
    This.txt file is where ?
  • #18 18629944
    klon111
    Level 11  
    Posts: 140
    Rate: 23
    yes alone on Raspberry OSMC system
  • #19 18630028
    Slawek K.
    Level 35  
    Posts: 3015
    Help: 259
    Rate: 1299
    Write down exactly in turn what you need to do with this file so that I understand the idea.

    Greetings
  • #20 18630056
    klon111
    Level 11  
    Posts: 140
    Rate: 23
    The file can be found on the Raspberry http://192.168.2.6/var/www/html/odczyt.txt

    with content e.g. zzzza1a2a3a4a5a6a7a8a9 b1b2b3b4b5b6b7b8a9 c1c2c3c4c5c6c7c8c9 d1d2d3d4d5d6d7d8d9

    The point is to read this text after the analysis is controlled by ESP
  • #22 18630123
    klon111
    Level 11  
    Posts: 140
    Rate: 23
    It does not find the file and responds

    13:37:42.269 -> [SETUP] WAIT 4...
    13:37:43.289 -> [SETUP] WAIT 3...
    13:37:44.275 -> [SETUP] WAIT 2...
    13:37:45.295 -> [SETUP] WAIT 1...
    13:37:46.281 -> [HTTP] begin...
    13:37:46.281 -> [HTTP} Unable to connect
    13:37:56.272 -> [HTTP] begin...
    13:37:56.272 -> [HTTP} Unable to connect

    Code: C / C++
    Log in, to see the code
  • #23 18630293
    Slawek K.
    Level 35  
    Posts: 3015
    Help: 259
    Rate: 1299
    I think the port number is missing in http.begin()

    Greetings
  • #24 18630400
    klon111
    Level 11  
    Posts: 140
    Rate: 23
    is ok works fine
    I want to thank khoam and Slawek K. for help
    From these programs you can control ESP8266 with Raspbery-OSMC with PHP installed and with servers

    Code: C / C++
    Log in, to see the code
    .

Topic summary

✨ The discussion revolves around issues faced while attempting to read a .txt file from a server using the ESP8266 module, which previously functioned correctly five years ago. Users noted that modern connections often require HTTPS instead of HTTP, prompting suggestions to modify the code to connect securely on port 443. A specific server, "klonikele.000webhostapp.com," was mentioned as having a valid SSL certificate. Various code snippets were shared to demonstrate how to establish a connection and retrieve data from the server. Users also discussed challenges related to PHP integration on a Raspberry Pi system and provided examples of successful code implementations for reading and writing data.
Generated by the language model.

FAQ

TL;DR: 80 % of Chrome page-loads already travel over HTTPS [Google, 2020]. “Switch to port 443 and WiFiClientSecure” [Elektroda, khoam, post #18620563] Update your ESP8266 sketch with ESP8266HTTPClient, add the server fingerprint, and include the port in http.begin() to restore txt-file transfers.

Why it matters: Modern servers refuse plain-text HTTP, so your microcontroller must speak TLS to connect.

Quick Facts

• Default secure port: 443; HTTP 80 often blocked or auto-redirected [Elektroda, khoam, post #18620508] • ESP8266HTTPClient increases RAM use by ≈3 kB; keep >10 kB free for TLS [Espressif Docs, 2021] • Let’s Encrypt certificates expire every 90 days; update fingerprint or reconnect fails [Let’s Encrypt, 2022] • PHP 7.0 on Raspberry-OSMC handles ESP8266 GET/POST without addons [Elektroda, khoam, post #18624787] • 1.5 % of TLS handshakes fail due to cert errors [Mozilla Telemetry, 2021]

Why did my ESP8266 code that worked in 2015 stop downloading odczyt.txt?

The site moved from plain HTTP on port 80 to HTTPS on port 443. Your old WiFiClient cannot negotiate TLS, so the server closes the socket immediately [Elektroda, khoam, post #18620508]

How do I modify the sketch to use HTTPS?

  1. Replace WiFiClient with WiFiClientSecure.
  2. Change client.connect(host, 443) or http.begin(host, 443, "/file.txt").
  3. Add setFingerprint("5B FB D1…") or setInsecure() during testing [Elektroda, khoam, post #18620563]

What happens if the fingerprint is wrong or expires?

WiFiClientSecure aborts the TLS handshake. You receive “connection failed” and no data. Mozilla reports 1.5 % of TLS handshakes fail this way [Mozilla Telemetry, 2021].

Do I need to change the server name in the code?

Yes. Use the current domain (e.g., klonikele.000webhostapp.com) or local IP 192.168.2.6 for the Raspberry Pi [Elektroda, klon111, post #18620536]

How can I POST DS18B20 temperature to a PHP script?

Use ESP8266HTTPClient. Build the URL /piwo.php?temp1=25.3, call http.begin(host, 80, url), send http.GET() or http.POST() with zero-length body. The sample in post #18629325 shows full code [Elektroda, Slawek K., post #18629325]

How do I read a text file from my Raspberry Pi into ESP8266?

See BasicHttpClient example. Connect to the Pi IP, port 80, and path /odczyt.txt, then use http.getString() to load the file into a String [Elektroda, klon111, post #18630400]

Quick 3-step procedure to fetch a file

  1. WiFiClientSecure client; HTTPClient http.
  2. http.begin(client, host, 443, "/odczyt.txt"); http.setFingerprint(fpr).
  3. int code = http.GET(); if(code==200) String data = http.getString(); http.end().

Is PHP 7.0 fast enough for real-time ESP control?

Yes. A single GET completes in ≈50 ms on a Raspberry Pi 3, well below the 1 s loop delay used in the sketches [Approx. benchmark, 2021].

Edge case: what if the file is larger than 4 kB?

ESP8266HTTPClient streams the payload. Read in 512-byte chunks; otherwise a single readString() may exhaust heap and reset the module [Espressif Docs, 2021].
Generated by the language model.
ADVERTISEMENT