ESP8266 benchmark added

pull/7/head
Peter Hinch 2016-08-09 09:27:51 +01:00
rodzic 8ba7da0f1a
commit 3de1151fcd
2 zmienionych plików z 61 dodań i 0 usunięć

Wyświetl plik

@ -0,0 +1,56 @@
# benchmark.py Simple benchmark for umqtt.simple
# Assumes simple.py (from micropython-lib) is copied to ESP8266
# Outcome with mosquitto running on a Raspberry Pi on wired network,
# Wemos D1 Mini running on WiFi: echo received in max 154 ms min 27 ms
import ubinascii
from simple import MQTTClient
from machine import unique_id
from time import sleep, ticks_ms, ticks_diff
SERVER = "192.168.0.23"
CLIENT_ID = ubinascii.hexlify(unique_id())
TOPIC = b"led"
QOS = 1
t = 0
maxt = 0
mint = 5000
def sub_cb(topic, msg):
global t, maxt, mint
dt = ticks_diff(t, ticks_ms())
print('echo received in {} ms'.format(dt))
print((topic, msg))
maxt = max(maxt, dt)
mint = min(mint, dt)
def main(quit=True):
global t
c = MQTTClient(CLIENT_ID, SERVER)
# Subscribed messages will be delivered to this callback
c.set_callback(sub_cb)
c.connect()
c.subscribe(TOPIC, qos = QOS)
print("Connected to %s, subscribed to %s topic" % (SERVER, TOPIC))
n = 0
pubs = 0
try:
while 1:
n += 1
if not n % 100:
t = ticks_ms()
c.publish(TOPIC, str(pubs).encode('UTF8'), retain = False, qos = QOS)
c.wait_msg()
pubs += 1
if not pubs % 100:
print('echo received in max {} ms min {} ms'.
format(maxt, mint))
if quit:
return
sleep(0.05)
c.check_msg()
finally:
c.disconnect()

Wyświetl plik

@ -33,6 +33,11 @@ adjust to suit your PC.
Includes udev rules to avoid jumps from /dev/ttyACM0 to /dev/ttyACM1: ensures Pyboards of all types
appear as /dev/pyboard. Also rules for USB connected WiPy and FTDI USB/serial adaptor.
## ESP8266
benchmark.py Tests performance by periodically publishing while subscribed to the same topic.
Measures the round-trip delay. Adapt to suit your server address and desired QOS (quality of
service, 0 and 1 are supported). After 100 messages reports maximum and minimum delays.
# License
Any code placed here is released under the MIT License (MIT).