导航

    • 登录
    • 搜索
    • 版块
    • 产品
    • 教程
    • 论坛
    • 淘宝
    1. 主页
    2. wqyp
    3. 楼层
    W
    • 资料
    • 关注
    • 粉丝
    • 屏蔽
    • 帖子
    • 楼层
    • 最佳
    • 群组

    wqyp 发布的帖子

    • 官方提供的WIFI例程,while循环的意义是什么呀?

      🤣

      import sensor, image, time, network, usocket, sys
      
      SSID ='OPENMV_AP'    # Network SSID
      KEY  ='1234567890'    # Network key (must be 10 chars)
      HOST = ''           # Use first available interface
      PORT = 8080         # Arbitrary non-privileged port
      
      # Reset sensor
      sensor.reset()
      # Set sensor settings
      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)
      
      # Init wlan module in AP mode.
      wlan = network.WINC(mode=network.WINC.MODE_AP)
      wlan.start_ap(SSID, key=KEY, security=wlan.WEP, channel=2)
      
      # You can block waiting for client to connect
      #print(wlan.wait_for_sta(10000))
      
      def response(s):
          print ('Waiting for connections..')
          client, addr = s.accept()
          # set client socket timeout to 2s
          client.settimeout(2.0)
          print ('Connected to ' + addr[0] + ':' + str(addr[1]))
      
          # Read request from client
          data = client.recv(1024)
          # Should parse client request here
      
          # Send multipart header
          client.send("HTTP/1.1 200 OK\r\n" \
                      "Server: OpenMV\r\n" \
                      "Content-Type: image/jpeg\r\n\r\n")
      
          # FPS clock
          clock = time.clock()
      
          # Start streaming images
          # NOTE: Disable IDE preview to increase streaming FPS.
      
      
          frame = sensor.snapshot()
          cframe = frame.compressed(quality=35)
          client.send(cframe)
          client.close()
      
      while (True):
          # Create server socket
          s = usocket.socket(usocket.AF_INET, usocket.SOCK_STREAM)
          try:
              # Bind and listen
              s.bind([HOST, PORT])
              s.listen(5)
      
              # Set server socket timeout
              # NOTE: Due to a WINC FW bug, the server socket must be closed and reopened if
              # the client disconnects. Use a timeout here to close and re-create the socket.
              s.settimeout(3)
              response(s)
          except OSError as e:
              s.close()
              print("socket error: ", e)
              #sys.print_exception(e)
      
      
      发布在 OpenMV Cam
      W
      wqyp
    • socket传输图片未能传输完全,代码如何修改?

      socket传输的图片效果
      0_1586658813677_nw.jpg

      openmv客户端

      import sensor, image, time, network, usocket, sys
      
      # Reset sensor
      sensor.reset()
      
      # Set sensor settings
      sensor.set_contrast(1)
      sensor.set_brightness(1)
      sensor.set_saturation(1)
      sensor.set_gainceiling(16)
      sensor.set_framesize(sensor.QVGA)
      sensor.set_pixformat(sensor.RGB565)
      sensor.set_auto_gain(True)
      sensor.set_auto_whitebal(True)
      
      SSID='*******'
      KEY='*******'
      wlan = network.WINC()
      wlan.connect(SSID, key=KEY, security=wlan.WPA_PSK)
      print(wlan.ifconfig())
      
      addr=("******",20000)
      
      # connect to serve
      client = usocket.socket(usocket.AF_INET, usocket.SOCK_STREAM)
      client.connect(addr)
      
      client.settimeout(0)
      
      frame = sensor.snapshot()
      cframe = frame.compressed(quality=35)
      client.send(str(cframe.size()))
      client.send(cframe)
      
      client.close()
      
      

      服务器端

      import base64
      import threading
      from socket import *
      import time
      
      print("Waiting for connection...")
      phserv = socket(AF_INET,SOCK_STREAM)
      phserv.bind(('******', 20000))
      phserv.listen(5)
      car, addr = phserv.accept()
      print("Connected to")
      print(addr)
      
      a=car.recv(4)
      size=int(a.decode())
      time.sleep(1)
      
      fl=open('nw2.jpg','wb')
      while size>0:
              data = car.recv(1024)
              fl.write(data)
              size=size-len(data)
      
      time.sleep(0.02)
      fl.close()
      car.close()
      
      
      发布在 OpenMV Cam
      W
      wqyp