GithubHelp home page GithubHelp logo

tomorrowdata / iottly-sdk-python Goto Github PK

View Code? Open in Web Editor NEW
3.0 3.0 1.0 724 KB

Python module handling interaction with the iottly agent

License: Apache License 2.0

Python 97.27% Shell 0.70% Roff 2.04%

iottly-sdk-python's People

Contributors

baldoalessandro avatar oscar-campo avatar stefanoterna avatar xrmx avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

oscar-campo

iottly-sdk-python's Issues

call_agent function doesn't work inside on_agent_status_changed call-back

Il problema รจ che si sta cercando di chiamare la call_agent da dentro la callback on_agent_status_changed.
La call_agent verifica che l'agent abbia una versione compatibile (>=1.8).
Quando viene triggerata la callback on_agent_status_changed("started"), l'agent non ha ancora fatto in tempo a mandare la sua versione, quindi la call_agent non viene chiamata.

A stacktrace is printed when no user CB is provided in the constructor

How to reproduce

>>> import iottly_sdk
>>> sdk = iottly_sdk.IottlySDK("Wilson")
>>> sdk.start()
>>> Exception in thread receiver_t:
Traceback (most recent call last):
  File "/usr/lib/python3.5/threading.py", line 914, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.5/threading.py", line 862, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/local/lib/python3.5/dist-packages/iottly_sdk-1.3.0-py3.5.egg/iottly_sdk/iottly.py", line 486, in _receive_msgs_from_agent
    self._process_msg_from_agent(msg)
  File "/usr/local/lib/python3.5/dist-packages/iottly_sdk-1.3.0-py3.5.egg/iottly_sdk/iottly.py", line 506, in _process_msg_from_agent
    self._handle_signals_from_agent(msg['signal'])
  File "/usr/local/lib/python3.5/dist-packages/iottly_sdk-1.3.0-py3.5.egg/iottly_sdk/iottly.py", line 519, in _handle_signals_from_agent
    self._on_connection_status_changed_cb(status)
TypeError: 'NoneType' object is not callable

Cause

def _handle_signals_from_agent(self, signal):
if 'agentstatus' in signal:
status = signal['agentstatus'] # TODO validate status
self._on_agent_status_changed_cb(status)
elif 'connectionstatus' in signal:
status = signal['connectionstatus'] # TODO validate status
self._on_connection_status_changed_cb(status)

The invocations should be guarded like in
if self._on_agent_status_changed_cb:
self._on_agent_status_changed_cb('started')

Thanks to @Oscar-Campo and @lupodellasleppa ๐ŸŽ–๏ธ

[DOC] Improve connection status and agent status callbacks use cases

When the SDK initializes, it gives no feedback as to if the start() has completed or not.

This could lead to third party applications considering the SDK as started, while in reality it's still starting.

It could happen, for example, that the SDK has not yet received the agent version from the agent, while trying to call the call_agent() method, resulting in a InvalidAgentVersion error.

Send() doesn't work for big data

def _send_msg_through_socket(self, payload):
"""Send messages through the socket after acquiring a shared lock.
This avoid possible interleaving between threads. Messages are
sezialized as they should.
All raised errors are propagated to the callers which should act upon
accordingly to their specific semantic.
"""
with self._socket_write_lock:
self._socket.sendall(payload)

The sdk.send() doesn't work when the payload is greater than 65535 bytes (TCP packet max size).

Nothing is sent to the Agent and no exception is raised. sdk.send() stops working.

Probably we need to use socket.send() instead of socket.sendall() and manage the size of payload.

[Docs]Callback exception sends error msg to agent, not documented

A message is sent automatically to the agent when an exception is raised from the callback.

Perhaps this must be written inside SDK documentation.

def _wrapped_cb_execution(self, f):
"""Wrap callback execution and send error to agent.
"""
if f is None:
return None
@wraps(f)
def wrapper(*args, **kwargs):
try:
f(*args, **kwargs)
except Exception as exc:
exc_dump = json.dumps({
'type': exc.__class__.__name__,
'msg': str(exc)
})
# Format signal message
exc_msg = Msg(
payload=self._err_msg.format(exc_dump).encode(),
type=True,
channel=None
)
self._buffer.put(exc_msg) # En-quque msg blocking
return wrapper

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.