Skip to content

Commit

Permalink
Merge pull request #147 from Luos-io/feat/telemetry
Browse files Browse the repository at this point in the history
Add telemetry on pyluos, fix #146
  • Loading branch information
JeromeGalan authored Jul 7, 2022
2 parents 629fb2d + b58ab86 commit 30d474b
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 3 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,11 @@ This section details the features of Luos technology as an embedded development
* Definition of [Packages](https://docs.luos.io/docs/luos-technology/package/package), and how to make a portable and reusable development.
* Definition of [Services](https://docs.luos.io/docs/luos-technology/services/services), how to create and declare features in your product.
* 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.

## Disclaimer
This library send some anonymous information to Luos allowing to improve Pyluos experience.
To disable the telemetry please add `telemetry=False` parameter at Device creation.
For example:
```python
device = Device('/dev/cu.usbserial-DN2EUDGP', telemetry=False)
```
21 changes: 21 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,23 @@ def _setup(self):
self._cmd_data = []
self._binary = []

if (self.telemetry == True):
from pyluos.version import version
self.logger.info('Sending telemetry...')
luos_telemetry = {"telemetry_type": "pyluos",
"mac": hex(uuid.getnode()),
"system": sys.platform,
"unix_time": int(time.time()),
"pyluos_rev": version,
"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
3 changes: 2 additions & 1 deletion pyluos/tools/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ def main():
args = parser.parse_args()

def print_version():
sys.stderr.write("luos control utility v" + pyluos.__version__ + "\n")
from pyluos.version import version
sys.stderr.write("luos control utility v" + version + "\n")
sys.stderr.flush()
return 0

Expand Down
2 changes: 1 addition & 1 deletion pyluos/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version = '2.2.2'
version = '2.2.3'
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
'numpy',
'anytree',
'crc8',
'ipython'
'ipython',
'requests'
],
extras_require={
'tests': ['pytest', 'flake8'],
Expand Down

0 comments on commit 30d474b

Please sign in to comment.