Skip to content

Instantly share code, notes, and snippets.

@tmkasun
Last active April 19, 2017 13:55
Show Gist options
  • Save tmkasun/f041a531cb6f99ffd46dd8b15d46c3de to your computer and use it in GitHub Desktop.
Save tmkasun/f041a531cb6f99ffd46dd8b15d46c3de to your computer and use it in GitHub Desktop.
Capture frames from Lepton camera using PyLepton and serialize the data and transmit it over web socket protocol
class ThermalDataHandler(WebSocketHandler):
clients = []
DEBUG = False
def __init__(self, application, request, **kwargs):
super(ThermalDataHandler, self).__init__(application, request, **kwargs)
if not ThermalDataHandler.DEBUG:
self.lepton = Lepton("/dev/spidev0.0")
self.lepton.__enter__()
self.mock_samples = MockData()
def check_origin(self, origin):
return True
def open(self):
if self not in ThermalDataHandler.clients:
self.write_message("ACK")
ThermalDataHandler.clients.append(self)
def on_close(self):
if self in ThermalDataHandler.clients:
ThermalDataHandler.clients.remove(self)
def on_message(self, message):
self.write_message(self._get_data())
def _get_data(self):
if ThermalDataHandler.DEBUG:
raw_frame = self.mock_samples.get_next_sample()
else:
raw_frame, _ = self.lepton.capture()
raw_frame.astype(np.uint16)
return json.dumps(raw_frame.tolist())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment