Basic Network Table Test Fails

Hello,
So my team is planning on using Vision Processing this year to help with the shooter, and a precursory step to this is manipulating Network Tables. Today I was working on a basic example between the RoboRIO (C++) and a Java Client on a Mac (Java). The basic scenario is that the roboRio creates a network table (Net) and posts to it the variable Test with the value of 10. The client program then connects to the RoboRIO, and attempts to read the Net/Test value from the RoboRIO. However, the client fails to read the value from the network table and I am not sure why as both programs have repeatedly been dumbed down until there is hardly anything left. Any advice/suggestions would be much appreciated.

    Thanks a bunch,
            Henry

Here are the logistics:

Setup:

  • C++ Iterative Robot Code
  • Java Client Program on Mac
    • Links to the jar discussed in the screensteps tutorial

Result:

  • Server (RoboRIO Code) seems to run fine. The Network Table (Net) and it’s value for Test are displayed in the variables tab of the SmartDashboard.

  • Client (Java - Mac) does not run as hoped. The code cannot find the Net/Test value and thus returns -1. Meanwhile, the SmartDashboard Console is spammed with NT: server: client CONNECTED: 10.51.4.198 port 5**** with ever-increasing port numbers.

  • On the Client Side, the lines of “Test: -1” are split up by alternate outputs of…
    edu.wpi.first.wpilibj.networktables2.client.ClientConnectionAdapter@b4c966a entered connection state: DISCONNECTED_FROM_SERVER

    and

edu.wpi.first.wpilibj.networktables2.client.ClientConnectionAdapter@b4c966a entered connection state: CONNECTED_TO_SERVER

  • Disabling the robot continues these console outputs until the client program is terminated.

Below, I have stripped the programs down to the basics, eliminating extraneous print statements and empty functions. As there is so little code, I can’t imagine what is going wrong?


Server Code: (The Relevant Stuff)

#include “WPILib.h”
#include “NetworkTables/NetworkTable.h”

class Robot: public IterativeRobot {

public:
// Network Table Test
std::shared_ptr<NetworkTable> table;

Robot():
{
	table = NetworkTable::GetTable("Net");
}

private:

void TeleopPeriodic(){
	table-&gt;PutNumber("Test",10);
}

};

START_ROBOT_CLASS(Robot)

Client Code: (The Relevant Stuff)

import edu.wpi.first.wpilibj.networktables.NetworkTable;

public class Client {

public static void main(String] arg){
	
	NetworkTable.setClientMode();
	NetworkTable.setIPAddress("10.51.4.105");
	
	NetworkTable table = NetworkTable.getTable("Net");
	
	while (true){
		
		double test = table.getNumber("Test", -1);
		
		System.out.printf("Test: %f

",test);

	}
}

}

That looks like you are using a VERY old version of NetworkTables. What screensteps page did you find that on?

The newest version can be found at http://first.wpi.edu/FRC/roborio/maven/release/edu/wpi/first/wpilib/networktables/java/NetworkTables/3.1.5/NetworkTables-3.1.5-desktop.jar. Try using that jar instead, as that has been tested to work with the newest robot version of NetworkTables.

The only thing I’m going to recommend changing is in your Java code, use setTeam(5104) rather then setIPAddress. setTeam has mechanisms built in to help connect easier.

Thanks so much for your quick reply. Now that I look at it, the screensteps page I was working off of was from 2014 (EEK!). I don’t know why that came up instead of the more recent pages, but I guess it’s my fault for not using an updated tutorial.

Thanks for the updated jar file, it works perfectly. All problems solved.