Phidget Network Server and data return via UDP

Supporting Visual Studio on Windows
Post Reply
Fishmaster
Fresh meat
Posts: 2
Joined: Mon May 17, 2021 6:26 am
Contact:

Phidget Network Server and data return via UDP

Post by Fishmaster »

I'm working with a Phidget Interface Kit 2/2/2 to measure voltage on two channels from two separate batteries. I'm specifically attempting to use the 1135 precision sensor to do this and also do it remotely from another PC.

I'm hitting a snag with firewalls and security as it seems data is coming back via UDP instead of the original connection.

So far, the code I'm using would not give the precision sensor value, but rather the generic voltage SensorValue instead. I've traced this down to the actual SensorValue I want coming back in a UDP packet which is being blocked by the firewall.

Below code is what I'm currently using. It's part of a function called with the computer name which has the Phidget itself (I need to poll multiple workstations hence a function).

Code: Select all

VoltageInput voltageInput0 = new VoltageInput();
VoltageInput voltageInput1 = new VoltageInput();
voltageInput0.IsRemote = true;
voltageInput1.IsRemote = true;
voltageInput0.ServerName = wksName;
voltageInput1.ServerName = wksName;
voltageInput0.Channel = 0;
voltageInput1.Channel = 1;
voltageInput0.Open(Phidget.DefaultTimeout);
voltageInput1.Open(Phidget.DefaultTimeout);
Thread.Sleep(5000); // for testing purposes
voltageInput0.SensorType = Phidget22.VoltageSensorType.PN_1135;
voltageInput1.SensorType = Phidget22.VoltageSensorType.PN_1135;
batt0 = voltageInput0.SensorValue;
batt1 = voltageInput1.SensorValue;
log.Debug("Voltage: " + batt0 + " - " + batt1);
If I leave return traffic blocked in the firewall the UDP is dropped and I never get the correct value from the sensor. I can confirm it sets the correct SensorType by doing a get of SensorType, but unless the UDP packets get in 95% of the time the SensorValue only gives me the default voltage reading.

I can capture the packet with the data via Wireshark, below is what I see in the UDP stream, my missing precision voltage data (12.38V for Channel0 and 12.396V for Channel1).

Code: Select all

}}*.......0IHP......5....F{"v":0,"s":1,"f":1,"p":115,"I":1742552895792,"O":31885837736710,"X":0,"c":4,"e":{
"0":{"t":"g","v":1.238000e+01},
"UnitInfo.unit":{"t":"d","v":12},
"UnitInfo name":{"t":"s","v":"volt"},
"UnitInfo.symbol":{"t":"s","v":"V"}
}}+.......0IHP......7....F{"v":0,"s":1,"f":1,"p":115,"I":1742552979472,"O":72089479875664646,"X":1,"c":4,"e":{
"0":{"t":"g","v":1.239600e+01},
"UnitInfo.unit":{"t":"d","v":12},
"UnitInfo name":{"t":"s","v":"volt"},
"UnitInfo.symbol":{"t":"s","v":"V"}
}},.......
From what I can see the UDP is using a random port somewhere between 50000 and 65000, far too large of a range to get it past security and open on the firewall. Ideally, I'd rather get the data on the same connection I use to open to the Phidget remotely. I can't find a way to configure this though based on the API documentation. Is this possible at all?

Another possibility is limiting the UDP port range used for the reply, again I don't see this documented so is this possible?
User avatar
Patrick
Lead Developer
Posts: 634
Joined: Mon Jun 20, 2005 8:46 am
Location: Canada
Contact:

Re: Phidget Network Server and data return via UDP

Post by Patrick »

You can disable datagram (UDP) from the network server config file:

Code: Select all

phidget {
	...
	network {
		...
		datagram {
			enabled: false					# if UDP for events is allowed
		}
	}
}
Location of the config file depends on OS:

Windows: C:\ProgramData\Phidgets\phidget22networkserver.pc
macOS: /Library/Preferences/Phidget22NetworkServer/phidget22networkserver.pc
Linux: /etc/phidgets/phidget22networkserver.pc

-Patrick
Fishmaster
Fresh meat
Posts: 2
Joined: Mon May 17, 2021 6:26 am
Contact:

Re: Phidget Network Server and data return via UDP

Post by Fishmaster »

That's done the trick perfectly, thanks Patrick!
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests