Go Down

Topic: Using BridgeClient in Python Scripts. (Read 28187 times) previous topic - next topic

mediamad

I don't understand (probably because of the noob factor).  There's a serial connection between the two sides.  Why is it not possible to just pass data on it monitoring in python on one side and in the sketch on the other?

mamu


I don't understand (probably because of the noob factor).  There's a serial connection between the two sides.  Why is it not possible to just pass data on it monitoring in python on one side and in the sketch on the other?

I came up with the same thoughts and asked the same question in another thread.
Why all this bridge class heck? Why not simply using the well know Serial in the sketch and having access on the Linino site with JSON and WebSockets like node.js offers?

federicofissore

#17
Nov 08, 2013, 10:17 am Last Edit: Nov 08, 2013, 11:12 am by Federico Fissore Reason: 1
What kind of performance are you expecting? Maybe you'll find this discussion interesting

mediamad

Very interesting indeed.  Kind of surprised this wasn't already taken care of via library upon release.  Seems a no brainer if using the Arduino as a dumb I/O.  Throughput in most cases would be a non issue.

federicofissore

If you're suggesting we should change some library and have working code to share, I'm eager to test it

OPtoss

This post helped me track down the issue. Thanks to wpunkts the true reason for the lag is brought to light:

Quote
Avoiding opening and closing a socket for every put is the key.
Now as of how to resolve it, I found that the bridgeclient.py already has an answer, but it's not obvious or well documented.

Code: [Select]

// Init a bridge client
client = bridgeclient()
// Flag it to not open and close the socket every function call
client.begin()


A quick peek at the source reveals that's what begin does. And indeed it appears to have the same performance as your json client, but for some reason my values weren't saved with that approach, and I'd like to trust the lib where I can.

Hope this helps some one else with this problem!

jfourie

Is there a way o do the same on the Python side? I find it also slower to do gets.  Also I found that if you read the bridge to fast you get wrong values back. Is there a way to read it fast and not break it from the Linux side using Python.

steinvb12

The "put" command you post is working great for me in the python script.

Code: [Select]
json.send({'command':'put', 'key':'testjson', 'value':'jsonvalue'})



However, the "get" command returns a null (None) value. What am I missing?

Code: [Select]
jsonData = json.send({'command':'get', 'key': 'testjson'})

Go Up