Skip to content

Commit 4ac51f3

Browse files
author
Federico Fissore
committed
bridgeclient: added mailbox function to both python and php clients. Fixes #17
1 parent 9de2793 commit 4ac51f3

File tree

4 files changed

+31
-3
lines changed

4 files changed

+31
-3
lines changed

bridge/bridgeclient.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
## invalidate any other reasons why the executable file might be covered by
2424
## the GNU General Public License.
2525
##
26-
## Copyright 2013 Arduino LLC (http://www.arduino.cc/)
26+
## Copyright 2014 Arduino LLC (http://www.arduino.cc/)
2727

2828
from tcp import TCPJSONClient
2929
from time import sleep
@@ -81,3 +81,8 @@ def delete(self, key):
8181
r = r['value']
8282
json.close()
8383
return r
84+
85+
def mailbox(self, message):
86+
json = TCPJSONClient('127.0.0.1', 5700)
87+
json.send({'command': 'raw', 'data': message})
88+
json.close()

bridge/bridgeclient_example.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,8 @@
3636
print 'Listing all stored values'
3737
print all
3838
print 'Value assigned to D11 is ' + all['D11']
39+
40+
print
41+
42+
print 'Sending mailbox message \'Hello world!\''
43+
client.mailbox('Hello world!')

bridge/php/bridgeclient.class.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
------------------------
66
by Luca Soltoggio - 2013
77
http://www.arduinoelettronica.com/
8+
by Federico Fissore - 2014
9+
http://arduino.cc/
810
911
Released under GPL v.2 license
1012
@@ -15,7 +17,7 @@
1517
Usage
1618
-----
1719
The usage is the same as bridgeclient.py
18-
You have just three methods: get, put and getall (see example.php)
20+
You have methods: get, getall, put, delete, mailbox (see example.php)
1921
2022
*/
2123

@@ -37,7 +39,7 @@ private function disconnect() {
3739
socket_close($this->socket);
3840
}
3941

40-
private function sendcommand($command, $key = "", $value = "") {
42+
private function sendcommand($command, $key = "", $value = "", $data = "", $has_response = true) {
4143
$jsonreceive = "";
4244
$obraces = 0;
4345
$cbraces = 0;
@@ -52,10 +54,17 @@ private function sendcommand($command, $key = "", $value = "") {
5254
if ($value <> "") {
5355
$jsonsend->value = $value;
5456
}
57+
if ($data <> "") {
58+
$jsonsend->data = $data;
59+
}
5560
$jsonsend = json_encode($jsonsend);
5661

5762
socket_write($this->socket, $jsonsend, strlen($jsonsend));
5863

64+
if (!$has_response) {
65+
return;
66+
}
67+
5968
do {
6069
socket_recv($this->socket, $buffer, 1, 0);
6170
$jsonreceive .= $buffer;
@@ -92,6 +101,10 @@ public function put($key, $value) {
92101
public function delete($key) {
93102
return $this->sendcommand("delete", $key);
94103
}
104+
105+
public function mailbox($message) {
106+
return $this->sendcommand("raw", "", "", $message, false);
107+
}
95108
}
96109

97110
?>

bridge/php/example.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,9 @@
3131
print("Listing all stored values\n");
3232
print_r($all);
3333
print("Value assigned to D11 is " . $all->{"D11"} . "\n");
34+
35+
print("\n");
36+
37+
print("Sending mailbox message 'Hello world!'\n");
38+
$client->mailbox("Hello world!");
3439
?>

0 commit comments

Comments
 (0)