3131# SLEEP_TIME = 60 * 60 * 24 # seconds
3232
3333# URL to fetch the data from
34- JSON_GET_URL = "https://api. jwst-hub.com/track "
34+ JSON_GET_URL = "https://jwst.nasa.gov/content/webbLaunch/flightCurrentState2.0.json?unique={} "
3535
3636# Whether to fetch live data or use cached
37- TEST_RUN = False
37+ TEST_RUN = True
3838# Cached data, helpful when developing interface
3939# pylint: disable=line-too-long
40- FAKE_DATA = '{"distanceEarthKm":"1103975.4","launchElapsedTime":"15:03:47:44","distanceL2Km":342356.2,"percentageCompleted":76.3291,"speedKmS":0.3778,"deploymentImgURL":"https://webb.nasa.gov/content/webbLaunch/assets/images/deployment/1000pxWide/123Crop.png","currentDeploymentStep":"WEBB IS FULLY DEPLOYED! - The largest, most complex telescope ever launched into space is fully deployed.","tempC":{"tempWarmSide1C":55,"tempWarmSide2C":11,"tempCoolSide1C":-178,"tempCoolSide2C":-200},"timestamp":"2022-01-09T16:07:44.147Z" }'
40+ FAKE_DATA = '{"currentState": {"STEPS": "MirrorAlignSteps, TempBlurb, MirrorBlurb, ArraysForPlots, Plots", "launchDateTimeString": "2021-12-25T12:20Z", "currentDeployTableIndex": 34, "tempWarmSide1C": 37.1, "tempWarmSide2C": 12.0, "tempCoolSide1C": -229.1, "tempCoolSide2C": -233.0, "---INST TEMPS IN KELVIN----": "", "tempInstNirCamK": 42.7, "tempInstNirSpecK": 39.9, "tempInstFgsNirissK": 47.3, "tempInstMiriK": 108.7, "tempInstFsmK": 37.1, "tempsShow": true, "last": ""} }'
4141
4242# Background Color for the label texts
4343LBL_BACKGROUND = 0x444444
@@ -75,7 +75,11 @@ def try_refresh():
7575 supervisor .reload ()
7676
7777
78- def make_label_text (text , anchor_point , anchored_position ):
78+ def get_time_str ():
79+ return str (time .monotonic ()).replace ("." , "" )
80+
81+
82+ def make_name_text (text , anchor_point , anchored_position , bg_color = LBL_BACKGROUND ):
7983 """
8084 Create label object for labeling data values.
8185 It will get a background color box and appropriate padding.
@@ -90,15 +94,16 @@ def make_label_text(text, anchor_point, anchored_position):
9094 text = text ,
9195 anchor_point = anchor_point ,
9296 anchored_position = anchored_position ,
93- background_color = LBL_BACKGROUND ,
97+ background_color = bg_color ,
9498 padding_left = 4 ,
9599 padding_right = 4 ,
96100 padding_bottom = 3 ,
97101 padding_top = 3 ,
102+ line_spacing = 1.0
98103 )
99104
100105
101- def make_value_text (anchor_point , anchored_position , custom_font = True ):
106+ def make_value_text (anchor_point , anchored_position , custom_font = True , bg_color = 0x000000 , font_color = 0xFFFFF ):
102107 """
103108 Create label object for showing data values.
104109
@@ -112,7 +117,9 @@ def make_value_text(anchor_point, anchored_position, custom_font=True):
112117 else :
113118 _font = terminalio .FONT
114119 return bitmap_label .Label (
115- _font , text = "" , anchor_point = anchor_point , anchored_position = anchored_position
120+ _font , text = "" , anchor_point = anchor_point , anchored_position = anchored_position ,
121+ line_spacing = 1.0 , padding_top = 3 , background_color = bg_color , color = font_color ,
122+ padding_right = 4 , padding_left = 4 , padding_bottom = 4
116123 )
117124
118125
@@ -122,118 +129,90 @@ def make_value_text(anchor_point, anchored_position, custom_font=True):
122129# initialize custom font
123130font = bitmap_font .load_font ("fonts/LeagueSpartan-Light.bdf" )
124131
125- # value text initialization
132+ # value text initializations
126133
127- # top left
128- elapsed_time_val = make_value_text (anchor_point = (0 , 0 ), anchored_position = (6 , 6 ))
134+ # top left. Hot side | Cold side temperature values
135+ top_left_value = make_value_text (anchor_point = (0 , 0 ), anchored_position = (0 , 6 ), bg_color = 0xBBBBBB , font_color = 0x000000 )
129136
130- # top right
131- distance_from_earth_val = make_value_text (
132- anchor_point = (1.0 , 0 ), anchored_position = (display .width - 6 , 6 )
137+ # top right. Instrument temperature values
138+ top_right_value = make_value_text (
139+ anchor_point = (1.0 , 0 ), anchored_position = (display .width - 6 , 6 ),
133140)
134141
135- # middle right
136- distance_to_l2_val = make_value_text (
137- anchor_point = (1.0 , 0 ), anchored_position = (display .width - 6 , 56 )
138- )
139-
140- # bottom right
141- percent_complete_val = make_value_text (
142- anchor_point = (1.0 , 1.0 ), anchored_position = (display .width - 6 , display .height - 6 )
143- )
144-
145- # middle left
146- speed_val = make_value_text (anchor_point = (0 , 0 ), anchored_position = (6 , 56 ))
147-
148- # bottom left
142+ # bottom left timestamp
149143timestamp_val = make_value_text (
150- anchor_point = (0 , 1.0 ), anchored_position = (6 , display .height - 6 ), custom_font = False
144+ anchor_point = (0 , 1.0 ), anchored_position = (0 , display .height - 6 ), custom_font = False
151145)
152146
153- # center
154- temperature_val = make_value_text (
155- anchor_point = (0.5 , 0.0 ), anchored_position = (display .width // 2 , 6 )
156- )
147+ main_group .append (top_left_value )
148+ main_group .append (top_right_value )
157149
158- main_group .append (elapsed_time_val )
159- main_group .append (distance_from_earth_val )
160- main_group .append (distance_to_l2_val )
161- main_group .append (percent_complete_val )
162- main_group .append (speed_val )
163150main_group .append (timestamp_val )
164151
165152# label text initialization
166153
167- # top left
168- elapsed_time_lbl = make_label_text (
169- text = "Elapsed" , anchor_point = (0.0 , 0 ), anchored_position = (6 , 26 )
170- )
171-
172- # top right
173- distance_from_earth_lbl = make_label_text (
174- text = "From Earth" , anchor_point = (1.0 , 0 ), anchored_position = (display .width - 6 , 26 )
175- )
176-
177- # middle right
178- distance_to_l2_lbl = make_label_text (
179- text = "To L2 Orbit" , anchor_point = (1.0 , 0 ), anchored_position = (display .width - 6 , 76 )
180- )
181-
182- # center
183- temperature_lbl = make_label_text (
184- text = "Temp" , anchor_point = (0.5 , 0.0 ), anchored_position = (display .width // 2 , 54 )
154+ # middle left. Hot side | Cold side temps label
155+ middle_left_name = make_name_text (
156+ text = "Temperature" , anchor_point = (0.0 , 0 ), anchored_position = (0 , 51 )
185157)
186158
187- # middle left
188- speed_lbl = make_label_text (
189- text = "Speed" , anchor_point = (0 , 0 ), anchored_position = (6 , 76 )
159+ # center. Instrument temp labels
160+ inst_temp_labels = "NIRCam Bench\n NIRSpec Bench\n FGS Bench\n MIRI Bench\n FSM"
161+ top_center_name = make_name_text (
162+ text = inst_temp_labels , anchor_point = (1.0 , 0.0 ), anchored_position = (top_right_value .x - 2 , 6 )
190163)
191164
192- main_group .append (elapsed_time_lbl )
193- main_group .append (distance_from_earth_lbl )
194- main_group .append (distance_to_l2_lbl )
195- main_group .append (temperature_lbl )
196- main_group .append (speed_lbl )
197- main_group .append (temperature_val )
165+ main_group .append (middle_left_name )
166+ main_group .append (top_center_name )
198167
199168if not TEST_RUN :
200169 try :
201- print ("Fetching JSON data from %s" % JSON_GET_URL )
202- response = requests .get (JSON_GET_URL , timeout = 30 )
170+ print ("Fetching JSON data from {}" . format ( JSON_GET_URL . format ( get_time_str ())) )
171+ response = requests .get (JSON_GET_URL . format ( get_time_str ()) , timeout = 30 )
203172 except (RuntimeError , OSError ) as e :
204173 print (e )
205174 print ("Failed GET request. Rebooting in 3 seconds..." )
206175 time .sleep (3 )
207176 supervisor .reload ()
208177
209178 print ("-" * 40 )
210- text_data = response .text
211- text_data = text_data .replace ('"distanceEarthKm":' , '"distanceEarthKm":"' ).replace (
212- ',"launchElapsedTime"' , '","launchElapsedTime"'
213- )
214-
215- json_data = json .loads (text_data )
179+ print (response .headers )
180+ json_data = response .json ()
181+ _time_parts = response .headers ["date" ].split (" " )
182+ _time_str = "{}\n {}" .format (" " .join (_time_parts [:4 ]), " " .join (_time_parts [4 :]))
216183
217184 print ("JSON Response: " , json_data )
218185 print ("-" * 40 )
219186 response .close ()
220187else :
221188 json_data = json .loads (FAKE_DATA )
189+ _time_parts = ["Mon," , "28" , "Feb" , "2022" , "17:17:54 GMT" ]
190+ _time_str = "{}\n {}" .format (" " .join (_time_parts [:4 ]), " " .join (_time_parts [4 :]))
191+
192+ # Date/Time
193+ timestamp_val .text = _time_str
194+
195+ # instrument temps
196+ top_right_value .text = "{}K\n {}K\n {}K\n {}K\n {}K" .format (
197+ json_data ["currentState" ]["tempInstNirCamK" ],
198+ json_data ["currentState" ]["tempInstNirSpecK" ],
199+ json_data ["currentState" ]["tempInstFgsNirissK" ],
200+ json_data ["currentState" ]["tempInstMiriK" ],
201+ json_data ["currentState" ]["tempInstFsmK" ],
202+ )
222203
223- # update the labels to display values
224- elapsed_time_val .text = json_data ["launchElapsedTime" ]
225- distance_from_earth_val .text = "{}km" .format (json_data ["distanceEarthKm" ])
226- distance_to_l2_val .text = "{}km" .format (str (json_data ["distanceL2Km" ]))
227- percent_complete_val .text = "{}%" .format (str (json_data ["percentageCompleted" ]))
228- speed_val .text = "{}km/s" .format (str (json_data ["speedKmS" ]))
229- timestamp_val .text = str (json_data ["timestamp" ])
230- temperature_val .text = "{}c | {}c\n {}c | {}c" .format (
231- json_data ["tempC" ]["tempWarmSide1C" ],
232- json_data ["tempC" ]["tempCoolSide1C" ],
233- json_data ["tempC" ]["tempWarmSide2C" ],
234- json_data ["tempC" ]["tempCoolSide2C" ],
204+ # hot side | cold site temps
205+ top_left_value .text = "{}C | {}C\n {}C | {}C" .format (
206+ json_data ["currentState" ]["tempWarmSide1C" ],
207+ json_data ["currentState" ]["tempCoolSide1C" ],
208+ json_data ["currentState" ]["tempWarmSide2C" ],
209+ json_data ["currentState" ]["tempCoolSide2C" ],
235210)
236211
212+ # Set the name position after the instrument temps are in the value
213+ # label, so that it's x will be in the proper position.
214+ top_center_name .anchored_position = (top_right_value .x - 2 , 6 )
215+
237216# show the group
238217display .show (main_group )
239218
0 commit comments