LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Request JavaScript Variable Values from a Website

Solved!
Go to solution

I have a local hardware device that displays device status data through a browser. If I open a browser, go to the local device url, and open the console, I can access the hardware status variables by typing "response[x]" where x is a possition in an array. This command will return the value for a given variable. I would like to access these variables in Labview so I can incorporate this device's status into my front panel. There is no documentation for other ways to communicate with this piece of hardware.

 

Is there a way in Labview to effectively load a website and open a javascript console with the website in order to request and monitor data?

 

I can't seem to find anything that is useful to this end. Thank you.

 

-A

0 Kudos
Message 1 of 9
(6,859 Views)

I found another forum post that may be helpful. 

 

http://forums.ni.com/t5/LabVIEW/i-want-use-google-map-api-in-VI-i-tried-so-mutch-to-do-it-i-used/td-...

 

Take a look at the "Map JavaScript (simplified).zip"

RF R&D
National Instruments
0 Kudos
Message 2 of 9
(6,769 Views)
First off, in terms of background, this (and the post following) might be helpful.

http://www.notatamelion.com/2015/06/01/understanding-web-io/

Second, remember that the primary technique JavaScript has for accessing a server is the same one LabVIEW can use: PHP.

Third, all browsers will let you look at the source code for a web page. That will show you a lot.

Fourth, talk to the vendor.

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
Message 3 of 9
(6,749 Views)

Thanks for the replies so far. From the google map example, I can now open websites in labview (and access the page for my hardware). This will be very helpful even if I can't get any further. I didn't seem to have any luck when trying to use .html and .js files with my device, as they did in the google maps api example. One obvious issue with the google map api code is that they have no way to receive data using the webbrowser invoke node (as far as I can tell), and what I'm looking to do is get data values back from the site.

 

To hopefuly make it a little clearer, here is a screan shot of the hardware interface. It is accessed by navigating to 192.168.50.50 and is primarily graphical, displaying the status of various sensors. By typing "response[X]" in console, I can get the value for many of these sensors, and I can read the source code for the page to figure out which values I care about. For example, response[2] is the value for the red 'Temp' light.

 

I've got a bunch more to read over, including:

http://forums.ni.com/t5/LabVIEW/ActiveX-and-IWebBrowser2/td-p/24432

http://forums.ni.com/t5/LabVIEW/How-to-send-a-URL-from-within-LabView/m-p/791309?view=by_date_ascend...

http://www.ni.com/example/25081/en/

https://decibel.ni.com/content/docs/DOC-2042

http://zone.ni.com/reference/en-XX/help/371361K-01/lvhowto/build_web_service/

but if there is an easy way to access a console for an open browser in labview and send/receive values to it, that would be exactly what I'm looking for, I think. Thanks.

 

Capture.PNG

0 Kudos
Message 4 of 9
(6,692 Views)

You may also want to look at the network tab and see if the page is making network requests that include that data. The Get Data and Pause buttons make me guess that it is making network requests to get the data (unless the buttons just refresh the page). If you do find a good URL that is providing the data you can use the HTTP Client VIs to query it and then parse out what you need.


Milan
Message 5 of 9
(6,681 Views)

So the device is sending data using POST, but I'm not sure how to get that data into Labview (see image below).

 

The relevant line in the javascript code being run by the hardware appears to be Line 120 from the file 192.168.50.50/js/main_noimage.js

YAHOO.util.Connect.asyncRequest('POST', '/cmd/getalldata', webserver.data_handler_callback);

Once Get Data is pressed, the hardware automatically sends this data, but if I try to use GET I can't figure out a way to get more than just the .html or .js file code, not the values being sent from the hardware.

 

I'll also need a way to automatically push the Get Data button in Labview. I think this code might work in javascript to do that, but not sure how to do this from Labview:

var newWin = window.open(siteYouHaveAccessTo);
newWin.document.getElementById('titlebutton').click();

 

I've attached the .html and the primary .js for the hardware below. I don't think the .html file tells anything useful (just sets up the page layout and calls a few .js files)

 

Capture7.PNG

 

Thanks for all the help. I'm not too familiar with javascript and network communications, but I feel like I'm getting close to a solution.

 

EDIT: And if I try using POST, I'm getting Error 42:

Capture8.PNG

0 Kudos
Message 6 of 9
(6,644 Views)
Solution
Accepted by topic author MDI-AJT

For the URL for the POST VI you have put just the ip address of the instrument. But from the javascript it looks like the full url includes /cmd/getalldata. So based on the ip addess in the screenshot you may need to do "192.168.50.50/cmd/getalldata" as the URL.

 

Also it looks like for the POST data you have just entered the string "getalldata" in the VI. You should look at the Headers for the Post messages in Chrome to see what POST data the JavaScript code is actually sending.


Milan
Message 7 of 9
(6,635 Views)
Solution
Accepted by topic author MDI-AJT

That worked! Thanks!

I had tried a bunch of different combinations of URL and Data values for GET and POST, but hadn't tried that one with POST.

 

HTTP Client POST

url: 192.168.50.50/cmd/getalldata

data: anything (or nothing) seems to work

 

Using GET with that URL returns a 404.

 

And I don't need to press Get Data at all, I can just call /cmd/getalldata whenever I want an update.

 

(And because I don't think I addressed this point, the manufacturer doesn't seem to have any available documentation to have figured this out without reading through the source files to get the right command names.)

 

Thanks again.

 

 

--------------------------------------------

 

This code works with a Synrad Firestar i401 Laser which has a web interface accessible from a web browser. This interface provides codes for various faults and warnings that might come up and can be used for troubleshooting laser problems. This LabVIEW code will pull a string of values from the laser via a POST to 192.168.50.50/cmd/getalldata with the values being returned in the body output of POST. These values can then be parsed in LabVIEW and evaluated and incorporated into an existing Front Panel. The meaning of the values returned can be figured out by reading the .js file 192.168.50.50/js/main_noimage.js. It is worth noting that a delay should be used between subsequent calls to /cmd/getalldata since it appears to timeout if requests are sent too rapidly (this delay can be short, well under 1000ms, but I haven't tested it for a better limit yet). For this device, the IP address can be manually set to a value of your choosing.

 

2.png

0 Kudos
Message 8 of 9
(6,625 Views)

As a quick final point (can't edit my last post anymore), all I really need is the HTTP POST vi with the string 192.168.50.50/cmd/getalldata passed to it as the url and then the data I want will be on the body output. I plan to integrate a browser with the rest of my code, but otherwise none of that other stuff is needed.

0 Kudos
Message 9 of 9
(6,587 Views)