123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- from maix import camera, display, zbar, image
- import socket
- import os
- import sys
- sys.path.append('/root/CocoPi.py')
- import http.client
- from CocoPi import BUTTON
- import time
- key_A = BUTTON(14)
- key_B = BUTTON(8)
- key_C = BUTTON(13)
- key_D = BUTTON(7)
- ScreenOrientation = False
- image.load_freetype("/root/preset/fonts/yahei-ttf.ttf")
- camera.camera.config(size=(240,320))
- def lcdRotation(inputImg,rotationAngle):
- from maix import image
- imageRotationBuffer = inputImg.crop(0, 0, 240, 320)
- if ScreenOrientation:
- imgRotationAim = image.new(size = (240, 320))
- else:
- imgRotationAim = image.new(size = (320, 240))
- return imgRotationAim.draw_image(imageRotationBuffer.rotate(rotationAngle, adjust=1),0,0,alpha=1)
- if ScreenOrientation:
- CAMERAROTATE = +180
- else:
- CAMERAROTATE = +90
- def getNetworkDate_noexit():
- global getDateNum
- try:
- coon = http.client.HTTPConnection('www.baidu.com')
- coon.request("GET","/")
- r = coon.getresponse()
- ts = r.getheader('date')
- GMT_time = time.strptime(ts[5:25],"%d %b %Y %H:%M:%S")
- BeiJing_time = time.localtime(time.mktime(GMT_time) + 8*60*60)
- format_time = time.strftime("%Y-%m-%d %H:%M:%S",BeiJing_time)
- command = "date -s "+"\"{}\"".format(format_time)
- os.system(command)
- getDateNum = 1
- # sys.exit()
- except:
- pass
- def wifi_is_content():
- global getDateNum
- cmd = "wifi_get_connection_info_test 1"
- res = os.popen(cmd).read()
- data = False
- print(res)
- if res.find('get connection infomation successfully!') != -1:
- data = True
- return data
- def extract_ip():
- st = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
- try:
- st.connect(("10.255.255.255",1))
- IP = st.getsockname()[0]
- except Exception:
- IP = "127.0.0.1"
- finally:
- st.close()
- return IP
- SSID = ""
- PASS = ""
- isContent = True
- contentText = ""
- canvas1 = image.new(size = (320, 240))
- while True:
- canvas = lcdRotation(camera.capture(),CAMERAROTATE)
- IP = extract_ip()
- mks = canvas.find_qrcodes()
- for mk in mks:
- #外框数据
- X = mk['x']
- Y = mk['y']
- W = mk['w']
- H = mk['h']
- #二维码信息
- string = mk['payload']
- codeData = string.split(";")
- SSID = codeData[0].split(":")[1]
- PASS = codeData[1].split(":")[1]
- #画外框
- canvas.draw_rectangle(X, Y, X + W, Y + H, color=(0, 0, 255), thickness = 2)
- #打印信息
- canvas.draw_string(int(X) , int(Y - 35) , str(string), scale = 1, color = (255, 0, 0), thickness = 2) #内框ID
- if key_C.is_pressed():
- while not (key_C.is_pressed() == False):
- time.sleep(0.01)
- os.system("wifi_disconnect_ap_test")
- os.system('wifi_connect_chinese_ap_test '+SSID+' '+PASS+'')
- isContent = False
- contentText == ""
- elif(contentText == "" and isContent == False):
- if wifi_is_content():
- contentText = "Wi-Fi success"
- canvas1 = image.new(size = (320, 320), color = (255,255,255), mode = "RGB")
- else:
- contentText = "Wi-Fi failure"
- isContent = True
- # canvas1.draw_rectangle(0,0, 320,20, color=(255,255,255), thickness=-1)
- canvas.draw_image(canvas1,0,0, alpha=0.6)
- canvas.draw_string(10,50, contentText, scale = 1.5, color = (0,0,0) , thickness = 1)
- canvas.draw_string(10,0, "Press C to take pictures for networking", scale = 1, color = (0,0,0) , thickness = 1)
- canvas.draw_string(10,20, "Hold D to build and exit", scale = 1, color =(0,0,0) , thickness = 1)
- if IP != "127.0.0.1" and contentText != "":
- canvas.draw_string(10,80, "IP:" + extract_ip(), scale = 1.5, color = (0,0,0), thickness = 1)
- display.show(canvas)
-
|