We’re thinking of having the code determine which robot it’s installed on so we can use a single code base for several bots. Is there any unique IDs or serial #s that can be read in from the roborio? MAC address?
This thread has some good answers
Yep, MAC address is your best bet. The RIO runs a POSIX-ish OS, so you should be able to get what you need from /sys/class/net
or so.
I think here is half of a solution but I need a guru or an NI expert to provide the other half. The beauty of this, if it can be made to work, is you can assign meaningful labels instead of cryptic ones.
On the roboRIO configuration page (my team is 4237 obviously)
http://roborio-4237-frc.local/#!/SystemConfig
there is a comments field that is remembered even if powered off
That’s the easy half but how do you access where that info stored?
Maybe you could do an http get and pull it off that page but that’s overkill if there is an easy to access field somewhere else.
edit - it was easy! Lucky Guess!
admin@roboRIO-4237-FRC:/etc# ls -lta
-rw-rw-r-- 1 admin ni 24 Aug 20 11:23 machine-info
admin@roboRIO-4237-FRC:/etc# cat mach*
PRETTY_HOSTNAME=“hello”
No programming needed to set it or check it. No programming needed change roboRIOs on a particular robot
Cool find. This would be an interesting addition to wpilib as a function teams could easily call.
Thanks. Need NI to verify this will work as guessed. I wonder if that PRETTY_HOSTNAME appears as a system parameter anywhere that is already available within programs? I looked at command line “set” and it wasn’t there. Would be a nice place to put it, though.
Edit:
This works in Java but a nice wrapper for everyone is better
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
final Path commentPath = Path.of(“/etc/machine-info”);
try {
var comment = Files.readString(commentPath);
System.out.println(comment);
} catch (IOException e) {
System.out.println(e);
}
PRETTY_HOSTNAME=“hello”
The script that runs the robot program sets a serialnum environment variable that should be unique to every Rio. I’m not sure where the text boxes in the web interface get stored.
In Java
System.getenv()
returns this including the serial number on the roboRIO external label
{FPGADeviceCode=0x7AAF, PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/frc/bin:/usr/local/natinst/bin, EDITOR=vi, serialnum=032398EA, DeviceCode=0x7AAE, TERM=dumb, TargetClass=cRIO, PWD=/, DeviceDesc=roboRIO 2.0, LANG=L1, SHLVL=3, _=/usr/local/frc/JRE/bin/java}
So the serial number solution is done but I still like the roboRIO-neutral and robot-specific PRETTY_HOSTNAME. Needs a little more effort but it’s worth it (if NI can verify it’s a reliable solution).
For the Java newbies here’s the complete statement
System.out.println(System.getenv(“serialnum”));
which prints
032398EA
for example - that’s my roboRIO.
Great find. Our roboRIO is locked in the school so I’ve had to manage without it.
It easy enough to replicate this on a non-RoboRIO running the stack by just setting the environment variable.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.