代码拉取完成,页面将自动刷新
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)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。