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.
|
Use Phidgets Wirelessly with the SBC
The project described here is a basic network control program for an LED plugged in to an 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. Here, we also provide in-depth instructions on installing external libraries on the SBC from source, and from an SVN trunk. We then show how to use the microhttpd.h library within C code to communicate with and control attached Phidgets.
Note: This is a complex way of doing something that the SBC can do much more simply. This page uses the simple example of using an Interface Kit over the network to demonstrate the much more complex concept of using embedded C HTTP servers. An embedded server is a powerful beast, and wanting to create one probably means you've grown needs above and beyond our simple Application Guides. The simpler guides are:
- If you just want to get Phidget data over the network, the SBC already does this naturally from the time it ships. We show an application in the Use Phidgets Wirelessly with the SBC guide.
Time: About a day
Special Needed Tools: A Phidget SBC, Ethernet and power cords (or Wireless), an LED, and your computer.
You should have already worked through the 1072 - Getting Started page before this one to have set up the network on your SBC and obtained its IP or local link address.
Introduction
When the SBC is powered on and connected to a network, it automatically handles any network requests for the Phidgets attached to it. All sensor and other Phidget data is broadcast over the local network as it changes, and all incoming Phidget control requests to the SBC over the local network are directed to the appropriate Phidgets.
This Webservice system looks something like this:
To create these requests to control the attached Phidgets, or to receive incoming sensor data, we write code on the controlling and receiving computer. This application guide simply blinks an LED plugged in to the SBC, and does so over the network.
Phidgets
Code
#include <stdio.h>
#include <stdlib.h>
#include "phidget21.h"
int main(int argc, char* argv[]) {
int result;
int outputState;
int i;
CPhidgetInterfaceKitHandle interfaceKit = 0;
CPhidgetInterfaceKit_create(&interfaceKit);
CPhidget_openRemoteIP((CPhidgetHandle)interfaceKit, -1, "phidgetsbc.local", 5001, NULL);
result = CPhidget_waitForAttachment((CPhidgetHandle)interfaceKit, 10000);
if (result) {
printf("No Device!\n");
return 0;
}
outputState = 1;
CPhidgetInterfaceKit_setOutputState(interfaceKit, 0, outputState);
for (i = 0; i < 1000; i++) {
if (outputState) { outputState = 0; }
else { outputState = 1; }
CPhidgetInterfaceKit_setOutputState(interfaceKit, 0, outputState);
}
CPhidgetInterfaceKit_setOutputState(interfaceKit, 0, 0);
CPhidget_close((CPhidgetHandle)interfaceKit);
CPhidget_delete((CPhidgetHandle)interfaceKit);
return 0;
}