2118浏览
查看: 2118|回复: 1

[M10项目] 行空板WiFi保存与连接

[复制链接]
本帖最后由 量子 于 2023-7-12 20:54 编辑

行空板WiFi连接和保存

项目背景

行空板许多项目离不开WiFi,比如各种API的访问、Easy iot及Siot的通讯等等,但是行空板的网络连接却受到了限制,或多或少的需要其他设备的辅助,连接过程也较为繁琐。
在前面论坛关于python代码连接WiFi的项目中,新WiFi的配置也需要用其他设备进行编程。那么是否可以在不用其他设备的情况下,直接在行空板上保存新WiFi、连接WiFi呢?

项目设计

我们可以用Mind+的python模式进行编程,需要用到xlwt与xlrd。###         程序设置

WiFi手动连接

扫描WiFi可能需要多次尝试

代码如下(独立代码):

#  -*- coding: UTF-8 -*-

# MindPlus
# Python
from unihiker import GUI
import requests
import time

def upRange(start, stop, step):
  while start <= stop:
    yield start
    start += abs(step)

def downRange(start, stop, step):
  while start >= stop:
    yield start
    start -= abs(step)

# 事件回调函数
def button_click2():
    global SaoMiaoQingKuang_XZuoBiao
    SaoMiaoQingKuang_XZuoBiao = (SaoMiaoQingKuang_XZuoBiao - 30)
    扫描情况.config(x=SaoMiaoQingKuang_XZuoBiao)
def button_click3():
    global SaoMiaoQingKuang_XZuoBiao
    SaoMiaoQingKuang_XZuoBiao = (SaoMiaoQingKuang_XZuoBiao + 30)
    扫描情况.config(x=SaoMiaoQingKuang_XZuoBiao)
def button_click11():
    global ShuRu
    ShuRu = (str(ShuRu) + str((str("1"))))
    输入文字.config(text=ShuRu)
def button_click12():
    global ShuRu
    ShuRu = (str(ShuRu) + str((str("2"))))
    输入文字.config(text=ShuRu)
def button_click13():
    global ShuRu
    ShuRu = (str(ShuRu) + str((str("3"))))
    输入文字.config(text=ShuRu)
def button_click14():
    global ShuRu
    ShuRu = (str(ShuRu) + str((str("4"))))
    输入文字.config(text=ShuRu)
def button_click15():
    global ShuRu
    ShuRu = (str(ShuRu) + str((str("5"))))
    输入文字.config(text=ShuRu)
def button_click1():
    global SaoMiaoQingKuang_XZuoBiao
    SaoMiaoQingKuang_XZuoBiao = 42
    副标题1.config(text="扫描WiFi:")
    扫描情况.config(x=42)
    扫描情况.config(text=" , ".join((requests.get("http://10.1.2.3/wifi/scan").json()["ssid"])))
def button_click16():
    global ShuRu
    ShuRu = (str(ShuRu) + str((str("6"))))
    输入文字.config(text=ShuRu)
def button_click17():
    global ShuRu
    ShuRu = (str(ShuRu) + str((str("7"))))
    输入文字.config(text=ShuRu)
def button_click18():
    global ShuRu
    ShuRu = (str(ShuRu) + str((str("8"))))
    输入文字.config(text=ShuRu)
def button_click19():
    global ShuRu
    ShuRu = (str(ShuRu) + str((str("9"))))
    输入文字.config(text=ShuRu)
def button_click10():
    global ShuRu
    ShuRu = (str(ShuRu) + str((str("0"))))
    输入文字.config(text=ShuRu)
def button_click203():
    fileObj = open("Mind+.txt", "w", encoding="UTF8")
    fileObj.write((str((str("http://10.1.2.3/wifi/connect?") + str(WangLuo))) + str((str("&") + str(MiMa)))))
    扫描情况.config(text="保存成功")
def button_click202():
    副标题1.config(text="连接状况:")
    扫描情况.config(x=42)
    扫描情况.config(text=requests.get((str((str("http://10.1.2.3/wifi/connect?") + str(WangLuo))) + str((str("&") + str(MiMa))))).text)
def button_click103():
    global ShuRu
    ShuRu = (str("输入:"))
    输入文字.config(text=ShuRu)
def button_click1a():
    global ShuRu
    ShuRu = (str(ShuRu) + str((str("a"))))
    输入文字.config(text=ShuRu)
def button_click104():
    global ShuRu
    global LieBiaoXian
    global Xian2
    global MiMa
    Xian2 = (str("密码:"))
    LieBiaoXian = 3
    MiMa = (str("password="))
    for LieBiaoXian in (3 <= int(len(ShuRu))) and upRange(3, int(len(ShuRu)), 1) or downRange(3, int(len(ShuRu)), 1):
        Xian2 = (str((str(Xian2) + str((ShuRu[LieBiaoXian])))))
        MiMa = (str((str(MiMa) + str((ShuRu[LieBiaoXian])))))
        密码.config(text=Xian2)
def button_click1b():
    global ShuRu
    ShuRu = (str(ShuRu) + str((str("b"))))
    输入文字.config(text=ShuRu)
def button_click105():
    global ShuRu
    global WangLuo
    global LieBiaoXian
    global Xian2
    Xian2 = (str("网络:"))
    LieBiaoXian = 3
    WangLuo = (str("ssid="))
    for LieBiaoXian in (3 <= int(len(ShuRu))) and upRange(3, int(len(ShuRu)), 1) or downRange(3, int(len(ShuRu)), 1):
        Xian2 = (str((str(Xian2) + str((ShuRu[LieBiaoXian])))))
        WangLuo = (str((str(WangLuo) + str((ShuRu[LieBiaoXian])))))
        网络.config(text=Xian2)
def button_click1c():
    global ShuRu
    ShuRu = (str(ShuRu) + str((str("c"))))
    输入文字.config(text=ShuRu)
def button_click1d():
    global ShuRu
    ShuRu = (str(ShuRu) + str((str("d"))))
    输入文字.config(text=ShuRu)
def button_click1f():
    global ShuRu
    ShuRu = (str(ShuRu) + str((str("f"))))
    输入文字.config(text=ShuRu)
def button_click1e():
    global ShuRu
    ShuRu = (str(ShuRu) + str((str("e"))))
    输入文字.config(text=ShuRu)
def button_click102():
    global ShuRu
    ShuRu = (str(ShuRu) + str((str(" "))))
    ShuRu.config(text=ShuRu)
def button_click1g():
    global ShuRu
    ShuRu = (str(ShuRu) + str((str("g"))))
    输入文字.config(text=ShuRu)
def button_click1h():
    global ShuRu
    ShuRu = (str(ShuRu) + str((str("h"))))
    输入文字.config(text=ShuRu)
def button_click1k():
    global ShuRu
    ShuRu = (str(ShuRu) + str((str("k"))))
    输入文字.config(text=ShuRu)
def button_click1i():
    global ShuRu
    ShuRu = (str(ShuRu) + str((str("i"))))
    输入文字.config(text=ShuRu)
def button_click1j():
    global ShuRu
    ShuRu = (str(ShuRu) + str((str("j"))))
    输入文字.config(text=ShuRu)
def button_click1n():
    global ShuRu
    ShuRu = (str(ShuRu) + str((str("n"))))
    输入文字.config(text=ShuRu)
def button_click1l():
    global ShuRu
    ShuRu = (str(ShuRu) + str((str("l"))))
    输入文字.config(text=ShuRu)
def button_click1m():
    global ShuRu
    ShuRu = (str(ShuRu) + str((str("m"))))
    输入文字.config(text=ShuRu)
def button_click1o():
    global ShuRu
    ShuRu = (str(ShuRu) + str((str("o"))))
    输入文字.config(text=ShuRu)
def button_click1p():
    global ShuRu
    ShuRu = (str(ShuRu) + str((str("p"))))
    输入文字.config(text=ShuRu)
def button_click1q():
    global ShuRu
    ShuRu = (str(ShuRu) + str((str("q"))))
    输入文字.config(text=ShuRu)
def button_click1A():
    global ShuRu
    ShuRu = (str(ShuRu) + str((str("A"))))
    输入文字.config(text=ShuRu)
def button_click1B():
    global ShuRu
    ShuRu = (str(ShuRu) + str((str("B"))))
    输入文字.config(text=ShuRu)
def button_click1C():
    global ShuRu
    ShuRu = (str(ShuRu) + str((str("C"))))
    输入文字.config(text=ShuRu)
def button_click1D():
    global ShuRu
    ShuRu = (str(ShuRu) + str((str("D"))))
    输入文字.config(text=ShuRu)
def button_click1E():
    global ShuRu
    ShuRu = (str(ShuRu) + str((str("E"))))
    输入文字.config(text=ShuRu)
def button_click1F():
    global ShuRu
    ShuRu = (str(ShuRu) + str((str("F"))))
    输入文字.config(text=ShuRu)
def button_click1r():
    global ShuRu
    ShuRu = (str(ShuRu) + str((str("r"))))
    输入文字.config(text=ShuRu)
def button_click1G():
    global ShuRu
    ShuRu = (str(ShuRu) + str((str("G"))))
    输入文字.config(text=ShuRu)
def button_click1s():
    global ShuRu
    ShuRu = (str(ShuRu) + str((str("s"))))
    输入文字.config(text=ShuRu)
def button_click1t():
    global ShuRu
    ShuRu = (str(ShuRu) + str((str("t"))))
    输入文字.config(text=ShuRu)
def button_click1u():
    global ShuRu
    ShuRu = (str(ShuRu) + str((str("u"))))
    输入文字.config(text=ShuRu)
def button_click1v():
    global ShuRu
    ShuRu = (str(ShuRu) + str((str("v"))))
    输入文字.config(text=ShuRu)
def button_click1w():
    global ShuRu
    ShuRu = (str(ShuRu) + str((str("w"))))
    输入文字.config(text=ShuRu)
def button_click1x():
    global ShuRu
    ShuRu = (str(ShuRu) + str((str("x"))))
    输入文字.config(text=ShuRu)
def button_click1H():
    global ShuRu
    ShuRu = (str(ShuRu) + str((str("H"))))
    输入文字.config(text=ShuRu)
def button_click1y():
    global ShuRu
    ShuRu = (str(ShuRu) + str((str("y"))))
    输入文字.config(text=ShuRu)
def button_click1z():
    global ShuRu
    ShuRu = (str(ShuRu) + str((str("z"))))
    输入文字.config(text=ShuRu)
def button_click1I():
    global ShuRu
    ShuRu = (str(ShuRu) + str((str("I"))))
    输入文字.config(text=ShuRu)
def button_click1J():
    global ShuRu
    ShuRu = (str(ShuRu) + str((str("J"))))
    输入文字.config(text=ShuRu)
def button_click1K():
    global ShuRu
    ShuRu = (str(ShuRu) + str((str("K"))))
    输入文字.config(text=ShuRu)
def button_click1L():
    global ShuRu
    ShuRu = (str(ShuRu) + str((str("L"))))
    输入文字.config(text=ShuRu)
def button_click1M():
    global ShuRu
    ShuRu = (str(ShuRu) + str((str("M"))))
    输入文字.config(text=ShuRu)
def button_click1N():
    global ShuRu
    ShuRu = (str(ShuRu) + str((str("N"))))
    输入文字.config(text=ShuRu)
def button_click1O():
    global ShuRu
    ShuRu = (str(ShuRu) + str((str("O"))))
    输入文字.config(text=ShuRu)
def button_click1P():
    global ShuRu
    ShuRu = (str(ShuRu) + str((str("P"))))
    输入文字.config(text=ShuRu)
def button_click1Q():
    global ShuRu
    ShuRu = (str(ShuRu) + str((str("Q"))))
    输入文字.config(text=ShuRu)
def button_click1R():
    global ShuRu
    ShuRu = (str(ShuRu) + str((str("R"))))
    输入文字.config(text=ShuRu)
def button_click1S():
    global ShuRu
    ShuRu = (str(ShuRu) + str((str("S"))))
    输入文字.config(text=ShuRu)
def button_click1T():
    global ShuRu
    ShuRu = (str(ShuRu) + str((str("T"))))
    输入文字.config(text=ShuRu)
def button_click1U():
    global ShuRu
    ShuRu = (str(ShuRu) + str((str("U"))))
    输入文字.config(text=ShuRu)
def button_click1V():
    global ShuRu
    ShuRu = (str(ShuRu) + str((str("V"))))
    输入文字.config(text=ShuRu)
def button_click1W():
    global ShuRu
    ShuRu = (str(ShuRu) + str((str("W"))))
    输入文字.config(text=ShuRu)
def button_click1X():
    global ShuRu
    ShuRu = (str(ShuRu) + str((str("X"))))
    输入文字.config(text=ShuRu)
def button_click1Y():
    global ShuRu
    ShuRu = (str(ShuRu) + str((str("Y"))))
    输入文字.config(text=ShuRu)
def button_clicklian1():
    global ShuRu
    ShuRu = (str(ShuRu) + str((str("-"))))
    输入文字.config(text=ShuRu)
def button_clicklian2():
    global ShuRu
    ShuRu = (str(ShuRu) + str((str("_"))))
    输入文字.config(text=ShuRu)
def button_click1dx():
    大写.config(onclick=button_click1xx)
    大写.config(text="小写")
    a.config(onclick=button_click1A)
    b.config(onclick=button_click1B)
    c.config(onclick=button_click1C)
    d.config(onclick=button_click1D)
    e.config(onclick=button_click1E)
    f.config(onclick=button_click1F)
    g.config(onclick=button_click1G)
    h.config(onclick=button_click1H)
    i.config(onclick=button_click1I)
    j.config(onclick=button_click1J)
    k.config(onclick=button_click1K)
    l.config(onclick=button_click1L)
    m.config(onclick=button_click1M)
    n.config(onclick=button_click1N)
    o.config(onclick=button_click1O)
    p.config(onclick=button_click1P)
    q.config(onclick=button_click1Q)
    r.config(onclick=button_click1R)
    s.config(onclick=button_click1S)
    t.config(onclick=button_click1T)
    u.config(onclick=button_click1U)
    v.config(onclick=button_click1V)
    w.config(onclick=button_click1W)
    x.config(onclick=button_click1X)
    y.config(onclick=button_click1Y)
    z.config(onclick=button_click1Z)
    连字符.config(onclick=button_clicklian2)
    time.sleep(0.1)
    连字符.config(text="_")
    a.config(text="A")
    b.config(text="B")
    c.config(text="C")
    d.config(text="D")
    e.config(text="E")
    f.config(text="F")
    g.config(text="G")
    h.config(text="H")
    i.config(text="I")
    j.config(text="J")
    k.config(text="K")
    l.config(text="L")
    m.config(text="M")
    n.config(text="N")
    o.config(text="O")
    p.config(text="P")
    q.config(text="Q")
    r.config(text="R")
    s.config(text="S")
    t.config(text="T")
    u.config(text="U")
    v.config(text="V")
    w.config(text="W")
    x.config(text="X")
    y.config(text="Y")
    z.config(text="Z")
def button_click1Z():
    global ShuRu
    ShuRu = (str(ShuRu) + str((str("Z"))))
    输入文字.config(text=ShuRu)
def button_click1xx():
    大写.config(onclick=button_click1dx)
    大写.config(text="大写")
    a.config(onclick=button_click1a)
    b.config(onclick=button_click1b)
    c.config(onclick=button_click1c)
    d.config(onclick=button_click1d)
    e.config(onclick=button_click1e)
    f.config(onclick=button_click1f)
    g.config(onclick=button_click1g)
    h.config(onclick=button_click1h)
    i.config(onclick=button_click1i)
    j.config(onclick=button_click1j)
    k.config(onclick=button_click1k)
    l.config(onclick=button_click1l)
    m.config(onclick=button_click1m)
    n.config(onclick=button_click1n)
    o.config(onclick=button_click1o)
    p.config(onclick=button_click1p)
    q.config(onclick=button_click1q)
    r.config(onclick=button_click1r)
    s.config(onclick=button_click1s)
    t.config(onclick=button_click1t)
    u.config(onclick=button_click1u)
    v.config(onclick=button_click1v)
    w.config(onclick=button_click1w)
    x.config(onclick=button_click1x)
    y.config(onclick=button_click1y)
    z.config(onclick=button_click1z)
    连字符.config(onclick=button_clicklian1)
    time.sleep(0.1)
    连字符.config(text="-")
    a.config(text="a")
    b.config(text="b")
    c.config(text="c")
    d.config(text="d")
    e.config(text="e")
    f.config(text="f")
    g.config(text="g")
    h.config(text="h")
    i.config(text="i")
    j.config(text="j")
    k.config(text="k")
    l.config(text="l")
    m.config(text="m")
    n.config(text="n")
    o.config(text="o")
    p.config(text="p")
    q.config(text="q")
    r.config(text="r")
    s.config(text="s")
    t.config(text="t")
    u.config(text="u")
    v.config(text="v")
    w.config(text="w")
    x.config(text="x")
    y.config(text="y")
    z.config(text="z")

u_gui=GUI()
global SaoMiaoQingKuang_XZuoBiao
SaoMiaoQingKuang_XZuoBiao = 42
global ShuRu
ShuRu = (str("输入:"))
global XiaXian
标题=u_gui.draw_text(text="WiFi连接",x=75,y=2,font_size=15, color="#000000")
副标题1=u_gui.draw_text(text="扫描WiFi:",x=5,y=25,font_size=11, color="#000000")
扫描情况=u_gui.draw_text(text="扫描WiFi",x=42,y=85,font_size=10, color="#000000")
扫描WiFi=u_gui.add_button(text="扫描WiFi",x=20,y=45,w=200,h=30,onclick=button_click1)
遮挡1=u_gui.fill_rect(x=0,y=80,w=41,h=30,color="#FFFFFF")
遮挡2=u_gui.fill_rect(x=199,y=80,w=41,h=30,color="#FFFFFF")
显示框1=u_gui.draw_rect(x=40,y=80,w=160,h=30,width=1,color="#660000")
调节框1=u_gui.add_button(text="<—",x=3,y=80,w=34,h=30,onclick=button_click2)
调节框2=u_gui.add_button(text="—>",x=202,y=80,w=34,h=30,onclick=button_click3)
输入文字=u_gui.draw_text(text="输入:",x=5,y=120,font_size=10, color="#000000")
网络=u_gui.draw_text(text="网络:",x=40,y=140,font_size=7, color="#333333")
密码=u_gui.draw_text(text="密码:",x=40,y=155,font_size=7, color="#000000")
输入1=u_gui.add_button(text="1",x=0,y=170,w=24,h=30,onclick=button_click11)
输入2=u_gui.add_button(text="2",x=24,y=170,w=24,h=30,onclick=button_click12)
输入3=u_gui.add_button(text="3",x=48,y=170,w=24,h=30,onclick=button_click13)
输入4=u_gui.add_button(text="4",x=72,y=170,w=24,h=30,onclick=button_click14)
输入5=u_gui.add_button(text="5",x=96,y=170,w=24,h=30,onclick=button_click15)
输入6=u_gui.add_button(text="6",x=120,y=170,w=24,h=30,onclick=button_click16)
输入7=u_gui.add_button(text="7",x=144,y=170,w=24,h=30,onclick=button_click17)
输入8=u_gui.add_button(text="8",x=168,y=170,w=24,h=30,onclick=button_click18)
输入9=u_gui.add_button(text="9",x=192,y=170,w=24,h=30,onclick=button_click19)
输入0=u_gui.add_button(text="0",x=216,y=170,w=24,h=30,onclick=button_click10)
确定=u_gui.add_button(text="修改网络",x=80,y=200,w=80,h=30,onclick=button_click105)
确定=u_gui.add_button(text="修改密码",x=160,y=200,w=80,h=30,onclick=button_click104)
空格=u_gui.add_button(text="空格",x=0,y=200,w=40,h=30,onclick=button_click102)
清除=u_gui.add_button(text="清除",x=40,y=200,w=40,h=30,onclick=button_click103)
a=u_gui.add_button(text="a",x=0,y=230,w=24,h=30,onclick=button_click1a)
b=u_gui.add_button(text="b",x=24,y=230,w=24,h=30,onclick=button_click1b)
c=u_gui.add_button(text="c",x=48,y=230,w=24,h=30,onclick=button_click1c)
d=u_gui.add_button(text="d",x=72,y=230,w=24,h=30,onclick=button_click1d)
e=u_gui.add_button(text="e",x=96,y=230,w=24,h=30,onclick=button_click1e)
f=u_gui.add_button(text="f",x=120,y=230,w=24,h=30,onclick=button_click1f)
g=u_gui.add_button(text="g",x=144,y=230,w=24,h=30,onclick=button_click1g)
h=u_gui.add_button(text="h",x=168,y=230,w=24,h=30,onclick=button_click1h)
i=u_gui.add_button(text="i",x=192,y=230,w=24,h=30,onclick=button_click1i)
j=u_gui.add_button(text="j",x=216,y=230,w=24,h=30,onclick=button_click1j)
k=u_gui.add_button(text="k",x=0,y=260,w=24,h=30,onclick=button_click1k)
l=u_gui.add_button(text="l",x=24,y=260,w=24,h=30,onclick=button_click1l)
m=u_gui.add_button(text="m",x=48,y=260,w=24,h=30,onclick=button_click1m)
n=u_gui.add_button(text="n",x=72,y=260,w=24,h=30,onclick=button_click1n)
o=u_gui.add_button(text="o",x=96,y=260,w=24,h=30,onclick=button_click1o)
p=u_gui.add_button(text="p",x=120,y=260,w=24,h=30,onclick=button_click1p)
q=u_gui.add_button(text="q",x=144,y=260,w=24,h=30,onclick=button_click1q)
r=u_gui.add_button(text="r",x=168,y=260,w=24,h=30,onclick=button_click1r)
s=u_gui.add_button(text="s",x=192,y=260,w=24,h=30,onclick=button_click1s)
t=u_gui.add_button(text="t",x=216,y=260,w=24,h=30,onclick=button_click1t)
u=u_gui.add_button(text="u",x=0,y=290,w=24,h=30,onclick=button_click1u)
v=u_gui.add_button(text="v",x=24,y=290,w=24,h=30,onclick=button_click1v)
w=u_gui.add_button(text="w",x=48,y=290,w=24,h=30,onclick=button_click1w)
x=u_gui.add_button(text="x",x=72,y=290,w=24,h=30,onclick=button_click1x)
y=u_gui.add_button(text="y",x=96,y=290,w=24,h=30,onclick=button_click1y)
z=u_gui.add_button(text="z",x=120,y=290,w=24,h=30,onclick=button_click1z)
大写=u_gui.add_button(text="大写",x=144,y=290,w=40,h=30,onclick=button_click1dx)
连字符=u_gui.add_button(text="-",x=184,y=290,w=40,h=30,onclick=button_clicklian1)
连接=u_gui.add_button(text="连接",x=0,y=140,w=40,h=30,onclick=button_click202)
保存=u_gui.add_button(text="保存",x=200,y=140,w=40,h=30,onclick=button_click203)

while True:
    pass

点击保存可以将WiFi请求格式生成Mind+.txt。

WiFi保存

需要用到上面代码中生成的Mind+.txt以及WiFi.xls,并进行覆写:

代码如下(独立代码):

#  -*- coding: UTF-8 -*-

# MindPlus
# Python
import time
import xlrd
import xlwt

def upRange(start, stop, step):
  while start <= stop:
    yield start
    start += abs(step)

def downRange(start, stop, step):
  while start >= stop:
    yield start
    start -= abs(step)

global my_variable
global XingShangXian
print("网络保存")
time.sleep(0.7)
print("读取中")
fileObj = open("Mind+.txt", "r", encoding="UTF8")
my_variable = (str(fileObj.read()))
print(my_variable)
time.sleep(0.7)
print("开始覆写")
print("覆写中")
fp = xlrd.open_workbook(filename="Mind+.xls")
table = fp.sheet_by_name("Mind+")
df = xlwt.Workbook(encoding="ascii")
dfrobot = df.add_sheet(sheetname="WiFi", cell_overwrite_ok=False)
mindStyle = xlwt.easyxf(strg_to_parse="font: name Times New Roman, color-index black, bold on", num_format_str="dd/mm/yyyy")
XingShangXian = 0
for XingShangXian in (1 <= int(table.nrows)) and upRange(1, int(table.nrows), 1) or downRange(1, int(table.nrows), 1):
    dfrobot.write((XingShangXian - 1), 0, table.row_values((XingShangXian - 1), start_colx=0, end_colx=1), style=mindStyle)
dfrobot.write(XingShangXian, 0, my_variable, style=mindStyle)
df.save("WiFi.xls")
df = xlrd.open_workbook(filename="WiFi.xls")
dfrobot = df.sheet_by_name("WiFi")
fp = xlwt.Workbook(encoding="ascii")
table = fp.add_sheet(sheetname="Mind+", cell_overwrite_ok=False)
mindStyle = xlwt.easyxf(strg_to_parse="font: name Times New Roman, color-index black, bold on", num_format_str="dd/mm/yyyy")
XingShangXian = 0
for XingShangXian in (1 <= int(dfrobot.nrows)) and upRange(1, int(dfrobot.nrows), 1) or downRange(1, int(dfrobot.nrows), 1):
    table.write((XingShangXian - 1), 0, dfrobot.row_values((XingShangXian - 1), start_colx=0, end_colx=1), style=mindStyle)
fp.save("Mind+.xls")
print("覆写完成")
time.sleep(0.7)
print("保存成功")

while True:
    pass

可将txt中的内容保存到xls中

WiFi自动连接

需要用到WiFi.xls(扫描与连接可能需要尝试多次)

代码如下(独立代码):

#  -*- coding: UTF-8 -*-

# MindPlus
# Python
from unihiker import GUI
import requests
import xlrd

# 事件回调函数
def button_click1():
    global XZuoBiao01
    XZuoBiao01 = 42
    扫描文字.config(x=XZuoBiao01)
    扫描文字.config(text=(str("扫描结果:") + str(" , ".join((requests.get("http://10.1.2.3/wifi/scan").json()["ssid"])))))
def button_click3():
    global XZuoBiao01
    XZuoBiao01 = (XZuoBiao01 - 30)
    扫描文字.config(x=XZuoBiao01)
def button_click2():
    global XZuoBiao01
    XZuoBiao01 = (XZuoBiao01 + 30)
    扫描文字.config(x=XZuoBiao01)
def button_click4():
    global XZuoBiao02
    XZuoBiao02 = (XZuoBiao02 + 30)
    连接文字.config(x=XZuoBiao02)
def button_click5():
    global XZuoBiao02
    XZuoBiao02 = (XZuoBiao02 - 30)
    连接文字.config(x=XZuoBiao02)
def button_click6():
    global XZuoBiao03
    XZuoBiao03 = (XZuoBiao03 + 30)
    连接状态.config(x=XZuoBiao03)
def button_click7():
    global XZuoBiao03
    XZuoBiao03 = (XZuoBiao03 + -30)
    连接状态.config(x=XZuoBiao03)
def button_click8():
    global LianJie
    global XZuoBiao03
    LianJie = (dfrobot.row_values(my_variable, start_colx=0, end_colx=1)[0])
    print(LianJie)
    连接状态.config(x=XZuoBiao03)
    连接状态.config(text=requests.get(LianJie).text)
def button_click9():
    global my_variable
    if (my_variable > 0):
        my_variable = (my_variable - 1)
        连接文字.config(text=dfrobot.row_values(my_variable, start_colx=0, end_colx=1))
    else:
        连接文字.config(text=dfrobot.row_values(my_variable, start_colx=0, end_colx=1))
def button_click10():
    global my_variable
    if (my_variable < ShangXian):
        my_variable = (my_variable + 1)
        连接文字.config(text=dfrobot.row_values(my_variable, start_colx=0, end_colx=1))
    else:
        连接文字.config(text=dfrobot.row_values(my_variable, start_colx=0, end_colx=1))

u_gui=GUI()
global my_variable
global ShangXian
global XZuoBiao02
global XZuoBiao01
global XZuoBiao03
my_variable = 0
XZuoBiao01 = 42
XZuoBiao02 = 42
XZuoBiao03 = 42
df = xlrd.open_workbook(filename="WiFi.xls")
dfrobot = df.sheet_by_name("WiFi")
ShangXian = (dfrobot.nrows - 1)
标题=u_gui.draw_text(text="WiFi连接",x=75,y=5,font_size=15, color="#000000")
扫描=u_gui.add_button(text="扫描WiFi",x=10,y=40,w=220,h=30,onclick=button_click1)
扫描文字=u_gui.draw_text(text="扫描WiFi",x=42,y=81,font_size=10, color="#000000")
遮挡=u_gui.fill_rect(x=0,y=75,w=41,h=30,color="#FFFFFF")
遮挡=u_gui.fill_rect(x=199,y=75,w=41,h=30,color="#FFFFFF")
显示框1=u_gui.draw_rect(x=40,y=75,w=160,h=30,width=1,color="#660000")
调节=u_gui.add_button(text="<—",x=3,y=75,w=34,h=30,onclick=button_click2)
调节=u_gui.add_button(text="—>",x=203,y=75,w=34,h=30,onclick=button_click3)
连接=u_gui.add_button(text="连接WiFi",x=10,y=110,w=220,h=30,onclick=button_click8)
连接文字=u_gui.draw_text(text=dfrobot.row_values(my_variable, start_colx=0, end_colx=1),x=42,y=176,font_size=10, color="#000000")
调换=u_gui.add_button(text="上一个",x=5,y=140,w=80,h=30,onclick=button_click9)
调换=u_gui.add_button(text="下一个",x=155,y=140,w=80,h=30,onclick=button_click10)
遮挡=u_gui.fill_rect(x=0,y=170,w=41,h=30,color="#FFFFFF")
遮挡=u_gui.fill_rect(x=199,y=170,w=41,h=30,color="#FFFFFF")
显示框2=u_gui.draw_rect(x=40,y=170,w=160,h=30,width=1,color="#660000")
调节=u_gui.add_button(text="<—",x=3,y=170,w=34,h=30,onclick=button_click4)
调节=u_gui.add_button(text="—>",x=203,y=170,w=34,h=30,onclick=button_click5)
连接状态后=u_gui.draw_text(text="连接状态:",x=5,y=225,font_size=12, color="#000000")
连接状态=u_gui.draw_text(text="连接状态",x=42,y=261,font_size=10, color="#000000")
遮挡=u_gui.fill_rect(x=0,y=255,w=41,h=30,color="#FFFFFF")
遮挡=u_gui.fill_rect(x=199,y=255,w=41,h=30,color="#FFFFFF")
显示框1=u_gui.draw_rect(x=40,y=255,w=160,h=30,width=1,color="#660000")
调节=u_gui.add_button(text="<—",x=3,y=255,w=34,h=30,onclick=button_click6)
调节=u_gui.add_button(text="—>",x=203,y=255,w=34,h=30,onclick=button_click7)

while True:
    pass

也可以用积木编程,但都需要用到txt与xls文件


问题

无法连接中文名称的网络以及有特殊字符的网络;
输入法无法进行回格操作。





WiFi.xls

18.5 KB, 下载次数: 2340

Mind .txt

52 Bytes, 下载次数: 2302

Mind .xls

18.5 KB, 下载次数: 2362

网络连接--WIFI.mp

178.62 KB, 下载次数: 2381

WiFi连接-V2.2.mp

201.59 KB, 下载次数: 2325

WiFi保存.mp

168.24 KB, 下载次数: 2365

木子呢  管理员

发表于 2023-7-13 13:57:58

6
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

为本项目制作心愿单
购买心愿单
心愿单 编辑
[[wsData.name]]

硬件清单

  • [[d.name]]
btnicon
我也要做!
点击进入购买页面
关于楼主

楼主的其它帖子

上海智位机器人股份有限公司 沪ICP备09038501号-4

© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed

mail