Alert.png

Notice: This page contains information for the legacy Phidget21 Library.

Phidget21 is out of support. Bugfixes may be considered on a case by case basis.

Phidget21 does not support VINT Phidgets, or new USB Phidgets released after 2020. We maintain a selection of legacy devices for sale that are supported in Phidget21.

We recommend that new projects be developed against the Phidget22 Library.


Click on the 2phidget22.jpg button in the menu bar to go to the Phidget22 version of this page.

Alert.png

Web Page on the SBC: Difference between revisions

From Phidgets Legacy Support
Line 48: Line 48:
==Code==
==Code==


First, we build a static web page with no Phidget involvement.  If you just want to host a few pages on the SBC, that part of the example will help greatly. 


Then we write a separate and unrelated Python script, save it in the SBC's cgi-bin directory, and run it over the network.
===Static Page===
To create a web page hosted on the SBC, you simply have to create one and save it in the {{Code|/var/www/}} directory.
When you log into the SBC using [[OS - Phidget SBC#SSH|SSH]], you can move into that directory and start editing a simple HTML file by:
<div class="source">
<syntaxhighlight lang=bash>
cd /var/www
nano helloworld.html
</syntaxhighlight>
</div>
Then, type in a simple web page structure, such as this:
[[Image:app_guide_sbcweb_staticpage_nano.png|border|link=|alt=]]
Finally, go to that address in a browser on the same local network as the SBC, using the address {{Code|http://phidgetsbc.local/helloworld.html}} (replace the link local address of the SBC and the filename if you've changed them).  Which will give you something like this:
[[Image:app_guide_sbcweb_staticpage.png|border|link=|alt=]]


==Putting it All Together==
==Putting it All Together==

Revision as of 17:55, 19 March 2012

The project described here creates a website hosted on the Phidget Single Board Computer (SBC). The website can both serve static pages, as well as pages that can send simple requests back and forth to the Phidgets attached to the SBC.

With this kind of system, you only need to develop cross-browser compatible web pages, as the code to control the Phidget runs on the SBC.

Practical concepts covered are (click on links to see other projects on that topic):  


As with any of our described projects, Phidgets takes care of the electrical component design. This is a middle-ground solution to controlling Phidgets over a network using the SBC.

  • If you just want data to go back and forth between Phidgets and your computer - via the SBC - over the network, you probably want the simple example in the Use Phidgets Wirelessly with the SBC guide.
  • If you want something more powerful and flexible than the CGI in this guide to control Phidgets over a network, you may be interested in the full Web Server on the SBC guide.

Time: A few hours

Special Needed Tools: A Phidget SBC, Ethernet and power cords (or Wireless), an LED, and your computer.

You should also have:


Introduction

The SBC already runs a web server, with the pages to be served located in the /var/www directory. We take advantage of this by creating a web page using a cgi-bin Python script. Since the script is in Python, it can also control any attached Phidgets, including the Interface Kit on the SBC.

The flow of the system we will build looks like this:

Phidgets

For this, you will need:

  • A 1072 0 - PhidgetSBC2, set up as per the 1072 - Getting Started guide
    • This is the SBC that this guide used; others will probably work fine as well
  • An LED, such as one of the ones from Phidgets (many part numbers starting at 3600), attached to digital output port 0 (long wire) and ground (short wire)

Code

First, we build a static web page with no Phidget involvement. If you just want to host a few pages on the SBC, that part of the example will help greatly.

Then we write a separate and unrelated Python script, save it in the SBC's cgi-bin directory, and run it over the network.

Static Page

To create a web page hosted on the SBC, you simply have to create one and save it in the /var/www/ directory.

When you log into the SBC using SSH, you can move into that directory and start editing a simple HTML file by:

cd /var/www
nano helloworld.html

Then, type in a simple web page structure, such as this:

Finally, go to that address in a browser on the same local network as the SBC, using the address http://phidgetsbc.local/helloworld.html (replace the link local address of the SBC and the filename if you've changed them). Which will give you something like this:

Putting it All Together

Extra Credit