Filter löschen
Filter löschen

Why does webread() fail to find my host?

3 Ansichten (letzte 30 Tage)
zach tyler
zach tyler am 14 Nov. 2020
Kommentiert: zach tyler am 28 Nov. 2020
I'm writing a script to scrape .csv file data from a webserver hosted on an ESP8266. The webserver works -- I can access the .csv data stored there through my web browser. When I try to scrape that data into MATLAB using the code below, webread() fails. Interestingly I can comment out one of the calls to webread() and the other will work. What gives?
The data is the UNIX timestamp and a temperature or distance measurement separated by a comma and delimited by newlines, if that's relevant. MATLAB reads it as a 1 x n char.
% to prevent matlab from erroring out during the webread, set up a while
% loop:
i = 1;
e = 0;
I = 100;
while i < I
try
% specify the url of the .csv:
urlT = 'http://esp8266.local/temp.csv';
% read the contents of the url with matlab's webread:
T = webread(urlT);
% specify a new url and read it into a char array:
urlD = 'http://esp8266.local/dist.csv';
D = webread(urlD);
i = i + 1;
e = 0;
catch
fprintf("webread was unsuccessful; waiting to try again.\n");
pause(0.5);
e = e + 1;
if e > 50
keyboard
end
end
end

Antworten (1)

Rohit Pappu
Rohit Pappu am 24 Nov. 2020
webread() might not be able to process the CSV file, directed by the URL. A possible workaround could be
D = webread(url, 'table'); %% Explicitly mention that the url points to a CSV file
%% Alternatively, download the csv file into a filename
filename = 'dummy.csv';
D = websave(filename,url);
Additional documentation about websave()
  1 Kommentar
zach tyler
zach tyler am 28 Nov. 2020
Really interesting -- this is exactly the sort of functionality I was hoping for, but couldn't find initially (I'm a newbie). Thanks, I will give this a try.

Melden Sie sich an, um zu kommentieren.

Produkte


Version

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by