forked from fizista/micropython-umqtt.simple2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_test_main.py
More file actions
50 lines (41 loc) · 1.28 KB
/
example_test_main.py
File metadata and controls
50 lines (41 loc) · 1.28 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# ###
# <<< Add the network initiation code to your device here.>>>
# ###
import machine
import utime
import network
from ubinascii import hexlify
utime.sleep(2)
import tests as tests_mod
class TestMQTT(tests_mod.TestMQTT):
def disable_net(self):
# Works with esp32 and esp8266 ports.
# If it doesn't work with your port, please rewrite this part.
wlan = network.WLAN(network.STA_IF)
wlan.disconnect()
for i in range(500):
utime.sleep_ms(100)
if not wlan.isconnected():
return
raise Exception('Network disconnection problem!')
def enable_net(self):
# Works with esp32 and esp8266 ports.
# If it doesn't work with your port, please rewrite this part.
wlan = network.WLAN(network.STA_IF)
wlan.connect()
for i in range(500):
utime.sleep_ms(100)
if wlan.isconnected():
return
raise Exception('Network connection failure!')
# 1883 : MQTT, unencrypted
# 8883 : MQTT, encrypted
# 8884 : MQTT, encrypted, client certificate required
tests = TestMQTT(
hexlify(machine.unique_id()).decode('ascii'),
'test.mosquitto.org',
port=1883
)
tests.run()
# A single test can be run with a command:
# tests.run_test('<test_name>')