Reputation: 59
I have a wi-fi module connected to my arduino uno. There is server setup using it. The Wi-Fi is sending data(<p>Start</p>
) on IP address 192.168.4.1. Now if I connect my PC to the hotspot created using Wi-Fi module and open browser and go to address http://192.168.4.1/ then text 'Start' is displayed.
I have to take that text in MATLAB. I found this page.
http://in.mathworks.com/help/matlab/matlab_external/example--reading-a-url.html?searchHighlight=url
This is the code I am using apparently it works on very few websites like mathworks.com and snapdeal.com.
Here is the code I am using.
clear all;
clc;
url = java.net.URL(...
'http://192.168.4.1')
is = openStream(url);
isr = java.io.InputStreamReader(is);
br = java.io.BufferedReader(isr);
p1 = java.lang.String('<p>');
p2 = java.lang.String('</p>');
s = readLine(br);
while ~(s.startsWith(p1))
s = readLine(br);
end
s
Here is the output..
url =
http://192.168.4.1
Error using test (line 5)
Java exception occurred:
java.io.IOException: Invalid
Http response
at
sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown
Source)
at
java.net.URL.openStream(Unknown
Source).
Please tell me the possible solution.
Upvotes: 0
Views: 395
Reputation: 2469
are you sure your webpage is setup correctly? Can you view the source code and verify it actually says <p>Start</p>
To do this in in chrome or IE navigate to the page and press ctrl+u
to view source
You also might need to add more than just your paragraph to your web page. I'm not sure what exactly your sever is doing but here is a good example http://www.w3schools.com/tags/tag_doctype.asp
I think when you view the source code to REALLY work it needs to look mroe like this
{!DOCTYPE html}
{html}
{p}Start{/p}
{/html}
I replaced all the <>
with {}
otherwise stack overflow interprets it and displays it as a regular paragraph
Upvotes: 1