#!/usr/bin/env python3
#
# This is a NetworkTables server (eg, the robot or simulator side).
#
# On a real robot, you probably would create an instance of the 
# wpilib.SmartDashboard object and use that instead -- but it's really
# just a passthru to the underlying NetworkTable object.
#
# When running, this will continue incrementing the value 'robotTime',
# and the value should be visible to networktables clients such as 
# SmartDashboard. To view using the SmartDashboard, you can launch it
# like so:
#
#     SmartDashboard.jar ip 127.0.0.1
#

import time
from networktables import NetworkTables

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

NetworkTables.enableVerboseLogging()
table = NetworkTables.getGlobalTable()

try:

    i = 0
    while True:
        try:
            print('dsTime:', table.getNumber('/SmartDashboard/dsTime'))
        except KeyError:
            print('dsTime: N/A')
    
        table.putNumber('/SmartDashboard/robotTime', i)
        time.sleep(1)
        i += 1

finally:
    NetworkTables.shutdown()