1 Star 0 Fork 0

mumu / Esp8266MicroPythonOLEDProject

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
main.py 3.71 KB
一键复制 编辑 原始数据 按行查看 历史
mumu 提交于 2022-02-04 22:23 . 可用
show_str = [
"IP:",
'RUN:',
'CENT:',
'BLK:',
'PCT:',
'UP:'
]
hangju = 16
jianju = 14
def chuli_str(list_in):
a = ''
for b in list_in:
a = a+b
if len(a) > hangju:
del a,b
if len(list_in) == 2:
a = ''
for _ in range(hangju-len(list_in[1])):
a = a+' '
a = a+list_in[1]
print(a)
return a
if len(list_in) == 4:
a = ''
for _ in range(int(hangju/2)-len(list_in[1])):
a = a+' '
a = list_in[1]+a
b = ''
for _ in range(int(hangju/2)-len(list_in[3])):
b = b+' '
b = b+list_in[3]
print(a+b)
return a+b
if len(a) <= hangju:
del a,b
if len(list_in) == 2:
a = list_in[0]
for _ in range(hangju-len(list_in[0])-len(list_in[1])):
a = a+' '
a = a+list_in[1]
print(a)
return a
if len(list_in) == 4:
a = list_in[0]
for _ in range(int(hangju/2)-len(list_in[0])-len(list_in[1])):
a = a+' '
a = a+list_in[1]
b = list_in[2]
for _ in range(int(hangju/2)-len(list_in[2])-len(list_in[3])):
b = b+' '
b = b+list_in[3]
print(a+b)
return a+b
def chuli(led_in,hang_in,str_in):
led_in.show_text(0,jianju*hang_in,chuli_str(str_in),16)
def test_show():
import time
from oledsc import SSD1306_I2C
from machine import Pin, I2C
PIN_CLK = 4
PIN_SDA = 5
clk = Pin(PIN_CLK,Pin.OUT)
sda = Pin(PIN_SDA,Pin.OUT)
i2c = I2C(-1, clk, sda, freq=400000)
oled = SSD1306_I2C(128, 64, i2c)
return oled
def do_connect():
import network
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
if not wlan.isconnected():
wlan.connect('pen_123', '6451003016902589')
while not wlan.isconnected():
pass
return wlan.ifconfig()
def get_json():
import json
try:
import urequests as requests
except ImportError:
import requests
r = requests.get("http://192.168.0.120/admin/api.php")
a = json.loads(r.content)
a['1'] = a['status']
a['2'] = a['dns_queries_today']
a['3'] = a['ads_blocked_today']
a['4'] = str(int(a['ads_percentage_today']))+'%'
a['5'] = ' '+str(a['gravity_last_updated']['relative']['days'])+'D '+str(a['gravity_last_updated']['relative']['hours'])+'H '+str(a['gravity_last_updated']['relative']['minutes'])+'M'
r.close()
return a
def roll(time_in = 1):
from machine import freq
freq(160000000)
from time import sleep,time
a = test_show()
sleep_time = time_in
time_1 = time()
time_2 = time()
chishu = 0
do_connect()[0]
while True:
chishu+=1
if chishu == int(3600/sleep_time):
a.clear()
chishu = 0
cha = time_2 -time_1
if (cha >= sleep_time):
time_1 = time()
a_j = get_json()
a_j['0'] = do_connect()[0]
chuli(a,0,[show_str[0],str(a_j[str(0)])])
chuli(a,1,[show_str[1],str(a_j[str(1)]),show_str[2],str(a_j[str(2)])])
chuli(a,2,[show_str[3],str(a_j[str(3)]),show_str[4],str(a_j[str(4)])])
chuli(a,3,[show_str[5],str(a_j[str(5)])])
print('============================')
a.show()
time_2 = time()
else:
sleep(sleep_time-cha)
time_2 = time()
freq(80000000)
print("等待debug中......")
from time import sleep
sleep(3)
del sleep
while True:
try:
roll(1)
except:
pass
from machine import freq
freq(80000000)
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/MUMU-DADA/esp8266-micro-python-oledproject.git
git@gitee.com:MUMU-DADA/esp8266-micro-python-oledproject.git
MUMU-DADA
esp8266-micro-python-oledproject
Esp8266MicroPythonOLEDProject
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891