|
18 | 18 | import base64 |
19 | 19 | import argparse |
20 | 20 | import logging |
| 21 | +import sys |
21 | 22 |
|
22 | | -try: |
| 23 | +try: |
23 | 24 | from PIL import Image |
24 | 25 | from PIL import ImageFont |
25 | 26 | from PIL import ImageDraw |
@@ -126,10 +127,19 @@ def _mqtt_handler_picturetoscreen(self, deviceType, deviceId, payload): |
126 | 127 | {{TESTBED}}/deviceType/box/deviceId/box1/cmd/picturetoscreen |
127 | 128 | ''' |
128 | 129 | assert deviceType==DEVICETYPE_BOX |
129 | | - image = Image.open(requests.get(json.loads(payload)['url'], stream=True).raw) |
130 | | - image.thumbnail((480,320),Image.ANTIALIAS) |
131 | | - self._otbox.change_image_queue.put(image) |
132 | | - self._otbox.change_image_queue.join() |
| 130 | + try: |
| 131 | + image_url = json.loads(payload)['url'] |
| 132 | + response = requests.get(image_url, stream=True) |
| 133 | + image = Image.open(response.raw) |
| 134 | + except IOError: |
| 135 | + # the image is not available now; skip this one |
| 136 | + print('image at {0} is not available, '.format(image_url) |
| 137 | + + 'HTTP response code {0}'.format(response.status_code)) |
| 138 | + sys.stdout.flush() |
| 139 | + else: |
| 140 | + image.thumbnail((480,320),Image.ANTIALIAS) |
| 141 | + self._otbox.change_image_queue.put(image) |
| 142 | + self._otbox.change_image_queue.join() |
133 | 143 | return {} |
134 | 144 |
|
135 | 145 | def _mqtt_handler_colortoscreen(self, deviceType, deviceId, payload): |
@@ -283,7 +293,7 @@ def _on_mqtt_connect(self, client, userdata, flags, rc): |
283 | 293 | self.mqttconnected = True |
284 | 294 |
|
285 | 295 | # subscribe to box commands (device-specific and 'all') |
286 | | - # note that unknown commands will be ignored by _execute_command_safely |
| 296 | + # note that unknown commands will be ignored by _execute_command_safely |
287 | 297 | client.subscribe('{0}/#'.format(self.mqtttopic_box_cmd_prefix)) |
288 | 298 | client.subscribe('{0}/deviceType/box/deviceId/all/cmd/#'.format(self.testbed)) |
289 | 299 |
|
@@ -541,13 +551,13 @@ def _mqtt_handler_program(self, deviceType, deviceId, payload): |
541 | 551 |
|
542 | 552 | payload = json.loads(payload) # shorthand |
543 | 553 | mote = self._eui64_to_moteinfoelem(deviceId) |
544 | | - |
| 554 | + |
545 | 555 | # reset the mote first |
546 | 556 | self._mqtt_handler_reset(deviceType, deviceId, payload=None) |
547 | 557 |
|
548 | 558 | # disconnect from the serialports |
549 | 559 | self.SerialportHandlers[mote['serialport']].disconnectSerialPort() |
550 | | - |
| 560 | + |
551 | 561 | if isinstance(self.tb, OpenTestbed): |
552 | 562 | # For OpenTestbed, we will use a separate firmware_temp |
553 | 563 | # for each deviceId. Although other testbeds may need to |
@@ -667,18 +677,18 @@ def _bootload_motes(self, serialports, firmware_file): |
667 | 677 | # start bootloading each mote |
668 | 678 | ongoing_bootloads = {} |
669 | 679 | for serialport in serialports: |
670 | | - |
| 680 | + |
671 | 681 | # simply the name |
672 | 682 | port = serialport.split('/')[-1] |
673 | | - |
| 683 | + |
674 | 684 | # stop serial reader |
675 | 685 | ongoing_bootloads[port] = self.tb.bootload_mote(serialport, firmware_file) |
676 | 686 |
|
677 | 687 | returnVal = [] |
678 | 688 | for ongoing_bootload in ongoing_bootloads: |
679 | 689 | # wait for this bootload process to finish |
680 | 690 | (stdout, stderr) = ongoing_bootloads[ongoing_bootload].communicate() |
681 | | - |
| 691 | + |
682 | 692 | # record the last output of bootload process |
683 | 693 | with open("log_{0}.txt".format(ongoing_bootload),'w') as f: |
684 | 694 | f.write("stdout: {0} stderr {1}".format(stdout,stderr)) |
|
0 commit comments