예제 #1
0
파일: rtsp.py 프로젝트: zm321/openmv
 def __init__(self,
              ssid,
              ssid_key,
              ssid_security,
              port=554,
              mode=network.WINC.MODE_STA,
              static_ip=None):  # private
     self.__winc = network.WINC(mode=mode)
     if mode == network.WINC.MODE_STA:
         if static_ip is not None: self.__winc.ifconfig(static_ip)
         self.__winc.connect(ssid, key=ssid_key, security=ssid_security)
         if not self.__winc.isconnected():
             raise OSError("Failed to connect to network!")
     elif mode == network.WINC.MODE_AP:
         self.__winc.start_ap(ssid, key=ssid_key, security=ssid_security)
     else:
         raise ValueError("Invalid mode")
     self.__myip = self.__winc.ifconfig()[0]
     self.__myaddr = (self.__myip, port)
     self.__tcp__socket = None
     self.__udp__socket = None
     self.__setup_cb = None
     self.__play_cb = None
     self.__pause_cb = None
     self.__teardown_cb = None
     self.__pathname = ""
     self.__session = pyb.rng()
     self.__transport_is_tcp = False
     self.__client_rtp_addr = None
     self.__playing = False
     self.__sequence_number = pyb.rng() & 0xFFFF
     self.__ssrc = pyb.rng()
     print("IP Address:Port %s:%d\nRunning..." % self.__myaddr)
예제 #2
0
    def start_wifi_hw(self):
        if self.wlan is None:
            try:
                self.wlan = network.WINC(mode=self.winc_mode)
                self.hw_retries = 0
            except OSError as exc:
                excstr = exclogger.log_exception(exc)
                if "irmware version mismatch" in excstr:
                    print("WiFi shield requires a firmware update!")
                    attempt_fw_update()
                else:
                    exclogger.log_exception("most likely hardware fault")
                    self.wlan = None
                    self.hw_retries += 1

        if self.wlan is None:
            self.wifi_timestamp = pyb.millis()
            return

        if self.winc_mode == network.WINC.MODE_AP:
            if self.winc_security == network.WINC.WPA_PSK:
                self.winc_security = network.WINC.WEP
            self.wlan.start_ap(self.ssid,
                               key=self.password,
                               security=self.winc_security)
            self.ip = self.wlan.ifconfig()[0]
            if self.ip == "0.0.0.0":
                self.ip = "192.168.1.1"
        else:
            self.wlan.connect(self.ssid,
                              key=self.password,
                              security=self.winc_security)
            self.ip = "0.0.0.0"
            self.wifi_timestamp = pyb.millis()
예제 #3
0
    def start_wifi_hw(self):
        if self.wlan is None:
            try:
                self.wlan = network.WINC(mode=self.winc_mode)
                self.hw_retries = 0
            except OSError as exc:
                exclogger.log_exception(exc)
                exclogger.log_exception("most likely hardware fault")
                self.wlan = None
                self.hw_retries += 1

        if self.wlan is None:
            self.wifi_timestamp = pyb.millis()
            return

        if self.winc_mode == network.WINC.MODE_AP:
            if self.winc_security == network.WINC.WPA_PSK:
                self.winc_security = network.WINC.WEP
            self.wlan.start_ap(self.ssid,
                               key=self.password,
                               security=self.winc_security)
            self.ip = self.wlan.ifconfig()[0]
            if self.ip == "0.0.0.0":
                self.ip = "192.168.1.1"
        else:
            self.wlan.connect(self.ssid,
                              key=self.password,
                              security=self.winc_security)
            self.ip = "0.0.0.0"
            self.wifi_timestamp = pyb.millis()
예제 #4
0
 def __init__(self, ssid, ssid_key, ssid_security, port=0x1DBA, mode=network.WINC.MODE_STA, static_ip=None): # private
     self._udp_limit = 1400
     self._timeout_scale = 10
     self.__winc = network.WINC(mode=mode)
     if mode == network.WINC.MODE_STA:
         if static_ip is not None: self.__winc.ifconfig(static_ip)
         self.__winc.connect(ssid, key=ssid_key, security=ssid_security)
         if not self.__winc.isconnected(): raise OSError("Failed to connect to network!")
     elif mode == network.WINC.MODE_AP: self.__winc.start_ap(ssid, key=ssid_key, security=ssid_security)
     else: raise ValueError("Invalid mode")
     self.__myip = self.__winc.ifconfig()[0]
     self.__myaddr = (self.__myip, port)
     self.__master_addr = None
     self.__tcp__socket = None
     self.__udp__socket = None
     print("IP Address:Port %s:%d\nRunning..." % self.__myaddr)
     rpc_slave.__init__(self)
예제 #5
0
def attempt_fw_update(fpath="/winc_19_6_1.bin"):
    try:
        st = uos.stat(fpath)
        wlan = network.WINC(mode=network.WINC.MODE_FIRMWARE)
        wlan.fw_update(fpath)
    except OSError as exc2:
        if exc2.args[0] == 2:
            while True:
                print("WiFi shield firmware update file is missing at \"" +
                      fpath + "\"")
                pyb.delay(500)
                pass
        else:
            exclogger.log_exception(exc2)
            while True:
                print("WiFi shield firmware update failed")
                pyb.delay(500)
                pass
    except Exception as exc2:
        exclogger.log_exception(exc2)
        while True:
            print("WiFi shield firmware update failed")
            pyb.delay(500)
            pass
예제 #6
0
파일: ntp.py 프로젝트: zsyqweqwe2/openmv
# NTP Example
#
# This example shows how to get the current time using NTP with the WiFi shield.

import network, usocket, ustruct, utime

SSID='' # Network SSID
KEY=''  # Network key

TIMESTAMP = 2208988800+946684800

# Init wlan module and connect to network
print("Trying to connect... (may take a while)...")

wlan = network.WINC()
wlan.connect(SSID, key=KEY, security=wlan.WPA_PSK)

# We should have a valid IP now via DHCP
print(wlan.ifconfig())

# Create new socket
client = usocket.socket(usocket.AF_INET, usocket.SOCK_DGRAM)

# Get addr info via DNS
addr = usocket.getaddrinfo("pool.ntp.org", 123)[0][4]

# Send query
client.sendto('\x1b' + 47 * '\0', addr)
data, address = client.recvfrom(1024)

# Print time
예제 #7
0
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 start_streaming(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
예제 #8
0
# WINC Firmware Update Script
#
# To start have a successful firmware update create a "firmware" folder on the
# uSD card and but a bin file in it. The firmware update code will load that
# new firmware onto the WINC module.

import network

# Init wlan module in Download mode.
wlan = network.WINC(True)
#print("Firmware version:", wlan.fw_version())

# Start the firmware update process.
wlan.fw_update()
#print("Firmware version:", wlan.fw_version())
예제 #9
0
# WINC Firmware Update Script.
#
# This script updates the ATWINC1500 WiFi module firmware.
# 1) Copy the firmware image to a FAT32/exFAT SD card.
# 2) Safe remove/eject the SD card (or umount on Linux).
# 3) Reset the camera from the IDE.
# 4) Run this script to update the firmware.
#
# NOTE: Older fimware versions are no longer supported by the host driver.
# NOTE: The latest firmware (19.6.1) only works on ATWINC1500-MR210PB.
# NOTE: Firmware is at <openmv-ide-install-dir>/share/qtcreator/firmware/WINC1500/winc_19_6_1.bin

import network

# Init wlan module in Download mode.
wlan = network.WINC(mode=network.WINC.MODE_FIRMWARE)

# For ATWINC1500-MR210PB only.
wlan.fw_update("/winc_19_6_1.bin")