• OpenMV VSCode 扩展发布了,在插件市场直接搜索OpenMV就可以安装
  • 如果有产品硬件故障问题,比如无法开机,论坛很难解决。可以直接找售后维修
  • 发帖子之前,请确认看过所有的视频教程,https://singtown.com/learn/ 和所有的上手教程http://book.openmv.cc/
  • 每一个新的提问,单独发一个新帖子
  • 帖子需要目的,你要做什么?
  • 如果涉及代码,需要报错提示全部代码文本,请注意不要贴代码图片
  • 必看:玩转星瞳论坛了解一下图片上传,代码格式等问题。
  • 發生問題 OSError:-103



    • 0_1682932515313_螢幕擷取畫面 2023-05-01 171331.png

      import network
      import json
      import time
      import ujson
      import ssl
      import os
      import gc
      #import firebase_admin
      #from firebase_admin.firebase_admin import credentials
      
      # WiFi 網路設定
      #ssid = "Zouyk"
      #password = "zouyk0219"
      
      # Firebase 儲存庫的網址
      FIREBASE_URL = 'https://openmv-test-45904-default-rtdb.firebaseio.com/'
      
      ssid = "Zouyk"
      password = "zouyk0219"
      
      # 連接 WiFi
      wlan = network.WLAN(network.STA_IF)
      wlan.active(True)
      wlan.connect(ssid, password)
      
      # 等待 WiFi 連線成功
      while not wlan.isconnected():
          time.sleep(1)
      
      # 印出 IP 位置
      print(wlan.ifconfig()[0])
      
      ## 設置 Firebase 認證信息
      #cred = credentials.Certificate("openmv-test-45904-firebase-adminsdk-lupkk-6d46339002.json")
      #firebase_admin.initialize_app(cred, {
          #'databaseURL': 'https://openmv-test-45904-default-rtdb.firebaseio.com/'
      #})
      
      ## 儲存一個字串到 Firebase
      #my_string = 'Hello, Firebase!'
      #ref = db.reference('messages')
      #ref.set({'message': my_string})
      
      import urequests
      
      # 定義一個函式,用來上傳資料到 Firebase
      try:
          def save_data_to_firebase(data):
              headers = {'Content-type': 'application/json'}
              response = urequests.put(FIREBASE_URL, data=ujson.dumps(data), headers=headers)
              print('Firebase 回應:', response.content)
      except Exception as e:
          print('發生錯誤:', e)
      
      # 儲存一個字串到 Firebase
      my_string = 'Hello, Firebase!'
      data = {'message': my_string}
      
      save_data_to_firebase(data)
      
      
      import usocket
      
      class Response:
      
          def __init__(self, f):
              self.raw = f
              self.encoding = "utf-8"
              self._cached = None
      
          def close(self):
              if self.raw:
                  self.raw.close()
                  self.raw = None
              self._cached = None
      
          @property
          def content(self):
              if self._cached is None:
                  try:
                      self._cached = self.raw.read()
                  finally:
                      self.raw.close()
                      self.raw = None
              return self._cached
      
          @property
          def text(self):
              return str(self.content, self.encoding)
      
          def json(self):
              import ujson
              return ujson.loads(self.content)
      
      
      def request(method, url, data=None, json=None, headers={}, stream=None, parse_headers=True):
          redir_cnt = 1
          while True:
              try:
                  proto, dummy, host, path = url.split("/", 3)
              except ValueError:
                  proto, dummy, host = url.split("/", 2)
                  path = ""
              if proto == "http:":
                  port = 80
              elif proto == "https:":
                  import ussl
                  port = 443
              else:
                  raise ValueError("Unsupported protocol: " + proto)
      
              if ":" in host:
                  host, port = host.split(":", 1)
                  port = int(port)
      
              ai = usocket.getaddrinfo(host, port, 0, usocket.SOCK_STREAM)
              ai = ai[0]
      
              resp_d = None
              if parse_headers is not False:
                  resp_d = {}
      
              s = usocket.socket(ai[0], ai[1], ai[2])
              try:
                  s.connect(ai[-1])
                  if proto == "https:":
                      s = ussl.wrap_socket(s, server_hostname=host)
                  s.write(b"%s /%s HTTP/1.0\r\n" % (method, path))
                  if not "Host" in headers:
                      s.write(b"Host: %s\r\n" % host)
                  # Iterate over keys to avoid tuple alloc
                  for k in headers:
                      s.write(k)
                      s.write(b": ")
                      s.write(headers[k])
                      s.write(b"\r\n")
                  if json is not None:
                      assert data is None
                      import ujson
                      data = ujson.dumps(json)
                      s.write(b"Content-Type: application/json\r\n")
                  if data:
                      s.write(b"Content-Length: %d\r\n" % len(data))
                  s.write(b"Connection: close\r\n\r\n")
                  if data:
                      s.write(data)
      
                  l = s.readline()
                  #print(l)
                  l = l.split(None, 2)
                  status = int(l[1])
                  reason = ""
                  if len(l) > 2:
                      reason = l[2].rstrip()
                  while True:
                      l = s.readline()
                      if not l or l == b"\r\n":
                          break
                      #print(l)
      
                      if l.startswith(b"Transfer-Encoding:"):
                          if b"chunked" in l:
                              raise ValueError("Unsupported " + l)
                      elif l.startswith(b"Location:") and 300 <= status <= 399:
                          if not redir_cnt:
                              raise ValueError("Too many redirects")
                          redir_cnt -= 1
                          url = l[9:].decode().strip()
                          #print("redir to:", url)
                          status = 300
                          break
      
                      if parse_headers is False:
                          pass
                      elif parse_headers is True:
                          l = l.decode()
                          k, v = l.split(":", 1)
                          resp_d[k] = v.strip()
                      else:
                          parse_headers(l, resp_d)
              except OSError:
                  s.close()
                  raise
      
              if status != 300:
                  break
      
          resp = Response(s)
          resp.status_code = status
          resp.reason = reason
          if resp_d is not None:
              resp.headers = resp_d
          return resp
      
      
      def head(url, **kw):
          return request("HEAD", url, **kw)
      
      def get(url, **kw):
          return request("GET", url, **kw)
      
      def post(url, **kw):
          return request("POST", url, **kw)
      
      def put(url, **kw):
          return request("PUT", url, **kw)
      
      def patch(url, **kw):
          return request("PATCH", url, **kw)
      
      def delete(url, **kw):
          return request("DELETE", url, **kw)
      
      


    • 你https肯定不行,不支持https,改用http



    • 謝謝 但是我還是無法引入urequests套件



    • 所以OpenMV H7 plus不能使用https嗎?