Changed the way RPC commands are sent over HTTP, spaces must be URL encoded.

pull/1184/head
sarahmarshy 2015-06-15 11:19:48 -05:00
parent 5df10cce37
commit 8f33cfd27c
1 changed files with 29 additions and 27 deletions

View File

@ -1,29 +1,31 @@
""" #mbedRPC.py - mbed RPC interface for Python
mbed SDK #
Copyright (c) 2010-2013 ARM Limited ##Copyright (c) 2010 ARM Ltd
##
Licensed under the Apache License, Version 2.0 (the "License"); ##Permission is hereby granted, free of charge, to any person obtaining a copy
you may not use this file except in compliance with the License. ##of this software and associated documentation files (the "Software"), to deal
You may obtain a copy of the License at ##in the Software without restriction, including without limitation the rights
##to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
http://www.apache.org/licenses/LICENSE-2.0 ##copies of the Software, and to permit persons to whom the Software is
##furnished to do so, subject to the following conditions:
Unless required by applicable law or agreed to in writing, software ##
distributed under the License is distributed on an "AS IS" BASIS, ##The above copyright notice and this permission notice shall be included in
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ##all copies or substantial portions of the Software.
See the License for the specific language governing permissions and ##
limitations under the License. ##THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
##IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
##FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Example: ##AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> from mbedRPC import* ##LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
> mbed = SerialRPC("COM5",9600); ##OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
> myled = DigitalOut(mbed, "myled"); <--- Where the text in quotations matches your ##THE SOFTWARE.
RPC pin definition's second parameter, in #
this case it could be RpcDigitalOut myled(LED1,"myled"); #Example:
> myled.write(1) #>from mbedRPC import*
> #>mbed = SerialRPC("COM5",9600)
""" #>myled = DigitalOut(mbed,"myled") <--- Where the text in quotations matches your RPC pin definition's second parameter, in this case it could be RpcDigitalOut myled(LED1,"myled");
#>myled.write(1)
#>
import serial, urllib2, time import serial, urllib2, time
@ -59,7 +61,7 @@ class HTTPRPC(mbed):
self.host = "http://" + ip self.host = "http://" + ip
def rpc(self, name, method, args): def rpc(self, name, method, args):
response = urllib2.urlopen(self.host + "/rpc/" + name + "/" + method + "," + ",".join(args)) response = urllib2.urlopen(self.host + "/rpc/" + name + "/" + method + "%20" + "%20".join(args))
return response.read().strip() return response.read().strip()