Skip to content

Commit

Permalink
Add telemetry on pyluos, fix #146
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-rabault committed Jul 7, 2022
1 parent 629fb2d commit 9362647
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions pyluos/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import sys
import json
import time
import uuid
import logging
import requests
import threading
import logging.config
import numpy as np
Expand Down Expand Up @@ -89,6 +91,7 @@ def __init__(self, host,
log_conf=_base_log_conf,
test_mode=False,
background_task=True,
telemetry=True,
*args, **kwargs):
if IO is not None:
self._io = IO(host=host, *args, **kwargs)
Expand All @@ -101,6 +104,7 @@ def __init__(self, host,
config = json.load(f)
logging.config.dictConfig(config)

self.telemetry = telemetry
self.logger = logging.getLogger(__name__)
self.logger.info('Connected to "{}".'.format(host))

Expand Down Expand Up @@ -228,6 +232,21 @@ def _setup(self):
self._cmd_data = []
self._binary = []

if (self.telemetry == True):
self.logger.info('Sending telemetry...')
luos_telemetry = {"telemetry_type": "pyluos",
"mac": hex(uuid.getnode()),
"system": sys.platform,
"unix_time": int(time.time()),
"routing_table":state['routing_table']}
try:
requests.post("https://monorepo-services.vercel.app/api/telemetry",
data=luos_telemetry)
except:
print("Telemetry request failed.")
else:
self.logger.info("Telemetry disabled, please consider enabling it by removing the 'telemetry=False' argument of your Device creation.")

# We push our current state to make sure that
# both our model and the hardware are synced.
self._push_once()
Expand Down

0 comments on commit 9362647

Please sign in to comment.