31
31
# SLEEP_TIME = 60 * 60 * 24 # seconds
32
32
33
33
# URL to fetch the data from
34
- JSON_GET_URL = "https://api.jwst-hub.com/track"
34
+ JSON_GET_URL = (
35
+ "https://jwst.nasa.gov/content/webbLaunch/flightCurrentState2.0.json?unique={}"
36
+ )
35
37
36
38
# Whether to fetch live data or use cached
37
- TEST_RUN = False
39
+ TEST_RUN = True
38
40
# Cached data, helpful when developing interface
39
41
# 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" }'
42
+ 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": ""} }'
41
43
42
44
# Background Color for the label texts
43
45
LBL_BACKGROUND = 0x444444
@@ -75,7 +77,11 @@ def try_refresh():
75
77
supervisor .reload ()
76
78
77
79
78
- def make_label_text (text , anchor_point , anchored_position ):
80
+ def get_time_str ():
81
+ return str (time .monotonic ()).replace ("." , "" )
82
+
83
+
84
+ def make_name_text (text , anchor_point , anchored_position , bg_color = LBL_BACKGROUND ):
79
85
"""
80
86
Create label object for labeling data values.
81
87
It will get a background color box and appropriate padding.
@@ -90,15 +96,22 @@ def make_label_text(text, anchor_point, anchored_position):
90
96
text = text ,
91
97
anchor_point = anchor_point ,
92
98
anchored_position = anchored_position ,
93
- background_color = LBL_BACKGROUND ,
99
+ background_color = bg_color ,
94
100
padding_left = 4 ,
95
101
padding_right = 4 ,
96
102
padding_bottom = 3 ,
97
103
padding_top = 3 ,
104
+ line_spacing = 1.0 ,
98
105
)
99
106
100
107
101
- def make_value_text (anchor_point , anchored_position , custom_font = True ):
108
+ def make_value_text (
109
+ anchor_point ,
110
+ anchored_position ,
111
+ custom_font = True ,
112
+ bg_color = 0x000000 ,
113
+ font_color = 0xFFFFF ,
114
+ ):
102
115
"""
103
116
Create label object for showing data values.
104
117
@@ -112,7 +125,17 @@ def make_value_text(anchor_point, anchored_position, custom_font=True):
112
125
else :
113
126
_font = terminalio .FONT
114
127
return bitmap_label .Label (
115
- _font , text = "" , anchor_point = anchor_point , anchored_position = anchored_position
128
+ _font ,
129
+ text = "" ,
130
+ anchor_point = anchor_point ,
131
+ anchored_position = anchored_position ,
132
+ line_spacing = 1.0 ,
133
+ padding_top = 3 ,
134
+ background_color = bg_color ,
135
+ color = font_color ,
136
+ padding_right = 4 ,
137
+ padding_left = 4 ,
138
+ padding_bottom = 4 ,
116
139
)
117
140
118
141
@@ -122,118 +145,98 @@ def make_value_text(anchor_point, anchored_position, custom_font=True):
122
145
# initialize custom font
123
146
font = bitmap_font .load_font ("fonts/LeagueSpartan-Light.bdf" )
124
147
125
- # value text initialization
126
-
127
- # top left
128
- elapsed_time_val = make_value_text (anchor_point = (0 , 0 ), anchored_position = (6 , 6 ))
148
+ # value text initializations
129
149
130
- # top right
131
- distance_from_earth_val = make_value_text (
132
- anchor_point = (1.0 , 0 ), anchored_position = (display .width - 6 , 6 )
150
+ # top left. Hot side | Cold side temperature values
151
+ top_left_value = make_value_text (
152
+ anchor_point = (0 , 0 ),
153
+ anchored_position = (0 , 6 ),
154
+ bg_color = 0xBBBBBB ,
155
+ font_color = 0x000000 ,
133
156
)
134
157
135
- # middle right
136
- distance_to_l2_val = make_value_text (
137
- anchor_point = (1.0 , 0 ), anchored_position = (display .width - 6 , 56 )
158
+ # top right. Instrument temperature values
159
+ top_right_value = make_value_text (
160
+ anchor_point = (1.0 , 0 ),
161
+ anchored_position = (display .width - 6 , 6 ),
138
162
)
139
163
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
164
+ # bottom left timestamp
149
165
timestamp_val = make_value_text (
150
- anchor_point = (0 , 1.0 ), anchored_position = (6 , display .height - 6 ), custom_font = False
166
+ anchor_point = (0 , 1.0 ), anchored_position = (0 , display .height - 6 ), custom_font = False
151
167
)
152
168
153
- # center
154
- temperature_val = make_value_text (
155
- anchor_point = (0.5 , 0.0 ), anchored_position = (display .width // 2 , 6 )
156
- )
169
+ main_group .append (top_left_value )
170
+ main_group .append (top_right_value )
157
171
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 )
163
172
main_group .append (timestamp_val )
164
173
165
174
# label text initialization
166
175
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 )
176
+ # middle left. Hot side | Cold side temps label
177
+ middle_left_name = make_name_text (
178
+ text = "Temperature" , anchor_point = (0.0 , 0 ), anchored_position = (0 , 51 )
175
179
)
176
180
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 )
181
+ # center. Instrument temp labels
182
+ inst_temp_labels = "NIRCam Bench\n NIRSpec Bench\n FGS Bench\n MIRI Bench\n FSM"
183
+ top_center_name = make_name_text (
184
+ text = inst_temp_labels ,
185
+ anchor_point = (1.0 , 0.0 ),
186
+ anchored_position = (top_right_value .x - 2 , 6 ),
180
187
)
181
188
182
- # center
183
- temperature_lbl = make_label_text (
184
- text = "Temp" , anchor_point = (0.5 , 0.0 ), anchored_position = (display .width // 2 , 54 )
185
- )
186
-
187
- # middle left
188
- speed_lbl = make_label_text (
189
- text = "Speed" , anchor_point = (0 , 0 ), anchored_position = (6 , 76 )
190
- )
191
-
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 )
189
+ main_group .append (middle_left_name )
190
+ main_group .append (top_center_name )
198
191
199
192
if not TEST_RUN :
200
193
try :
201
- print ("Fetching JSON data from %s" % JSON_GET_URL )
202
- response = requests .get (JSON_GET_URL , timeout = 30 )
194
+ print ("Fetching JSON data from {}" . format ( JSON_GET_URL . format ( get_time_str ())) )
195
+ response = requests .get (JSON_GET_URL . format ( get_time_str ()) , timeout = 30 )
203
196
except (RuntimeError , OSError ) as e :
204
197
print (e )
205
198
print ("Failed GET request. Rebooting in 3 seconds..." )
206
199
time .sleep (3 )
207
200
supervisor .reload ()
208
201
209
202
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 )
203
+ print (response .headers )
204
+ json_data = response .json ()
205
+ _time_parts = response .headers ["date" ].split (" " )
206
+ _time_str = "{}\n {}" .format (" " .join (_time_parts [:4 ]), " " .join (_time_parts [4 :]))
216
207
217
208
print ("JSON Response: " , json_data )
218
209
print ("-" * 40 )
219
210
response .close ()
220
211
else :
221
212
json_data = json .loads (FAKE_DATA )
213
+ _time_parts = ["Mon," , "28" , "Feb" , "2022" , "17:17:54 GMT" ]
214
+ _time_str = "{}\n {}" .format (" " .join (_time_parts [:4 ]), " " .join (_time_parts [4 :]))
215
+
216
+ # Date/Time
217
+ timestamp_val .text = _time_str
218
+
219
+ # instrument temps
220
+ top_right_value .text = "{}K\n {}K\n {}K\n {}K\n {}K" .format (
221
+ json_data ["currentState" ]["tempInstNirCamK" ],
222
+ json_data ["currentState" ]["tempInstNirSpecK" ],
223
+ json_data ["currentState" ]["tempInstFgsNirissK" ],
224
+ json_data ["currentState" ]["tempInstMiriK" ],
225
+ json_data ["currentState" ]["tempInstFsmK" ],
226
+ )
222
227
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" ],
228
+ # hot side | cold site temps
229
+ top_left_value .text = "{}C | {}C\n {}C | {}C" .format (
230
+ json_data ["currentState" ]["tempWarmSide1C" ],
231
+ json_data ["currentState" ]["tempCoolSide1C" ],
232
+ json_data ["currentState" ]["tempWarmSide2C" ],
233
+ json_data ["currentState" ]["tempCoolSide2C" ],
235
234
)
236
235
236
+ # Set the name position after the instrument temps are in the value
237
+ # label, so that it's x will be in the proper position.
238
+ top_center_name .anchored_position = (top_right_value .x - 2 , 6 )
239
+
237
240
# show the group
238
241
display .show (main_group )
239
242
0 commit comments