-
Notifications
You must be signed in to change notification settings - Fork 0
/
ww.py
36 lines (32 loc) · 910 Bytes
/
ww.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import re
import requests
from requests.auth import HTTPDigestAuth
import time,datetime
import paho.mqtt.client as mqtt
import asyncio
async def reconnection(mqtt) :
mqtt_copy = mqtt
loop = asyncio.get_event_loop()
try :
await loop.run_in_executor(mqtt_copy.reconnect())
if mqtt.is_connected(): return mqtt_copy
except :
print('false')
return mqtt
client = mqtt.Client()
client.connect('localhost', 1883)
print(type(client))
client.loop_start()
time.sleep(1)
while True:
time.sleep(1)
ttt = datetime.datetime.now().strftime('%Y%m%d-%H:%M:%S')
print(ttt)
if client.is_connected() :
client.publish('/test', f'{datetime.datetime.now()}')
time.sleep(1)
else :
s = time.time()
# client = asyncio.run(reconnection(client))
client.connect_async('localhost', 1883)
print(f'{time.time()- s}:.4f')