LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

LabVIEW android connection

Yes - create the html/javascript etc. for your application and then create a Web Service that serves up the pages as static content. There's details on how to do that here: http://zone.ni.com/reference/en-XX/help/371361L-01/lvhowto/ws_static_content/

 

You'll need to modify the javascript so that it gets the websockets address (which is hardcoded in the example) from the IP address/DNS name that served up the page. Essentially you need some way of telling the javascript on the page what the IP address of the server application is - you could use another Web Service to request the IP/Port for the websockets server or just try to extract the IP from the URL you access.

 

I got the first part working (serving the static content from a myRIO) but never got around to getting the second part working - I don't think it would be too difficult though.

 

There are some other things that you'll need to do - such as managing multiple connections (if required) - there is a multiple client/server architecture in the LabVIEW examples but I do something slightly differently with Asynchronous VI calls.


LabVIEW Champion, CLA, CLED, CTD
(blog)
0 Kudos
Message 21 of 32
(1,028 Views)

Thanks for the quick reply Sam! Yes, in fact, i had tried doing what you have suggested in the first part. But, I got stuck in between as the port used by web service application server (8080) cannot be used by the TCP listener in the sample code and it returned me an error. Again, I am still going through resources to understand it fully..

 

Thanks

Arya

0 Kudos
Message 22 of 32
(1,017 Views)

Yes - well you can set the WebSockets port to any available port - I just used 8080 as it's a commonly used alternative to port 80 (the standard http port) and is more commonly allowed through firewalls - 81 is another commonly used alternative.

 

To change it, you'll just need to modify the javascript and the example VI to a different port and run it again.


LabVIEW Champion, CLA, CLED, CTD
(blog)
0 Kudos
Message 23 of 32
(1,009 Views)

Thanks Sam! I have finally been able to run the sample code using web service on my development PC. Now, there seems to be some issue when I try to connect to it from another system in the same network (it is a DHCP server). I have been trying to solve this issue for quite sometime. I changed the javascript address to that of my development PC. When I call the webpage from a PC or smartphone in the same network, it loads the static page, but says that the connection is closed. I have also tried to change the port to someother port defined as TCP in my PC, but even that doesnt seem to work. 

 

Arya

0 Kudos
Message 24 of 32
(984 Views)

The example will only listen for a connection once (and only for a single connection) and then exit, so you will need to make sure you restart the VI before trying to connect from another device. 

 

It might also be a firewall issue? If it works on the same PC, but not from another PC then either the websocket address it's trying to connect to isn't correct or it can't connect to it due to a networking issue.


LabVIEW Champion, CLA, CLED, CTD
(blog)
0 Kudos
Message 25 of 32
(977 Views)

Yes, I had restarted the VI to run it again. Something strange that I have noticed is that, the line ' var socket = new Websocket (host) " does not make any difference at all! I tried commenting the line, and still it opens a connection in my dev PC. Could it be because the previous connection was not getting closed properly? 

 

Arya

0 Kudos
Message 26 of 32
(974 Views)

Hi Sam! I was not publishing the webserver each time i change the javascript. Hence the socket was still the same. Sorry for the confusion. But it still works only on my dev PC. I will just check if its a firewall issue. Thanks!

 

Arya

0 Kudos
Message 27 of 32
(952 Views)

Yes, I had exactly the same problem - hence why I suggested that you try and obtain the IP from your javascript, rather than having it hardcoded into the page - means you don't need to re-deploy the webservice each time! 🙂


LabVIEW Champion, CLA, CLED, CTD
(blog)
0 Kudos
Message 28 of 32
(931 Views)

Hi Sam! Thanks for the suggestion. I will try to implement the same once I establish a proper connection over the network. I verified the tcp port connectivity with two simple codes, one in my dev PC and another in a diff PC over the same network. But, between the same two systems and over the same port, I am unable to have a connectivity through webservice and the javascript (able to see the page, but it says connection closed). Putting the code on highlight mode tells me that the VI is still listening to the port and no connectivity has been established. I am still able to see an open connection through my dev PC. I think it is some silly mistake that I am making..

 

Thanks

Arya

0 Kudos
Message 29 of 32
(917 Views)

Hi Sam

 

I did a series of trials and it got running, my best guess is that opening the port was the reason for it to work. It still has some issue with IE which could be some settings issue. I tried your example on my real time controller, the data sending from the server to client was not working as expected, which I guess could be due to the event structure. Changed it to case structure and got it running. Will try to modify the code as per my requirements over the next few days (I am new to scripting) and will post the feedback in the thread. 🙂

 

Thanks

Arya

0 Kudos
Message 30 of 32
(897 Views)