Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.