连上wifi模块的热点之后,192.168.1.1打不开
-
!
# MJPEG Streaming AP. # # 这个例子展示了如何在AccessPoint模式下进行MJPEG流式传输。 # Android上的Chrome,Firefox和MJpegViewer App已经过测试。 # 连接到OPENMV_AP并使用此URL:http://192.168.1.1:8080查看流。 import time, sensor, image from image import SEARCH_EX, SEARCH_DS import sensor import image import time import network import usocket import sys import sensor import image import time import network import usocket import sys import math from pyb import UART from pyb import LED from image import SEARCH_EX, SEARCH_DS Frame_Cnt = 0 fCnt_tmp = [0, 0] count = 0 rangefinder = 0 # 局部函数定义区 red_led = LED(1) green_led = LED(2) blue_led = LED(3) ir_led = LED(4) SSID ='OPENMV_AP' # Network SSID KEY ='1234567890' # wifi密码(必须为10字符) HOST = '' # 使用第一个可用的端口 PORT = 8080 # 任意非特权端口 # 重置传感器 sensor.reset() # 设置传感器设置 sensor.set_contrast(1) sensor.set_brightness(1) sensor.set_saturation(1) sensor.set_gainceiling(16) sensor.set_framesize(sensor.QQVGA) sensor.set_pixformat(sensor.GRAYSCALE) # 在AP模式下启动wlan模块。 wlan = network.WINC(mode=network.WINC.MODE_AP) wlan.start_ap(SSID, key=KEY, security=wlan.WEP, channel=2) #您可以阻止等待客户端连接 #print(wlan.wait_for_sta(10000)) def UART_Send(FormType, Loaction0, Location1, range_finder=0): global Frame_Cnt global fCnt_tmp Frame_Head = [170, 170] Frame_End = [85, 85] fFormType_tmp = [FormType] Frame_Cnt += 1 if Frame_Cnt > 65534: FrameCnt = 0 fHead = bytes(Frame_Head) fCnt_tmp[0] = range_finder & 0xFF fCnt_tmp[1] = range_finder >> 8 # if(range_finder != 0): # fCnt_tmp[1] = range_finder fCnt = bytes(fCnt_tmp) fFormType = bytes(fFormType_tmp) fLoaction0 = bytes(ExceptionVar(Loaction0)) fLoaction1 = bytes(ExceptionVar(Location1)) fEnd = bytes(Frame_End) FrameBuffe = fHead + fCnt + fFormType + fLoaction0 + fLoaction1 + fEnd return FrameBuffe def ava_filter(x, filt_length): N = len(x) res = [] for i in range(N): if i <= filt_length // 2 or i >= N - (filt_length // 2): temp = x[i] else: sum = 0 for j in range(filt_length): sum += x[i - filt_length // 2 + j] temp = sum * 1.0 / filt_length res.append(temp) return res def Findblobs(img): Type=0xff p2=-1 p3=-1 greenblobs= img.find_blobs([green]) if greenblobs: green_led.on() listblobs=[] for blob in greenblobs: listblobs.append(blob.pixels()) maxindex=listblobs.index(max(listblobs)) img.draw_rectangle(greenblobs[maxindex].rect()) Type=25 p2=greenblobs[maxindex].cx() p3=greenblobs[maxindex].cy() else: print("not find") red_led.on() return Type,p2,p3 def start_streaming(s): print ('Waiting for connections..') client, addr = s.accept() # 将客户端套接字超时设置为2秒 client.settimeout(2.0) print ('Connected to ' + addr[0] + ':' + str(addr[1])) # 从客户端读取请求 data = client.recv(1024) # 应该在这里解析客户端请求 # 发送多部分head client.send("HTTP/1.1 200 OK\r\n" \ "Server: OpenMV\r\n" \ "Content-Type: multipart/x-mixed-replace;boundary=openmv\r\n" \ "Cache-Control: no-cache\r\n" \ "Pragma: no-cache\r\n\r\n") # FPS clock clock = time.clock() # 开始流媒体图像 #注:禁用IDE预览以增加流式FPS。 while (True): clock.tick() # 跟踪snapshots()之间经过的毫秒数。 img = sensor.snapshot() img.histeq(adaptive=True, clip_limit=3) (Type,p2,p3)=Findblobs(img) if Type==25 : green_led.on() red_led.off() if(len(listx)<=20 and len(listy)<=20): listx.append(p2) listy.append(p3) else: del(listx[0]) del(listy[0]) X=ava_filter(listx,20) Y=ava_filter(listy,20) p2=sum(X)/len(X) p3=sum(Y)/len(Y) img.draw_cross(int(p2),int(p3)) else: green_led.off() red_led.on() uart.write(UART_Send(Type,int(p2),int(p3))) cframe = img.compressed(quality=35) header = "\r\n--openmv\r\n" \ "Content-Type: image/jpeg\r\n"\ "Content-Length:"+str(cframe.size())+"\r\n\r\n" client.send(header) client.send(cframe) print(clock.fps()) while (True): # 创建服务器套接字 s = usocket.socket(usocket.AF_INET, usocket.SOCK_STREAM) try: # Bind and listen s.bind([HOST, PORT]) s.listen(5) # 设置服务器套接字超时 # 注意:由于WINC FW bug,如果客户端断开连接,服务器套接字必须 # 关闭并重新打开。在这里使用超时关闭并重新创建套接字。 s.settimeout(3) start_streaming(s) except OSError as e: s.close() print("socket error: ", e) #sys.print_exception(e)
-
你8080加了吗?
-
@kidswong999 加了
-
先用电脑试一下。
-
@kidswong999 还是打不开,但是例程是可以打开的