How do you enter values into a network tables in Java


#1

What is the method for adding network table values using java (frc documentation is not working because the methods are deprecating)


#2

I am assuming you are trying to get NT values off of something like a Raspberry Pi right? If so:

You need to create these 2 objects in robot:
public static NetworkTableInstance networkTableInstance = NetworkTableInstance.getDefault();
public static edu.wpi.first.networktables.NetworkTable networkTable;
The top one is the Instance and the bottom one is the actual table you are getting you’re data from
In RobotInit() you need to start your server and assign a keyname to your networktable:
networkTableInstance.startServer();
networkTable = networkTableInstance.getTable(“networkTable”);
Then to actually get values off your networktable you do this where you want to retrieve your value (in this case a double):
networkTable.getEntry(“desiredValue”).getDouble(defaultValue);


#3

is it essential to write networktableInstance.startServer()?


#4

If I understand correctly, it is not essential to start the server manually with startServer() since RobotBase does it for you. Source: https://github.com/wpilibsuite/allwpilib/blob/master/wpilibj/src/main/java/edu/wpi/first/wpilibj/RobotBase.java

If you use the non-default instance, it would be, but that’s probably not what you want to do here.


#5

I posted some code here that might be helpful.