Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 3723361

Browse files
author
Marty
committedJan 25, 2022
update lib
1 parent 875f1bc commit 3723361

File tree

5 files changed

+67
-94
lines changed

5 files changed

+67
-94
lines changed
 

Diff for: ‎esp01_ssd1306_mqtt.py

+8-40
Original file line numberDiff line numberDiff line change
@@ -2,59 +2,27 @@
22
from machine import Pin,I2C
33
import time, ssd1306
44

5-
65
# ssd1306
76
i2c = I2C(scl=Pin(0), sda=Pin(2), freq=100000) #Init i2c
87
lcd = ssd1306.SSD1306_I2C(128,64,i2c) #create LCD object,Specify col and row
98

10-
11-
class Board:
12-
13-
def init(self):
14-
self.wifi = WiFi
15-
self.mqtt = MQTT
16-
self.wifi.onlilne(self.online)
17-
18-
def online(self,status):
19-
if status:
20-
debug.print("connect mqtt...")
21-
self.mqtt.connect()
22-
debug.print("mqtt OK")
23-
lcd.text("MQTT connnected!",0,0)
24-
lcd.show()
25-
else:
26-
debug.print("offline...")
27-
pass
28-
29-
def connect(self,ssid='webduino.io',pwd='webduino'):
30-
while True:
31-
if self.wifi.connect(ssid,pwd):
32-
if self.mqtt.connect('mqtt1.webduino.io','webduino','webduino'):
33-
break
34-
debug.print("WiFi Ready , MQTT Ready , ready to go...")
35-
36-
def loop(self):
37-
debug.print("run...")
38-
while True:
39-
self.mqtt.checkMsg()
40-
time.sleep(0.1)
41-
42-
439
# esp01
4410
esp01 = Board()
4511
esp01.init()
4612
esp01.connect("KingKit_2.4G","webduino")
13+
#esp01.mqtt.pub("qq123","OKOK")
4714

4815
def execEval(topic,msg):
4916
topic = topic.decode("utf-8")
5017
msg = msg.decode("utf-8")
5118
print('topic:',topic,' ,msg:',msg)
5219
if(topic == 'debug/display'):
53-
try:
54-
eval(msg)
55-
lcd.show()
56-
except:
57-
pass
20+
eval(msg)
21+
lcd.show()
5822

5923
esp01.mqtt.sub('debug/display',execEval)
60-
esp01.loop()
24+
25+
lcd.fill(0)
26+
lcd.text("MQTT connnected!",0,0)
27+
lcd.show()
28+
esp01.loop()

Diff for: ‎i2c_scanner.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import machine
2-
i2c = machine.I2C(scl=machine.Pin(4), sda=machine.Pin(5))
1+
from machine import I2C, Pin
2+
3+
i2c = I2C(scl=Pin(5), sda=Pin(4), freq=100000)
34

45
print('Scan i2c bus...')
56
devices = i2c.scan()

Diff for: ‎lib/board.py

+14-46
Original file line numberDiff line numberDiff line change
@@ -3,59 +3,27 @@
33
import time, ssd1306
44

55
# ssd1306
6-
i2c = I2C(scl=Pin(0), sda=Pin(2), freq=100000) #Init i2c
7-
lcd = ssd1306.SSD1306_I2C(128,64,i2c) #create LCD object,Specify col and row
8-
9-
10-
class Board:
11-
12-
def init(self):
13-
self.wifi = WiFi
14-
self.mqtt = MQTT
15-
self.wifi.onlilne(self.online)
16-
17-
def online(self,status):
18-
if status:
19-
debug.print("connect mqtt...")
20-
self.mqtt.connect()
21-
debug.print("mqtt OK")
22-
lcd.text("MQTT connnected!",0,0)
23-
lcd.show()
24-
else:
25-
debug.print("offline...")
26-
pass
27-
28-
def connect(self,ssid='webduino.io',pwd='webduino'):
29-
while True:
30-
if self.wifi.connect(ssid,pwd):
31-
if self.mqtt.connect('mqtt1.webduino.io','webduino','webduino'):
32-
break
33-
debug.print("WiFi Ready , MQTT Ready , ready to go...")
34-
35-
def loop(self):
36-
debug.print("run...")
37-
now = 0
38-
while True:
39-
now = now + 1
40-
if now % 100 == 0:
41-
self.mqtt.client.ping()
42-
self.mqtt.checkMsg()
43-
time.sleep(0.1)
44-
6+
i2c = I2C(scl=Pin(5), sda=Pin(4), freq=100000) #Init i2c
7+
lcd = ssd1306.SSD1306_I2C(64,48,i2c) #create LCD object,Specify col and row
458

469
# esp01
47-
esp01 = Board()
48-
esp01.init()
49-
esp01.connect("KingKit_2.4G","webduino")
50-
esp01.mqtt.pub("qq123","OKOK")
10+
wemos = Board()
11+
wemos.init()
12+
wemos.connect("KingKit_2.4G","webduino")
13+
#esp01.mqtt.pub("qq123","OKOK")
5114

5215
def execEval(topic,msg):
5316
topic = topic.decode("utf-8")
5417
msg = msg.decode("utf-8")
5518
print('topic:',topic,' ,msg:',msg)
56-
if(topic == 'display'):
19+
if(topic == 'debug/display'):
5720
eval(msg)
5821
lcd.show()
5922

60-
esp01.mqtt.sub('debug/display',execEval)
61-
esp01.loop()
23+
wemos.mqtt.sub('debug/display',execEval)
24+
25+
lcd.fill(0)
26+
lcd.text("MQTT connnected!",0,0)
27+
lcd.show()
28+
wemos.loop()
29+

Diff for: ‎lib/webduino.py

+36-1
Original file line numberDiff line numberDiff line change
@@ -147,4 +147,39 @@ def checkMsg():
147147
try:
148148
MQTT.client.check_msg()
149149
except:
150-
pass
150+
pass
151+
152+
class Board:
153+
154+
def __init__(self):
155+
self.wifi = WiFi
156+
self.mqtt = MQTT
157+
self.wifi.onlilne(self.online)
158+
159+
def online(self,status):
160+
if status:
161+
debug.print("connect mqtt...")
162+
self.mqtt.connect()
163+
debug.print("mqtt OK")
164+
lcd.text("MQTT connnected!",0,0)
165+
lcd.show()
166+
else:
167+
debug.print("offline...")
168+
pass
169+
170+
def connect(self,ssid='webduino.io',pwd='webduino'):
171+
while True:
172+
if self.wifi.connect(ssid,pwd):
173+
if self.mqtt.connect('mqtt1.webduino.io','webduino','webduino'):
174+
break
175+
debug.print("WiFi Ready , MQTT Ready , ready to go...")
176+
177+
def loop(self):
178+
debug.print("run...")
179+
now = 0
180+
while True:
181+
now = now + 1
182+
if now % 100 == 0:
183+
self.mqtt.client.ping()
184+
self.mqtt.checkMsg()
185+
time.sleep(0.1)

Diff for: ‎wemos_ssd1306.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
import ssd1306
33

44
i2c = I2C(scl=Pin(5), sda=Pin(4), freq=100000) #Init i2c
5-
lcd=ssd1306.SSD1306_I2C(64,48,i2c) #create LCD object,Specify col and row
6-
lcd.text("ESP8266",0,0)
7-
lcd.text("test",0,16)
8-
lcd.text("123456",0,32)
9-
lcd.show()
5+
6+
lcd=ssd1306.SSD1306_I2C(64,48,i2c) #create LCD object,Specify col and row
7+
lcd.text("ESP8266",0,0)
8+
lcd.text("test",0,16)
9+
lcd.text("123456",0,32)
10+
lcd.show()

0 commit comments

Comments
 (0)
Please sign in to comment.