我尝试在一个专用的Raspberry Pi(我称之为PiServer)中每隔一秒生成一个随机信号,从Raspberry Pi发送到本地web服务器。在
然后,PiServer将消息发送回Raspberry Pi,并在MySQL数据库中存储一个数据。在
现在我想看看增加发送包裹的次数需要多少时间。所以我运行以下代码(咖啡机.py)多次。在
这是我的密码
在咖啡机.py包含在客户机中from time import sleep
import requests
import datetime
import random
home = "A"
device = ["CoffeeModel01", "WashingMachine01", "RiceCooker01", "DryingMachine01", "MicrowaveModel01"]
while True:
num1 = random.randint(0, 1)
num2 = random.randint(0, 1)
num3 = random.randint(0, 1)
deviceNum = random.randint(0,4)
code = "%d%d%d" % (num1, num2, num3)
interval = random.uniform(2.0, 4.0)
timestamp = datetime.datetime.now()
payload = {"Device": device[deviceNum], "Code": code, "Time": format(timestamp), "Home": home}
print "Data Sended : Device = " + device[deviceNum] + ", Code = " + code
r = requests.post("http://160.18.2.109/HomeAuto.php", data=payload)
if r.status_code != 200:
raise Exception("Failed to post data to server")
print(r.text)
sleep(interval)
在家庭汽车.php包含在PiServer中并与SQL一起使用
^{pr2}$
问题是当我增加咖啡机.py最多100个(同时运行100个文件),某些连接已断开,日志显示如下raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='160.18.2.109', port=80): Max retries exceeded with url: /HomeAuto.php (Caused by NewConnectionError(': Failed to establish a new connection: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond',))
我想知道这个问题是因为web服务器(PHP文件)还是带宽有限或者PiServer的资源。在
注意:我尝试过使用amazonec2作为服务器,同时也使用我的笔记本电脑和PiServer。所有人都有同样的问题。在
非常感谢。在