GithubHelp home page GithubHelp logo

research-virtualfortknox / msb-client-websocket-python Goto Github PK

View Code? Open in Web Editor NEW
5.0 5.0 4.0 2.22 MB

The python client library to connect to the websocket interface of the MSB (Manufacturing Service Bus)

License: Apache License 2.0

Python 100.00%
python msb websocket-interface msb-client msb-client-websocket

msb-client-websocket-python's People

Contributors

daniel-schel avatar dependabot[bot] avatar fossabot avatar ipamaas avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

msb-client-websocket-python's Issues

Tutorial project template in docs is not working

Describe the bug

https://github.com/research-virtualfortknox/msb-client-websocket-python/tree/master/doc/tutorials/create_service_and_communicate_with_msb/project_template

Tutorial project template in docs is not working.

Should be updated. Maybe use the app_sample.py.

To Reproduce

Try to execute the tutorial in the docs.

Expected behavior
Runnable MSB-Client.

Screenshots

Environment (please complete the following information):

Additional context

Use python dataclasses instead of msb_client.ComplexDataFormat

Is your feature request related to a problem? Please describe.
Allowing the user to use a dataclass as event payload would allow reusability of code and simplification.

Describe the solution you'd like
The library should use reflection to parse the dataclasses provided by the user and generate its internal ComplexDataFormat on its own. This would allow a more streamlined usage as in the java client implementation.

Describe alternatives you've considered

Additional context

Event caching is not work

I'm submitting a ...

  • bug report
  • feature request
  • other

Current behavior:

we can't publish an event directly after the register function:
myMsbClient.register()
myMsbClient.publish(
"E1",
'Test Event',
2)

unless we define a timeout before publishing the event like below:
myMsbClient.register()
time.sleep(10)
myMsbClient.publish(
"E1",
'Test Event',
2)

Expected behavior:

we should be able to publish a defined event immediately after registering our client with MSB.
myMsbClient.register()
myMsbClient.publish(
"E1",
'Test Event',
2
)
Steps to reproduce:

I defined a MSB client and set EventCache atrribute to False value as below:
myMsbClient.disableEventCache(False)
myMsbClient.connect(msb_url)
myMsbClient.register()

and after defining an event and a responding function we want to publish an event, but we notcied that publishing the event directly after the register function is not working at all and we don't get a IO_PUBLISHED response from the MSB. therefore we had to set a time out in order to publish the event after registering the client.
The code below shows an example:

myMsbClient.register()
time.sleep(10) # without this instruction we don't get IO_PUBLISHED response

event_id = "E1"
event_value = 'Rawad Test Event'
event_priority = 2
myMsbClient.publish(
"E1",
'Rawad Test Event',
2
)

MSB client version: x.y.z

MSB server version: x.y.z-RELEASE

Anything else:

Crash using bound methods as function callback

I'm submitting a ...

  • bug report
  • feature request
  • other

Current behavior:
The msb client crashes at getSelfDescription() when a function callback is bound to a object instance instead of a global method. Hence no registration to the MSB is possible.

Expected behavior:
There should be no difference using static methods as callbacks or methods bound to an object (non-static).

Steps to reproduce:

  1. Create a MsbClient with a function handler using a callback of a bound method
SERVICE_TYPE = "SmartObject"
SO_UUID = str(uuid.uuid1())
SO_NAME = "MSBClientPythonAppSample" + SO_UUID[-6:]
SO_DESCRIPTION = "MSBClientPythonAppSample description"  
SO_TOKEN = SO_UUID[-6:]
myMsbClient = MsbClient(
        SERVICE_TYPE,
        SO_UUID,
        SO_NAME,
        SO_DESCRIPTION,
        SO_TOKEN,
    )

class myClass():
    def myMethod(self,msg):
        print(str(msg))
        
myMsbClient = MsbClient(SERVICE_TYPE, SO_UUID,SO_NAME,SO_DESCRIPTION,SO_TOKEN,)

myInstance = myClass()

myFunction = Function("FUNCTION2",
        "Function2",
        "Function2_description",
        DataType.STRING,
        myInstance.myMethod,)

myMsbClient.addFunction(myFunction)

print(myMsbClient.objectToJson(myMsbClient.getSelfDescription()))
# Or call myMsbClient.register() to call getSelfDescription indirectly
  1. Observe the crash at: (Line number might be slightly off since i added debug output)
  File "c:\Users\xx\Downloads\msb-client-websocket-python\test.py", line 56, in <module>
    print(myMsbClient.objectToJson(myMsbClient.getSelfDescription()))
  File "c:\Users\xx\Downloads\msb-client-websocket-python\msb_client\MsbClient.py", line 819, in getSelfDescription
    del f["implementation"]
KeyError: 'implementation'

MSB client version: 1.0.2

Anything else:
The issue is related to the jsonpickle library, especially jsonpickle.encode(). Static method delegates get added to the json-tree with the value "None" whilst object bound methods don't get added to the json tree at all. The key error occurs since the "implementation" (= method delegate) is not found in the json tree when using object bound methods. The following example illustrates the behaviour that only the static method delegate gets pickled:

class myClass():
    def myMethod(self,msg):
        print(str(msg))

    @staticmethod
    def myStaticMethod(parameter_list):
        pass

    def __init__(self):
        self.myMethodDelegate = self.myMethod
        self.myMethodStaticDelegate = myClass.myStaticMethod

myInstance = myClass()
print(jsonpickle.encode(myInstance, unpicklable=False))
# prints { "myMethodStaticDelegate": null }

Possible fix: Check for the existence of the "implementation" key in the cloned object and remove the key only when its present.

Additional remark: Bound methods work out of the box in python with the msb client. This can be seen when calling the implementation directly (usually gets called from the websocket callback):

myMsbClient.functions["FUNCTION2"].implementation("test")

Support Gateway service type

The MSB supports, besides the two service types offered by this project (SmartObject, Application), the service type Gateway. This allows to register a service with sub services managed by it and to handle their communication.

This feature is already supported by the msb-client-websocket-java lib.

Search path for application.properties

I'm submitting a ...

  • bug report
  • feature request
  • other

Current behavior:
The application.properties is loaded from the current working directory:
config = open("application.properties", "r")

This works in most cases, but in edge cases like ROS the working directory is not set properly for the current node.

Expected behavior:
The user should be able to provide a path where the application.properties are stored. Otherwise the file should be searched in the working directory.

MSB client version: 1.0.2

Client crashed for msb 1.5.0 - 1.5.3 due to missing correlation id support

I'm submitting a ...

  • bug report
  • feature request
  • other

Current behavior:
Client crashed for msb 1.5.0 - 1.5.3 due to missing correlation id support

File "C:\Users\xxx\AppData\Local\Continuum\anaconda3\lib\site-packages\msb_client\MsbClient.py", line 157, in on_message
    jmsg["functionParameters"]["correlationId"] = jmsg["correlationId"]

Expected behavior:
If server does not send a correlationId, do not add it to function params.

MSB client version: 1.0.4

MSB server version: x1.5.0-RELEASE

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.