Phidget Network Server: Difference between revisions

From Phidgets Support
(25 intermediate revisions by 5 users not shown)
Line 1: Line 1:
[[Category:Overview]]
[[Category:Programming]]{{Recommended_Flow_Links|{{Flow Page Number|{{PAGENAME}} }} }}
__TOC__
__NOTOC__
The Phidget Network Server is a feature of Phidgets that makes it possible to control or interact with Phidgets connected to other computers on your local network.


==General Overview==
==General Overview==
The Phidget Network Server is a feature of Phidgets that makes it possible to control or interact with Phidgets connected to other computers on your local network. To understand how it works, let's first take a look at what a system looks like without the Network Server enabled:


Once the Phidget Network Server is enabled, your computer hosts a '''Phidget Server''' which broadcasts all connected Phidgets to other computers on your network. When another computer tries to open a channel, these Phidgets will be included in the list of channels that can be attached.


Phidgets attached over a Phidget Network server can be addressed, opened, and attached in much the same way as local Phidgets, so long as the program has access to the Network Server hosting the Phidgets.


Channels that are attached remotely may be opened by multiple programs simultaneously using the Phidget Network Server. There are some exceptions, such as motor controllers, that will never match more than one channel at a time for safety reasons.


[[Image:Phidgets_without_NetworkServer.jpg|link=|500px|right]]
[[Image:NetworkServer_PhidgetServer.jpg|link=|800px]]


When you open a Phidget, you have the option of opening it '''locally''' or '''remotely'''.


Opening a Phidget '''locally''' means communicating with it directly. You can only locally open Phidgets that are physically connected to the computer running your program.


At the top you have your computer, which has the Phidgets drivers installed. Connected via USB are a number of USB Phidgets and/or [[What_is_VINT?|VINT Hubs]]. Connected to the VINT Hubs could be VINT devices.
Opening a Phidget '''remotely''' means communicating with it using the Network Server. You can remotely open any Phidget on your network, even ones that are physically connected to the computer running your program.


'''''IsLocal''''' and '''''IsRemote''''' serve as additional Addressing Properties when a Phidget Network Server is used in your application, and are used to specify if a Phidget should be attached locally or remotely. If you are opening a Phidget your computer is physically connected to and your program uses the Phidget Network Server, it is strongly recommended to specify if you intend to connect to it locally or remotely.


All of these connected Phidgets have various channels that can be opened, which allow the program running on your computer to read data from them or control their various parts.
==Using The Network Server==
<!--
Each Operating System page has a section on how to use the Network Server on that operating system:


Notably, on Windows and Mac OS this can be handled from the '''Phidgets Control Panel''', under the ''Network Server'' tab.


Since the Network Server is disabled in this diagram, this computer is the only one that will be able to access these Phidgets.
* [[OS - Windows#Phidget Network Server|Windows]]
* [[OS - OS X#Phidget Network Server|Mac OS]]
* [[OS - Linux#Phidget Network Server|Linux]]
* [[OS - Phidget SBC#Phidget Network Server|Linux on the Phidget SBC]]
* [[OS - iOS#Phidget Network Server|iPhone/iPad iOS]]
 
The operating systems pages will tell you how to start and stop the Network Server on your computer, and how to run it with or without mDNS (Bonjour, avahi, etc).
-->


<br clear="all">
The specifics of running a Phidget Network Server on your machine depends on the operating system it is using. Select your operating system below for instructions:


Once the Phidget Network Server is enabled, your computer hosts a '''Phidget Server''' which broadcasts all connected Phidgets to other computers on your network. When another computer tries to open a channel, your Phidgets will be included in the list it selects the channel from.
<tabber>
=
===Select an Operating System for Instructions===
|-|
Windows=
{{Tabber_Tab_Title|Windows}}
In order to try the Phidget Network Server out, first download and install [https://www.apple.com/support/downloads/bonjourforwindows.html Bonjour for Windows] on your host computer and your client computer.
*'''Host computer:''' the computer that is physically connected to the Phidgets via USB and is running the Phidget Network Server.
*'''Client computer:''' a computer running a Phidgets application that accesses Phidgets connected to the host computer.
If you only have one computer, don't worry, your machine can act as both a host and a client.  


[[Image:NetworkServer_PhidgetServer.jpg|link=|800px]]


When you open a Phidget, you have the option of opening it '''locally''' or '''remotely'''.  
Next, open the Phidget Control Panel on your host computer. Do this by double-clicking on the [[File:Ph.jpg|link=]] icon in your taskbar, or by searching for ''Phidget Control Panel'' in the start menu.
Navigate to the Network Server tab, you will see something like this:
[[File:windows_networkserver.PNG|link=|center]]
 
 
From here, you can start, stop, or restart the Network Server. You can also decide how and when the Network Server will start.
[[File:windows_networkserver_startuptype.png|link=|center]]
 
 
Select ''Automatic'' as the startup type from the list and press the start button. By enabling automatic startup, the Network Server will run immediately after Windows boots, so you won't have to manually start it again.
 
 
Now that you have the Network Server running on your host computer, the next step will be accessing the Phidgets connected to your host computer from your client computer. Follow the steps below:
 
 
Open the Phidget Control Panel on your client computer. You will see something like this:
[[File:Windows_controlpanel_remote.PNG |link=|center]]
 
 
As you can see from the image above, Phidget servers are listed under the following heading:
*Remote Server: Servername (link local address)
 
 
You now have access to the Phidgets that are connected to your host computer. Try double-clicking one of them to bring up an example:
[[File:Windows_controlpanel_remoteexample.PNG|link=|center]]
 
 
Note the label in the example indicating a remote connection. This means the example is using the Phidget Network Server in order to communicate with the device.
|-|
macOS=
{{Tabber_Tab_Title|macOS}}
In order to try the Phidget Network Server out, you will need a host computer, and a client computer:
*'''Host computer:''' the computer that is physically connected to the Phidgets via USB and is running the Phidget Network Server.
*'''Client computer:''' a computer running a Phidgets application that accesses Phidgets connected to the host computer.
If you only have one computer, don't worry, your machine can act as both a host and a client.
 


Opening a Phidget '''locally''' means communicating with it directly. You can only locally open Phidgets that are physically connected to the computer running your program.
Next, open the Phidget Control Panel on your host computer. Do this by double-clicking on the [[File:Ph.jpg|link=]] icon in your applications folder. Navigate to the Network Server tab, you will see the following:
[[File:macos_networkserver.png|link=|center]]


Opening a Phidget '''remotely''' means communicating with it using the Network Service. You can remotely open any Phidget on your network, even ones that are physically connected to the computer running your program.


Why would you want to remotely open a Phidget that's physically attached to the computer? Well, a Phidget channel that is opened locally cannot be accessed by any other computer for as long as it's opened. A Phidget channel that is remotely opened, on the other hand, can be simultaneously opened by any number of programs.
From here, you can start or stop the Network Server. You can also decide when the Network Server will start.
[[File:macos_networkserver_run.png|link=|center]]


[[Image:NetworkServer_Local_Remote.jpg|link=|800px]]


As you can see in this example, there is a Phidget with four channels connected to one computer via USB. When it locally opens DigitalOutput channel 1, the other computer on the network is unable to open that channel remotely. Furthermore, that same computer cannot open a second instance of that channel using the network server because it's already opened it locally. On the other hand, both computers are able to open DigitalOutput channel 2 remotely, because it hasn't been opened locally by the host computer. Either computer in the diagram could remotely open several instances of DigitalOutput channel 2 in this way.
Check the automatic start box and enter a server name. By enabling automatic startup, the Network Server will run immediately after macOS boots, so you won't have to manually start it again. You can verify the Network Server is running by looking at the label beside the start/stop button.


==Using The Network Server==


Each Operating System page has a section on how to use the Network Server on that operating system:
Now that you have the Network Server running on your host computer, the next step will be accessing the Phidgets connected to your host computer from your client computer. Follow the steps below:


* [[OS - Windows#Phidget Network Server|Windows]]
* [[OS - OS X#Phidget Network Server|Mac OS]]
* [[OS - Linux#Phidget Network Server|Linux]]
* [[OS - Phidget SBC#Phidget Network Server|Linux on the Phidget SBC]]
* [[OS - iOS#Phidget Network Server|iPhone/iPad iOS]]


The operating systems pages have complete examples on how to set up a network server process and using it to remotely control or gather data from Phidgets. The pages also tell you how to start and stop the Network Server on your computer, and how to run it with or without mDNS (Bonjour, avahi, etc).
Open the Phidget Control Panel on your client computer. You will see something like this:
[[File:macos_controlpanel_remote.png|link=|center]]


== Connecting to a Network Server ==


There are two ways to gain access to a Phidget server that's being hosted on your network. If the server is broadcasting itself on mDNS, you can simply enable automatic server discovery in your program. In C#, for example, you would call the {{Code|Net.EnableServerDiscovery(ServerType.Device)}} method in your program. '''Net''' is the object that is used for Phidget Networking. You can find a full list of methods and properties in the {{Phidget22API}} by selecting "Networking API" in the drop-down menu.
As you can see from the image above, Phidget servers are listed under the following heading:
*Remote Server: Servername


If the Phidget server is not broadcasting itself on mDNS, you can connect to it by adding it specifically. In C#, for example, you would do this by calling the {{Code|Net.AddServer()}} method. AddServer takes a number of parameters that help specify the server to connect to (e.g. IP address, port, password). For more details on how to use AddServer, take a look at the "Networking API" in the {{Phidget22API}}.


==Network Server on a Phidget Single Board Computer==
You now have access to the Phidgets that are connected to your host computer. Try double-clicking one of them to bring up an example:
[[File:macos_controlpanel_remoteexample.png|link=|center]]


The Phidget Single Board Computer (SBC) can provide a compact, inexpensive way to easily run the Network Server.  It runs the Network Server in the background automatically from the moment you turn it on, and allows you to read from and control all Phidgets attached to it:


<<picture of SBC setup>>
Note the label in the example indicating a remote connection. This means the example is using the Network Server in order to communicate with the Phidget.
|-|
Linux=
{{Tabber_Tab_Title|Linux}}
In order to try the Phidget Network Server out, you will need a host computer, and a client computer with the Phidget libraries installed:
*'''Host computer:''' the computer that is physically connected to the Phidgets via USB and is running the Phidget Network Server.
*'''Client computer:''' a computer running a Phidgets application that accesses Phidgets connected to the host computer.
If you only have one computer, don't worry, your machine can act as both a host and a client.


This can allow for a compact, mobile-based system like this:


<<picture of SBC with mobile>>?
Next, open the terminal on the host computer and type in the following command to run the Network Server in the terminal:
<syntaxhighlight lang=bash>
phidget22networkserver
</syntaxhighlight>


The SBC runs Linux, which provides a [[OS - Phidget SBC|full operating system]] on which to develop code, {{ARTICLE|WebPageOnSBC|serve web pages}}, and {{ARTICLE|PhidgetsWirelesslyWithSBC|control Phidgets}}.
Or, as a daemon:
<syntaxhighlight lang=bash>
phidget22networkserver -D
</syntaxhighlight>


== Examples ==
Below are some quick examples showing how simple it is to open a Phidget remotely over the Network Server. In each example, a light sensor Phidget is being remotely opened on port 0 of a VINT Hub with serial number 37299.


{{hiddenh3|C/C++}}
[[File:Linux_networkserver.PNG|link=|center]]


<syntaxhighlight lang=cpp>
PhidgetLightSensorHandle ch;
PhidgetLightSensor_create(&ch);


Phidget_setDeviceSerialNumber((PhidgetHandle) ch, 37299);
The Network Server is now running on your machine with the default configuration. If you would like to change the Network Server configuration, you can do so by modifying the following file:
Phidget_setHubPort((PhidgetHandle) ch, 0);
*/etc/phidgets/phidget22networkserver.pc
Phidget_setIsRemote((PhidgetHandle) ch, 1);


Phidget_open((PhidgetHandle) ch);


You can also simply point towards your own configuration file with the following command:
<syntaxhighlight lang=bash>
phidget22networkserver -c /path/to/configuration/file
</syntaxhighlight>
</syntaxhighlight>


{{hiddenh3|C#}}


<syntaxhighlight lang='CSharp'>
Now that you have the Network Server running on your host computer, the next step will be accessing the Phidgets connected to your host computer from your client computer. Follow the steps below:
LightSensor ch = new LightSensor();
 
 
Open the terminal on the client computer and type in the following command (if you are using a single machine, simply open a new terminal session and continue):
<syntaxhighlight lang=bash>
phidget22admin -s
</syntaxhighlight>
[[File:Linux_networkserver_phidgetadmin.PNG|link=|center|850px]]
 


ch.DeviceSerialNumber = 37299;
This will list all of the Phidget Servers on your network. Confirm that you can see the Network Server running on your host computer.
ch.HubPort = 0;
ch.IsRemote = true;


ch.Open();


After you have confirmed your Network Server is running, type in the following command:
<syntaxhighlight lang=bash>
phidget22admin -R -d
</syntaxhighlight>
</syntaxhighlight>


{{hiddenh3|Java}}


<syntaxhighlight lang='Java'>
This command will list all remote Phidgets on the network. Confirm that you can see the Phidgets attached to your host computer:
LightSensor ch = new LightSensor();
[[File:Linux_networkserver_phidadminlist.PNG|link=|center]]
 
 
===Run Phidget Network Server on Boot===
If you would like the Network Server to run automatically when your computer boots, take a look at [{{SERVER}}/?view=articles&article=Daemon1 this project].
|-|
PhidgetSBC=
{{Tabber_Tab_Title|PhidgetSBC}}
In order to try the Phidget Network Server out, you will need a host computer, and a client computer with the Phidget libraries installed:
*'''Host computer:''' the computer that is physically connected to the Phidgets via USB and is running the Phidget Network Server.
*'''Client computer:''' a computer running a Phidgets application that accesses Phidgets connected to the host computer.
If you only have one computer, don't worry, your machine can act as both a host and a client.
 
 
The Phidget SBC comes with the Phidget Network Server installed, and the SBC automatically starts the Network Server on boot. In order to change any of this default behaviour, navigate to Phidgets->phidget22NetworkServer using the SBC Web Interface:
 
 
[[File:phidgetsbc_networkserver.PNG|link=|alt=|center]]
</tabber>
 
== Connecting to a Network Server ==
 
There are two ways to gain access to a Phidget server that's being hosted on your network. If the server is discoverable, you can simply enable automatic server discovery in your program. Select your programming language below to see a sample of how this is done.
 
<tabber>
Python=<syntaxhighlight lang=python>
Net.enableServerDiscovery(PhidgetServerType.PHIDGETSERVER_DEVICEREMOTE)
</syntaxhighlight>
|-|
Java=<syntaxhighlight lang=java>
Net.enableServerDiscovery(ServerType.DEVICE_REMOTE);
</syntaxhighlight>
|-|
C#=<syntaxhighlight lang=cSharp>
Net.EnableServerDiscovery(ServerType.DeviceRemote);
</syntaxhighlight>
|-|
C=<syntaxhighlight lang=c>
PhidgetNet_enableServerDiscovery(PHIDGETSERVER_DEVICEREMOTE);
</syntaxhighlight>
|-|
JavaScript=
In Javascript, instead of opening a Phidget using the network server, you can open it normally after connecting to the remote server that the Phidget belongs to. (In a sense, JavaScript is always opening Phidgets remotely)
</tabber>


ch.setDeviceSerialNumber(37299);
'''Net''' is the object that is used for Phidget Networking. You can find a full list of methods and properties available use with the network in the {{Phidget22API}} by selecting '''Networking API''' in the drop-down menu.
ch.setHubPort(0);
ch.setIsRemote(true);


ch.open();
If the Phidget server is not discoverable, you can connect to it by adding it specifically. This is done using {{code|AddServer}}, which takes a number of parameters that help specify the server to connect to (e.g. IP address, port, password). See below for an an example of adding a specific server, and take a look at the '''Networking API''' in the {{Phidget22API}} for details.


<tabber>
Python=<syntaxhighlight lang=python>
Net.addServer("ServerName", "192.168.2.20", 5661, "passwd", 0)
</syntaxhighlight>
</syntaxhighlight>
|-|
Java=<syntaxhighlight lang=java>
Net.addServer("ServerName", "192.168.2.20", 5661, "passwd", 0);
</syntaxhighlight>
|-|
C#=<syntaxhighlight lang=cSharp>
Net.AddServer("ServerName", "192.168.2.20", 5661, "passwd", 0);
</syntaxhighlight>
|-|
C=<syntaxhighlight lang=c>
PhidgetNet_addServer("ServerName", "192.168.2.20", 5661, "passwd", 0);
</syntaxhighlight>
|-|
JavaScript=
In Javascript, instead of opening a Phidget using the network server, you can open it normally after connecting to the remote server that the Phidget belongs to. (In a sense, JavaScript is always opening Phidgets remotely)
</tabber>
==Network Server on a Phidget Single Board Computer==
The [{{SERVER}}/products.php?product_id=SBC3003 Phidget Single Board Computer (SBC)] can provide a compact, inexpensive way to easily run the Network Server.  It runs the Network Server in the background automatically from the moment you turn it on, and allows you to remotely read from and control all Phidgets attached to it:
[[Image:network_server_sbc.jpg|link=|900px]]
In this example, a Phidget SBC is connected to a VINT Hub, which in turn is connected to a VINT device. By using the Network Server, it makes all of these channels available to any device connected to the same network. The Network Server on the SBC is discoverable by default.


{{hiddenh3|Python}}
This is convenient because it allows the Phidgets and sensors to be in a remote location, like mounted on a wall or inside some kind of assembly, rather than sitting on your computer desk. The channels of this system could be conveniently accessed by a home computer on the network, a phone running some Phidgets code, or even another Phidget SBC in a different location.
 
For more information on controlling Phidgets with your phone, have a look at the mobile section of our [[Operating System Support|operating system support]] page, or read {{ARTICLE|MurvRobotIOS|this article}} where we use [[OS_-_iOS|iOS]] to control a robot full of Phidgets.
 
== Examples ==
Below are some quick examples showing how simple it is to open a Phidget remotely over the Network Server. In each example, a light sensor Phidget is being remotely opened on port 0 of a VINT Hub with serial number 37299.


<syntaxhighlight lang='python'>
<tabber>
Python=<syntaxhighlight lang='python'>
ch = LightSensor()
ch = LightSensor()


Line 119: Line 258:
ch.setHubPort(0)
ch.setHubPort(0)
ch.setIsRemote(1)
ch.setIsRemote(1)
Net.enableServerDiscovery(PhidgetServerType.PHIDGETSERVER_DEVICEREMOTE)


ch.open();
ch.open();
</syntaxhighlight>
|-|
Java=<syntaxhighlight lang='Java'>
LightSensor ch = new LightSensor();
ch.setDeviceSerialNumber(37299);
ch.setHubPort(0);
ch.setIsRemote(true);


Net.enableServerDiscovery(ServerType.DEVICE_REMOTE);
ch.open();
</syntaxhighlight>
</syntaxhighlight>
|-|
C#=<syntaxhighlight lang='CSharp'>
LightSensor ch = new LightSensor();


== Web Server ==
ch.DeviceSerialNumber = 37299;
ch.HubPort = 0;
ch.IsRemote = true;


== Phidget Dictionaries ==
Net.EnableServerDiscovery(ServerType.DeviceRemote);
 
ch.Open();
</syntaxhighlight>
|-|
C=<syntaxhighlight lang=cpp>
PhidgetLightSensorHandle ch;
PhidgetLightSensor_create(&ch);
 
Phidget_setDeviceSerialNumber((PhidgetHandle) ch, 37299);
Phidget_setHubPort((PhidgetHandle) ch, 0);
Phidget_setIsRemote((PhidgetHandle) ch, 1);
 
PhidgetNet_enableServerDiscovery(PHIDGETSERVER_DEVICEREMOTE);
 
Phidget_open((PhidgetHandle) ch);
 
</syntaxhighlight>
|-|
JavaScript=
In Javascript, instead of opening a Phidget using the network server, you can open it normally after connecting to the remote server that the Phidget belongs to. (In a sense, JavaScript is always opening Phidgets remotely)
</tabber>
 
For more information, have a look at the {{Phidget22API}} and select your language from the drop-down menu. You can learn more about opening Phidgets on the [[Phidget_Programming_Basics#Opening_the_Phidget|Programming Basics]] page.


== Troubleshooting ==
== Troubleshooting ==


When using the Network Server, both the '''client and server should have the ''same version''''' of the Network Server installed.  The easiest way to ensure this is to update your libraries on both ends.
When using the Network Server, '''both the client and server should have the ''same version''''' of the Network Server installed.  The easiest way to ensure this is to update your libraries on both ends.
 
For other troubleshooting tips, try our [[Network Server Troubleshooting]] page.


For other troubleshooting tips, try our General Troubleshooting page, in its [[General_Troubleshooting#Network_Server_Troubleshooting|Network Server section]].
{{Flow_Navigation_Buttons|{{Flow Page Number|{{PAGENAME}} }} }}

Revision as of 19:31, 11 April 2019

 Phidget Programming Basics: Phidget Network ServerTOC Icon.png Table of Contents

Nav Back Arrow.png Nav Back Hover.png WhiteTab1.png HoverTab1.jpg WhiteTab2.png HoverTab2.jpg WhiteTab3.png HoverTab3.jpg WhiteTab4.png HoverTab4.jpg WhiteTab5.png HoverTab5.jpg WhiteTab6.png HoverTab6.jpg WhiteTab7.png HoverTab7.jpg WhiteTab8.png HoverTab8.jpg WhiteTab9.png HoverTab9.jpg WhiteTab10.png HoverTab10.jpg WhiteTab11.png HoverTab11.jpg WhiteTab12.png HoverTab12.jpg WhiteTab13.png HoverTab13.jpg WhiteTab14.png HoverTab14.jpg GreenTab15.png WhiteTab16.png HoverTab16.jpg Nav Next Arrow.png Nav Next Hover.png


15 . Phidget Network Server

The Phidget Network Server is a feature of Phidgets that makes it possible to control or interact with Phidgets connected to other computers on your local network.

General Overview

Once the Phidget Network Server is enabled, your computer hosts a Phidget Server which broadcasts all connected Phidgets to other computers on your network. When another computer tries to open a channel, these Phidgets will be included in the list of channels that can be attached.

Phidgets attached over a Phidget Network server can be addressed, opened, and attached in much the same way as local Phidgets, so long as the program has access to the Network Server hosting the Phidgets.

Channels that are attached remotely may be opened by multiple programs simultaneously using the Phidget Network Server. There are some exceptions, such as motor controllers, that will never match more than one channel at a time for safety reasons.

NetworkServer PhidgetServer.jpg

When you open a Phidget, you have the option of opening it locally or remotely.

Opening a Phidget locally means communicating with it directly. You can only locally open Phidgets that are physically connected to the computer running your program.

Opening a Phidget remotely means communicating with it using the Network Server. You can remotely open any Phidget on your network, even ones that are physically connected to the computer running your program.

IsLocal and IsRemote serve as additional Addressing Properties when a Phidget Network Server is used in your application, and are used to specify if a Phidget should be attached locally or remotely. If you are opening a Phidget your computer is physically connected to and your program uses the Phidget Network Server, it is strongly recommended to specify if you intend to connect to it locally or remotely.

Using The Network Server

The specifics of running a Phidget Network Server on your machine depends on the operating system it is using. Select your operating system below for instructions:

Select an Operating System for Instructions

Windows

In order to try the Phidget Network Server out, first download and install Bonjour for Windows on your host computer and your client computer.

  • Host computer: the computer that is physically connected to the Phidgets via USB and is running the Phidget Network Server.
  • Client computer: a computer running a Phidgets application that accesses Phidgets connected to the host computer.

If you only have one computer, don't worry, your machine can act as both a host and a client.


Next, open the Phidget Control Panel on your host computer. Do this by double-clicking on the Ph.jpg icon in your taskbar, or by searching for Phidget Control Panel in the start menu. Navigate to the Network Server tab, you will see something like this:

Windows networkserver.PNG


From here, you can start, stop, or restart the Network Server. You can also decide how and when the Network Server will start.

Windows networkserver startuptype.png


Select Automatic as the startup type from the list and press the start button. By enabling automatic startup, the Network Server will run immediately after Windows boots, so you won't have to manually start it again.


Now that you have the Network Server running on your host computer, the next step will be accessing the Phidgets connected to your host computer from your client computer. Follow the steps below:


Open the Phidget Control Panel on your client computer. You will see something like this:

Windows controlpanel remote.PNG


As you can see from the image above, Phidget servers are listed under the following heading:

  • Remote Server: Servername (link local address)


You now have access to the Phidgets that are connected to your host computer. Try double-clicking one of them to bring up an example:

Windows controlpanel remoteexample.PNG


Note the label in the example indicating a remote connection. This means the example is using the Phidget Network Server in order to communicate with the device.

macOS

In order to try the Phidget Network Server out, you will need a host computer, and a client computer:

  • Host computer: the computer that is physically connected to the Phidgets via USB and is running the Phidget Network Server.
  • Client computer: a computer running a Phidgets application that accesses Phidgets connected to the host computer.

If you only have one computer, don't worry, your machine can act as both a host and a client.


Next, open the Phidget Control Panel on your host computer. Do this by double-clicking on the Ph.jpg icon in your applications folder. Navigate to the Network Server tab, you will see the following:

Macos networkserver.png


From here, you can start or stop the Network Server. You can also decide when the Network Server will start.

Macos networkserver run.png


Check the automatic start box and enter a server name. By enabling automatic startup, the Network Server will run immediately after macOS boots, so you won't have to manually start it again. You can verify the Network Server is running by looking at the label beside the start/stop button.


Now that you have the Network Server running on your host computer, the next step will be accessing the Phidgets connected to your host computer from your client computer. Follow the steps below:


Open the Phidget Control Panel on your client computer. You will see something like this:

Macos controlpanel remote.png


As you can see from the image above, Phidget servers are listed under the following heading:

  • Remote Server: Servername


You now have access to the Phidgets that are connected to your host computer. Try double-clicking one of them to bring up an example:

Macos controlpanel remoteexample.png


Note the label in the example indicating a remote connection. This means the example is using the Network Server in order to communicate with the Phidget.

Linux

In order to try the Phidget Network Server out, you will need a host computer, and a client computer with the Phidget libraries installed:

  • Host computer: the computer that is physically connected to the Phidgets via USB and is running the Phidget Network Server.
  • Client computer: a computer running a Phidgets application that accesses Phidgets connected to the host computer.

If you only have one computer, don't worry, your machine can act as both a host and a client.


Next, open the terminal on the host computer and type in the following command to run the Network Server in the terminal:

phidget22networkserver

Or, as a daemon:

phidget22networkserver -D


Linux networkserver.PNG


The Network Server is now running on your machine with the default configuration. If you would like to change the Network Server configuration, you can do so by modifying the following file:

  • /etc/phidgets/phidget22networkserver.pc


You can also simply point towards your own configuration file with the following command:

phidget22networkserver -c /path/to/configuration/file


Now that you have the Network Server running on your host computer, the next step will be accessing the Phidgets connected to your host computer from your client computer. Follow the steps below:


Open the terminal on the client computer and type in the following command (if you are using a single machine, simply open a new terminal session and continue):

phidget22admin -s
Linux networkserver phidgetadmin.PNG


This will list all of the Phidget Servers on your network. Confirm that you can see the Network Server running on your host computer.


After you have confirmed your Network Server is running, type in the following command:

phidget22admin -R -d


This command will list all remote Phidgets on the network. Confirm that you can see the Phidgets attached to your host computer:

Linux networkserver phidadminlist.PNG


Run Phidget Network Server on Boot

If you would like the Network Server to run automatically when your computer boots, take a look at this project.

PhidgetSBC

In order to try the Phidget Network Server out, you will need a host computer, and a client computer with the Phidget libraries installed:

  • Host computer: the computer that is physically connected to the Phidgets via USB and is running the Phidget Network Server.
  • Client computer: a computer running a Phidgets application that accesses Phidgets connected to the host computer.

If you only have one computer, don't worry, your machine can act as both a host and a client.


The Phidget SBC comes with the Phidget Network Server installed, and the SBC automatically starts the Network Server on boot. In order to change any of this default behaviour, navigate to Phidgets->phidget22NetworkServer using the SBC Web Interface:


Connecting to a Network Server

There are two ways to gain access to a Phidget server that's being hosted on your network. If the server is discoverable, you can simply enable automatic server discovery in your program. Select your programming language below to see a sample of how this is done.

Net.enableServerDiscovery(PhidgetServerType.PHIDGETSERVER_DEVICEREMOTE)
Net.enableServerDiscovery(ServerType.DEVICE_REMOTE);
Net.EnableServerDiscovery(ServerType.DeviceRemote);
PhidgetNet_enableServerDiscovery(PHIDGETSERVER_DEVICEREMOTE);

In Javascript, instead of opening a Phidget using the network server, you can open it normally after connecting to the remote server that the Phidget belongs to. (In a sense, JavaScript is always opening Phidgets remotely)

Net is the object that is used for Phidget Networking. You can find a full list of methods and properties available use with the network in the Phidget22 API by selecting Networking API in the drop-down menu.

If the Phidget server is not discoverable, you can connect to it by adding it specifically. This is done using AddServer, which takes a number of parameters that help specify the server to connect to (e.g. IP address, port, password). See below for an an example of adding a specific server, and take a look at the Networking API in the Phidget22 API for details.

Net.addServer("ServerName", "192.168.2.20", 5661, "passwd", 0)
Net.addServer("ServerName", "192.168.2.20", 5661, "passwd", 0);
Net.AddServer("ServerName", "192.168.2.20", 5661, "passwd", 0);
PhidgetNet_addServer("ServerName", "192.168.2.20", 5661, "passwd", 0);

In Javascript, instead of opening a Phidget using the network server, you can open it normally after connecting to the remote server that the Phidget belongs to. (In a sense, JavaScript is always opening Phidgets remotely)

Network Server on a Phidget Single Board Computer

The Phidget Single Board Computer (SBC) can provide a compact, inexpensive way to easily run the Network Server. It runs the Network Server in the background automatically from the moment you turn it on, and allows you to remotely read from and control all Phidgets attached to it:

Network server sbc.jpg

In this example, a Phidget SBC is connected to a VINT Hub, which in turn is connected to a VINT device. By using the Network Server, it makes all of these channels available to any device connected to the same network. The Network Server on the SBC is discoverable by default.

This is convenient because it allows the Phidgets and sensors to be in a remote location, like mounted on a wall or inside some kind of assembly, rather than sitting on your computer desk. The channels of this system could be conveniently accessed by a home computer on the network, a phone running some Phidgets code, or even another Phidget SBC in a different location.

For more information on controlling Phidgets with your phone, have a look at the mobile section of our operating system support page, or read this article where we use iOS to control a robot full of Phidgets.

Examples

Below are some quick examples showing how simple it is to open a Phidget remotely over the Network Server. In each example, a light sensor Phidget is being remotely opened on port 0 of a VINT Hub with serial number 37299.

ch = LightSensor()

ch.setDeviceSerialNumber(37299)
ch.setHubPort(0)
ch.setIsRemote(1)

Net.enableServerDiscovery(PhidgetServerType.PHIDGETSERVER_DEVICEREMOTE)

ch.open();
LightSensor ch = new LightSensor();

ch.setDeviceSerialNumber(37299);
ch.setHubPort(0);
ch.setIsRemote(true);

Net.enableServerDiscovery(ServerType.DEVICE_REMOTE);

ch.open();
LightSensor ch = new LightSensor();

ch.DeviceSerialNumber = 37299;
ch.HubPort = 0;
ch.IsRemote = true;

Net.EnableServerDiscovery(ServerType.DeviceRemote);

ch.Open();
PhidgetLightSensorHandle ch;
PhidgetLightSensor_create(&ch);

Phidget_setDeviceSerialNumber((PhidgetHandle) ch, 37299);
Phidget_setHubPort((PhidgetHandle) ch, 0);
Phidget_setIsRemote((PhidgetHandle) ch, 1);

PhidgetNet_enableServerDiscovery(PHIDGETSERVER_DEVICEREMOTE);

Phidget_open((PhidgetHandle) ch);

In Javascript, instead of opening a Phidget using the network server, you can open it normally after connecting to the remote server that the Phidget belongs to. (In a sense, JavaScript is always opening Phidgets remotely)

For more information, have a look at the Phidget22 API and select your language from the drop-down menu. You can learn more about opening Phidgets on the Programming Basics page.

Troubleshooting

When using the Network Server, both the client and server should have the same version of the Network Server installed. The easiest way to ensure this is to update your libraries on both ends.

For other troubleshooting tips, try our Network Server Troubleshooting page.