Android Question Read value from web page

Azhar

Active Member
Licensed User
Longtime User
Hello,

I have created a simple Arduino project that acts as a web server and updates its web page of some numeric values and hosts a few buttons to control digital ports on it.
I use dynamic DNS, Port forwarding etc and everything is fine.

I have written a B4A application to send requests to those buttons on the web page to switch on/off digital ports on the Arduino - no problems there.

What I would like to do is to program my B4A application to read the data values from the web page into the B4A application to display (and later, act upon them etc).

Can anyone point me in the right direction to get started on that? I.e. to program to extract data values from the web page's text boxes.

Many thanks,

Azhar
 

Linostar

Member
Licensed User
Longtime User
You can make your webpage save the textboxes values periodically in a file, and your app download that file and read the values from there.
 
Upvote 0

nwhitfield

Active Member
Licensed User
Longtime User
If you want to keep the webpage more or less the same, allowing access from a browser, and not have a separate JSON or other file, you could use extended attributes in the web page, which could be easily parsed by using a pattern match in B4A. For instance, if the current web page contains something like

HTML:
<p>Port 1: on</p>

You could probably fairly easily change that to include some extra tags, using the more or less standard data-xxx way of defining an attribute, so you have something like this in the code:

HTML:
<p id="port1" data-port1-status="on">Port 1: on</p>

Then, your B4A code looks for the string "data-port-1-status=" in the code of the web page, and checks for the value. People looking at the output of the arduino in a web browser will see no difference to the page at all.
 
Upvote 0

Azhar

Active Member
Licensed User
Longtime User


Hi, I'll give it a whirl. Thanks for that. I'm not so hot on HTML.
I think only PHP can save textbox values to a file and the Arduino itself is hosting the webpage. Not sure whether JSON will work on Arduino either but I thank you for your contributions.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Do you have control over the website? If so you could display the page in a webview with javascriptinterface (search forum for it) and then you can put javascript-commands in your page giving or setting values from/to app.

See webviewextras-tutorial
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…