Skip to content

Commit 30d474b

Browse files
author
JeromeGalan
authored
Merge pull request #147 from Luos-io/feat/telemetry
Add telemetry on pyluos, fix #146
2 parents 629fb2d + b58ab86 commit 30d474b

File tree

5 files changed

+34
-3
lines changed

5 files changed

+34
-3
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,11 @@ This section details the features of Luos technology as an embedded development
3030
* Definition of [Packages](https://docs.luos.io/docs/luos-technology/package/package), and how to make a portable and reusable development.
3131
* Definition of [Services](https://docs.luos.io/docs/luos-technology/services/services), how to create and declare features in your product.
3232
* Definition of [Messages](https://docs.luos.io/docs/luos-technology/message/message), when, why, and how to handle them, explaining the more advanced features of Luos.
33+
34+
## Disclaimer
35+
This library send some anonymous information to Luos allowing to improve Pyluos experience.
36+
To disable the telemetry please add `telemetry=False` parameter at Device creation.
37+
For example:
38+
```python
39+
device = Device('/dev/cu.usbserial-DN2EUDGP', telemetry=False)
40+
```

pyluos/device.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
import sys
44
import json
55
import time
6+
import uuid
67
import logging
8+
import requests
79
import threading
810
import logging.config
911
import numpy as np
@@ -89,6 +91,7 @@ def __init__(self, host,
8991
log_conf=_base_log_conf,
9092
test_mode=False,
9193
background_task=True,
94+
telemetry=True,
9295
*args, **kwargs):
9396
if IO is not None:
9497
self._io = IO(host=host, *args, **kwargs)
@@ -101,6 +104,7 @@ def __init__(self, host,
101104
config = json.load(f)
102105
logging.config.dictConfig(config)
103106

107+
self.telemetry = telemetry
104108
self.logger = logging.getLogger(__name__)
105109
self.logger.info('Connected to "{}".'.format(host))
106110

@@ -228,6 +232,23 @@ def _setup(self):
228232
self._cmd_data = []
229233
self._binary = []
230234

235+
if (self.telemetry == True):
236+
from pyluos.version import version
237+
self.logger.info('Sending telemetry...')
238+
luos_telemetry = {"telemetry_type": "pyluos",
239+
"mac": hex(uuid.getnode()),
240+
"system": sys.platform,
241+
"unix_time": int(time.time()),
242+
"pyluos_rev": version,
243+
"routing_table":state['routing_table']}
244+
try:
245+
requests.post("https://monorepo-services.vercel.app/api/telemetry",
246+
data=luos_telemetry)
247+
except:
248+
print("Telemetry request failed.")
249+
else:
250+
self.logger.info("Telemetry disabled, please consider enabling it by removing the 'telemetry=False' argument of your Device creation.")
251+
231252
# We push our current state to make sure that
232253
# both our model and the hardware are synced.
233254
self._push_once()

pyluos/tools/shell.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ def main():
4040
args = parser.parse_args()
4141

4242
def print_version():
43-
sys.stderr.write("luos control utility v" + pyluos.__version__ + "\n")
43+
from pyluos.version import version
44+
sys.stderr.write("luos control utility v" + version + "\n")
4445
sys.stderr.flush()
4546
return 0
4647

pyluos/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
version = '2.2.2'
1+
version = '2.2.3'

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
'numpy',
2626
'anytree',
2727
'crc8',
28-
'ipython'
28+
'ipython',
29+
'requests'
2930
],
3031
extras_require={
3132
'tests': ['pytest', 'flake8'],

0 commit comments

Comments
 (0)