Log in

View Full Version : Python Network Tables Raspberry Pi 2


tomy
12-05-2016, 21:28
I am looking for some in-site on the python network tables. I am using the example code found here (http://pynetworktables.readthedocs.io/en/latest/examples.html#driver-station-example). I try to run it and I get and error stating that I need to set my ipadress. I read up on the error here (http://pynetworktables.readthedocs.io/en/latest/troubleshooting.html#ensure-you-re-using-the-correct-mode). Where would you put the IP adress and what would it be? It doesn't seem to be that well explain for newbies. Thanks for any help ahead of time.

team-4480
12-05-2016, 21:42
I am looking for some in-site on the python network tables. I am using the example code found here (http://pynetworktables.readthedocs.io/en/latest/examples.html#driver-station-example). I try to run it and I get and error stating that I need to set my ipadress. I read up on the error here (http://pynetworktables.readthedocs.io/en/latest/troubleshooting.html#ensure-you-re-using-the-correct-mode). Where would you put the IP adress and what would it be? It doesn't seem to be that well explain for newbies. Thanks for any help ahead of time.

In the Driver Station example you linked, the IP is set through sys.arg. For me, I just skip that and set the IP directly like this:

NetworkTable.setIPAddress("10.XX.XX.XX")#Your IP goes here

So the entire code would look like this if you were using the example(This is untested but is similar to what I used before):

import time
from networktables import NetworkTable

# To see messages from networktables, you must setup logging
import logging
logging.basicConfig(level=logging.DEBUG)


NetworkTable.setIPAddress("10.XX.XX.XX")#Change the address to your own
NetworkTable.setClientMode()
NetworkTable.initialize()

sd = NetworkTable.getTable("SmartDashboard")

i = 0
while True:
try:
print('robotTime:', sd.getNumber('robotTime'))
except KeyError:
print('robotTime: N/A')

sd.putNumber('dsTime', i)
time.sleep(1)
i += 1

Just makes sure to change IP address and that should be a working example. Let me know if it still doesn't work!

tomy
12-05-2016, 22:08
In the Driver Station example you linked, the IP is set through sys.arg. For me, I just skip that and set the IP directly like this:

NetworkTable.setIPAddress("10.XX.XX.XX")#Your IP goes here

So the entire code would look like this if you were using the example(This is untested but is similar to what I used before):

import time
from networktables import NetworkTable

# To see messages from networktables, you must setup logging
import logging
logging.basicConfig(level=logging.DEBUG)


NetworkTable.setIPAddress("10.XX.XX.XX")#Change the address to your own
NetworkTable.setClientMode()
NetworkTable.initialize()

sd = NetworkTable.getTable("SmartDashboard")

i = 0
while True:
try:
print('robotTime:', sd.getNumber('robotTime'))
except KeyError:
print('robotTime: N/A')

sd.putNumber('dsTime', i)
time.sleep(1)
i += 1

Just makes sure to change IP address and that should be a working example. Let me know if it still doesn't work!

So if I am running this on a raspberry pi 2 I would put the ip adress of the roboRio? If so should I change the roboRio to a static IP address such as 10.xx.yy.?? --> xx.yy would be team name but what would the ?? be at the end?

Thanks for you help.

team-4480
12-05-2016, 22:13
So if I am running this on a raspberry pi 2 I would put the ip adress of the roboRio? If so should I change the roboRio to a static IP address such as 10.xx.yy.?? --> xx.yy would be team name but what would the ?? be at the end?

Thanks for you help.

Yes, you would put the address of the roboRio. It has been a while since I used networktables so I don't quite remember, but if I recall correctly, you can use roborio-xxxx-frc.local where xxxx is obviously your team number. If that doesn't work, you can use the 10.xx.xx.?? where the ?? is where the Rio is located on your network. To find this out, connect to the WiFi network and type "roborio-xxxx-frc.local" into your browser(again your team number) and the webpage for the Rio will pop up. There, you will see the exact address of the Rio.

tomy
12-05-2016, 22:31
Yes, you would put the address of the roboRio. It has been a while since I used networktables so I don't quite remember, but if I recall correctly, you can use roborio-xxxx-frc.local where xxxx is obviously your team number. If that doesn't work, you can use the 10.xx.xx.?? where the ?? is where the Rio is located on your network. To find this out, connect to the WiFi network and type "roborio-xxxx-frc.local" into your browser(again your team number) and the webpage for the Rio will pop up. There, you will see the exact address of the Rio.

On the trouble shooting link it states

Yes, I know it says setIPAddress... it will accept a hostname also. If you are team 1234, then the hostname would be ‘roborio-1234.local’. Make sure you have an mDNS client installed on the coprocessor (like avahi)

Do you know how avahi works?

team-4480
12-05-2016, 22:42
Do you know how avahi works?

I haven't ever used it since I have always used the driver station for vision(which is what I assume the Pi is for). It appears that avahi is available through "apt-get" which would pretty easy to install then. Have you tried the script without installing avahi? Does it not work?

tomy
12-05-2016, 22:52
I haven't ever used it since I have always used the driver station for vision(which is what I assume the Pi is for). It appears that avahi is available through "apt-get" which would pretty easy to install then. Have you tried the script without installing avahi? Does it not work?

I haven't tried it yet. I'm just thinking ahead in case it doesn't work. Thanks again for you help I will let you know if it works tomorrow.

virtuald
13-05-2016, 11:22
When using a coprocessor (at least this year), you're better off setting everything up with static IPs. There are issues connecting to the roborio when mDNS is used.

euhlmann
13-05-2016, 12:24
There are issues connecting to the roborio when mDNS is used.
Quite unsurprisingly.

Arhowk
13-05-2016, 12:52
Quite unsurprisingly.

Yeah my team had a plethora of issues in districts than worked totally fine at MICMP and CMP after switching to static. mDNS just isn't as battle tested as static ip

tomy
13-05-2016, 13:49
Yeah my team had a plethora of issues in districts than worked totally fine at MICMP and CMP after switching to static. mDNS just isn't as battle tested as static ip


I've heard about people having troubles with mDNS but I dont know what it is or how to change it? Can someone explain it to me?

euhlmann
13-05-2016, 17:55
I've heard about people having troubles with mDNS but I dont know what it is or how to change it? Can someone explain it to me?

Assign a static IP (such as 10.te.am.2) for the roborio on the networking tab of its NI web dashboard.
http://i.imgur.com/7jFjOEz.png
Choose "static" in the dropdown and then enter the static IP you want.

tomy
13-05-2016, 18:10
Assign a static IP (such as 10.te.am.2) for the roborio on the networking tab of its NI web dashboard.
http://i.imgur.com/7jFjOEz.png
Choose "static" in the dropdown and then enter the static IP you want.

Thank you! That helps a lot.