Fetch txt file from Web

Hi there,

i just experiment with my brand new spark and now i’m kind of stuck.
i connected a thermal printer to the spark and can print variables over the cloud.
now i’m trying to fetch a txt file from the web (eg example.com/test.txt) to a variable to the spark, then i’d like to print this variable with the thermal printer.
anyone an idea how to fetch the txt file to a variable?

Thanks and Greetings from Germany

Depending on how large your text file is, you may want to download it in chunks and print each chunk as you get it. If the printer takes a long time to print each chunk you may have to buffer the file into an SD card first, then read and print each chunk from the SD card.

I have an example here of grabbing data from the web. You could point this to any file and get the same results.

One thing you are going to have to do is detect where the end of the response header is, and your file begins. That’s not in my example.

Also here’s the SD card stuff:

Let us know how it goes!

So you need a TCPClient to connect to the server, grab the txt file content and simple output to your printer.

Not too difficult for that matter!

Take a look at this: