Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions iottly_sdk/iottly.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from Queue import Queue, Full

import json
import logging

# Import the SDK version number
from .version import __version__
Expand All @@ -38,6 +39,16 @@
Msg = namedtuple('Msg', ['payload', 'type', 'channel'])


logger = logging.getLogger('iottly-sdk')
logger.setLevel(logging.ERROR)
sh = logging.StreamHandler()
sh.setLevel(logging.ERROR)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
sh.setFormatter(formatter)
logger.addHandler(sh)



class IottlySDK:
"""Class handling interactions with the iottly-agent

Expand Down Expand Up @@ -349,6 +360,13 @@ def _connect_to_agent(self):
s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
try:
s.connect(self._socket_path)

except PermissionError as e:
s.close()
s = None
logger.error("Permission denied, launch with proper permission")
return

except OSError as e:
if e.errno == errno.ECONNREFUSED:
s.close()
Expand Down Expand Up @@ -513,10 +531,12 @@ def _process_msg_from_agent(self, msg):
def _handle_signals_from_agent(self, signal):
if 'agentstatus' in signal:
status = signal['agentstatus'] # TODO validate status
self._on_agent_status_changed_cb(status)
if self._on_agent_status_changed_cb:
self._on_agent_status_changed_cb(status)
elif 'connectionstatus' in signal:
status = signal['connectionstatus'] # TODO validate status
self._on_connection_status_changed_cb(status)
if self._on_connection_status_changed_cb:
self._on_connection_status_changed_cb(status)
elif 'sdkinit' in signal:
version = signal['sdkinit']['version']
with self._agent_version_state_lock:
Expand Down