FieldPoint Family

cancel
Showing results for 
Search instead for 
Did you mean: 

Web page and cFP application.

Hi,

I would like to input some parameters to my application -- running on a cFP controller -- using a web page from the cFP's embedded Web Server.

Here are the details: let's say I have a LabVIEW-built application (.exe) running on my cFP. The cFP controller has a Web Server. When enabled, it publishes any HTML documents from its root folder. I can browse this page from any other remote machine with access to the cFP. I don't need LabVIEW run-time engine to do this.

So far so good. I would like to have a web page with a button on it. When this button on the web page is pressed from a remote machine, I want to pass this as a boolean input to one of my VIs in the running application.

To complicate things further, the remote machines will not have the LabVIEW run-time installed. So, Remote Panels are ruled out.

If the application was running on a PC (instead of the cFP), I could have used the CGI VIs from the Internet toolkit to pass the boolean input from the web page to the VI. But I can't use CGI VIs on cFP.

What options do I have for doing something like this?

Any input (pun intended) will be much appreciated.

-Khalid
0 Kudos
Message 1 of 10
(3,797 Views)
Two suggestions, neither particularly elegant:

1) In one of our cFP application we built a small web server that was just smart enough to
listen for our expected URL requests and reply (plus a default error page).  This gives
you complete control over how the application responds to any request so passing out
a boolean value when a certain link (button) is pressed is easy.  The disadvantage is
the reduced functionality of the web server and increased complexity of handling pages.

2) A 'wrapper' that just listens for a specific URL but otherwise passes any requests
through to the built in web server.  Listen on ip.address:8080 for the URL of your button
(hyperlink).  When it sees that specific URL respond to the application, otherwise pass
the request unaltered to the server (ip.address:80 or 127.0.0.1:80 should also work).
You will also have to handle the reply side of the conversation in the wrapper.

Hopefully someone can suggest simpler approaches!

Matt
Message 2 of 10
(3,793 Views)
Thanks for the response Matthew. I like the ideas you have presented.

So to build this custom "Web Server" or even the wrapper, am I right in understanding you as to just have a TCP listener on port 8080? Any broad tips on building this would be appreciated.

Thank you and best regards,

-Khalid
0 Kudos
Message 3 of 10
(3,764 Views)
Take a look at the attached.  tcp_fcn.vi is the basic listener; pass in port 8080 in this case.  Same
.vi is used to send the reponse.  Your application will have to properly parse the http request and
response; don't forget to handle a generic 'not found' case 😉

Error_x_timeout.vi just passes through any errors except timeouts.

Matt
Download All
Message 4 of 10
(3,753 Views)
Hi Matt,

Thanks for sharing the listener code. I am able to succesfully monitor any URL requests on a given port from a web page. I then parse the URL and get the values into my other VIs fine. Thanks for all the help so far!

However, I have one small problem: when I request the dummy URL from a web page, my browser is -- religiously -- waiting to display this URL. How do I respond to this? What would be a generic HTTP response? Should I be responding on a different port than that I am listening on (8000)? I guess I somehow need to send back a custom error page. Would appreciate if you can point me in the right direction for this as well.

Thanks much!

-Khalid
0 Kudos
Message 5 of 10
(3,723 Views)
Hi Matt,

After some head-scratching, and googling, I stumbled onto W3C's HHTP reference document. I wouldn't call it the most lucid document I have read. In any case, I figured out that I got to send a response of the following format:

HTTP/1.0 200 OK
(more header stuff)
CRLF
[Message Body]

I experimented with the above, and noticed that even though I sent the response right-away, the browser would not see the response until I closed the connection. Is this how it is supposed to be -- that each response is to be ended with a close-connection?

I am having a tough time figuring out the rest of the header for the HTTP response. Would appreciate if you could share the format of simple, working header.

Also, I was wondering if I can use the Status code of 307 ("Temporary Redirect") instead of the 200 ("OK") and direct the browser to the actual Web Server on the cFP (port 80). This way I don't have to respond with a page of my own. I however couldn't find where I would specify the forwarded address and port with the 307. Is this is even possible?

Thanks for any input.

Regards,

-Khalid
0 Kudos
Message 6 of 10
(3,715 Views)
Hi Khalid.  Attached is a response string exactly as it is submitted to the tcp_fcn.vi 'send' function.
You do have to close the connection with this approach.  There may be a way to avoid closing but
this met our needs 😉

I haven't tried any re-directs but I don't see why they wouldn't work once you get the HTTP syntax
figured out.  The W3C site is a good resource but it can be difficult to figure out exactly what you need.

Hope this helps.

Matt
Message 7 of 10
(3,710 Views)