Why does webread() fail to find my host?
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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
0 Kommentare
Antworten (1)
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()
Siehe auch
Kategorien
Mehr zu Web Services finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!