In the bridgeclient.py on OpenWrt there is only method mailbox(...) which are just sending message but there is no methods for recieving and check available messages.
How can I add some additional methods to the bridgeclient.py to make it similar to Mailbox class on Arduino side?
So, I need two additional classes for mailbox_read and mailbox_available...
Thank you for replay. I saw your materials. I have long time experience with programming (avr and UNIX gcc).
In my project 32u4 controls water supply, send some alert messages to linino when something wrong happens and reading messages from linino some manual operating command.
On linino I have Python based daemon which reading messages from AVR and perform some special operations (storing day in SQLite, sending sms and etc.
So, when water leaking detected on 32u4, AVR should send such alert message to linino where daemon save events in SQLite and send sms and etc.
For easy programming, I prefer to use Python bridgeclient.py library but I need some routing for checking available messages, like:
avr = bridgeclient.begin()
While True:
If avr.messageavailable():
msg = avr.readmessage()
If msg = "leaking detected":
sensors = avr.get('SENSORS')
... Do something ...
But currently I have to develop own library based on sockets operation and manage communication with JSONServer listening on 5700 by own way.
So, I just what to know is any others developers met with it and already developed some additional library for Python or not?
I have modified bridgeclient.py to be able to read messages from AVR.
Here is my code. In the bridgeclient.py you should replace wait_response method to avoid unnessesary 100ms delay and add to the end additional method get_message:
def wait_response(self, json, timeout):
if timeout is None or timeout < 0:
timeout = 0
while timeout >= 0:
r = json.recv()
if not r is None:
return r
timeout -= 0.1
if timeout >= 0:
sleep(0.1)
return None
...
def get_message(self, timeout=0):
json = self.socket_open()
r = self.wait_response(json, timeout)
m = None
if not r is None:
try:
m = r['data']
except:
pass
self.socket_close()
return m
I have also renamed message method into send_message.
So now, the bridgeclient_message_example.py is:
#!/usr/bin/python
import sys
sys.path.insert(0, '/usr/lib/python2.7/bridge')
from bridgeclient import BridgeClient as bridgeclient
avr = bridgeclient()
avr.begin()
while True:
msg = avr.getmessage()
if not msg is None:
print msg
avr.close()
I've not tried it, but thanks for posting your code. The Mailbox class has always shown a lot of potential, but as you discovered it is incomplete. This should help the situation.