我有一只胳膊,通过这个臂我可以控制我的相机向右移动,向左移动,向下移动,向上移动所以我想发送这个臂的命令但是这个臂在局域网中所以我必须设计一个服务器在宽区域网络,通过此服务器,我可以从浏览器获取命令
所以我设计这样的服务器:
我通过http get http://ip:port/sendcommand/arm_id=1&camera_id=2&command_type=3&command_value=4发送命令
我通过http get http://ip:port/receivecommand/arm_id=1收到我的命令
我想得到一个json {arm_id = 1,command_type = 2,command_value = 3}
我怎么能编写我的程序
requests
可能是使用的模块。
def sendCommand():
requests.get('http://ip:port/sendcommand/arm_id=1&camera_id=2&command_type=3&command_value=4')
def getCommand():
r = requests.get('http://ip:port/receivecommand/arm_id=1')
if r.status_code == 200:
return r.content
else:
raise requests.exceptions.ConnectionError('request failed')