Skip to content

Commit 5f554b7

Browse files
authored
Merge pull request #2 from robotpy/master
Updated master
2 parents 2be2c9a + 6b0f55b commit 5f554b7

File tree

3 files changed

+27
-11
lines changed

3 files changed

+27
-11
lines changed

README.rst

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ can connect to all FRC languages (C++, Java, LabVIEW, Python).
1212

1313
.. note:: NetworkTables is a protocol used for robot communication in the
1414
FIRST Robotics Competition, and can be used to talk to
15-
SmartDashboard/SFX. It does not have any security, and should never
15+
Shuffleboard/SmartDashboard. It does not have any security, and should never
1616
be used on untrusted networks.
1717

1818
Documentation
@@ -39,10 +39,10 @@ Easy install (Windows only)
3939
Manual install
4040
--------------
4141

42-
Make sure to install python 2 or 3 on your computer, and on Windows you can
42+
Make sure to install python 3 on your computer, and on Windows you can
4343
execute::
4444

45-
py -m pip install pynetworktables2js
45+
py -3 -m pip install pynetworktables2js
4646
4747
On Linux/OSX you can execute::
4848

@@ -75,20 +75,20 @@ Usage
7575
You can just distribute your HTML files, and run a pynetworktables server
7676
using the following command from inside the directory::
7777

78-
python -m pynetworktables2js
78+
python3 -m pynetworktables2js
7979

8080
Or on Windows::
8181

82-
py -m pynetworktables2js
82+
py -3 -m pynetworktables2js
8383

8484
This will start a pynetworktables2js server using Tornado (which is installed
8585
by default) and it will serve the current directory. You can navigate your
8686
browser (I recommend Chrome) to http://127.0.0.1:8888 and see your website.
8787

8888
You will want to also pass either the ``--robot`` or ``--team`` switch::
8989

90-
py -m pynetworktables2js --robot roborio-XXXX-frc.local
91-
py -m pynetworktables2js --team XXXX
90+
py -3 -m pynetworktables2js --robot roborio-XXXX-frc.local
91+
py -3 -m pynetworktables2js --team XXXX
9292

9393
Dashboard mode currently doesn't work, as the underlying support in
9494
pynetworktables hasn't been implemented yet for the newer FRC Driver Station.
@@ -102,17 +102,17 @@ uses `tornado <http://www.tornadoweb.org/en/stable/>`_, and one that uses
102102

103103
Go to the 'example' directory distributed with pynetworktables2js, and run::
104104

105-
python tornado_server.py --robot 127.0.0.1
105+
python3 tornado_server.py --robot 127.0.0.1
106106

107107
If you want to try this out with your current robot, you can do::
108108

109-
python tornado_server.py --robot roborio-XXX.local
109+
python3 tornado_server.py --robot roborio-XXX.local
110110
111111
If you are running pynetworktables2js on your driver station laptop, you can
112112
receive robot IP information directly from the Driver Station (handy during
113113
actual competitions)::
114114

115-
python tornado_server.py --dashboard
115+
python3 tornado_server.py --dashboard
116116

117117
If you navigate your browser (I recommend Chrome) to http://127.0.0.1:8888, all
118118
of the current NetworkTables values will be shown as they change.

pynetworktables2js/js/networktables.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,17 @@ var NetworkTables = new function () {
294294
host = "ws:";
295295
}
296296

297-
host += "//" + loc.host;
297+
// If the websocket is being served from a different host allow users
298+
// to add a data-nt-host="" attribute to the script tag loading
299+
// Networktables.
300+
var ntHostElement = document.querySelector('[data-nt-host]');
301+
if (ntHostElement) {
302+
var ntHost = ntHostElement.getAttribute('data-nt-host');
303+
host += "//" + ntHost;
304+
} else {
305+
host += "//" + loc.host;
306+
}
307+
298308
host += "/networktables/ws";
299309

300310
function createSocket() {

pynetworktables2js/tornado_handlers.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ def open(self):
2626
self.ioloop = IOLoop.current()
2727
self.ntserial = NTSerial(self.send_msg_threadsafe)
2828

29+
def check_origin(self, origin):
30+
"""
31+
Allow CORS requests
32+
"""
33+
return True
34+
2935
def on_message(self, message):
3036
if self.ntserial is not None:
3137
self.ntserial.process_update(message)

0 commit comments

Comments
 (0)