sipeed / Maixduino

Arduino port on Maix board ( k210 )
https://maixduino.sipeed.com
Other
213 stars 93 forks source link

[TCP/İP Socket] live stream using maixduino as client #120

Closed sahinemreaslan closed 2 years ago

sahinemreaslan commented 2 years ago

My Code: ` SSID = "MW40V" PASW = "***"

import sensor, image, time

sensor.reset() sensor.set_pixformat(sensor.RGB565) sensor.set_framesize(sensor.QVGA) sensor.skip_frames(time = 2000)

def enable_esp32(): from network_esp32 import wifi if wifi.isconnected() == False: for i in range(5): try:

Running within 3 seconds of power-up can cause an SD load error

            # wifi.reset(is_hard=False)
            wifi.reset(is_hard=True)
            print('try AT connect wifi...')
            wifi.connect(SSID, PASW)
            if wifi.isconnected():
                break
        except Exception as e:
            print(e)
print('network state:', wifi.isconnected(), wifi.ifconfig())

enable_esp32()

def enable_espat(): from network_espat import wifi if wifi.isconnected() == False: for i in range(5): try:

Running within 3 seconds of power-up can cause an SD load error

            # wifi.reset(is_hard=False)
            wifi.reset()
            print('try AT connect wifi...')
            wifi.connect(SSID, PASW)
            if wifi.isconnected():
                break
        except Exception as e:
            print(e)
print('network state:', wifi.isconnected(), wifi.ifconfig())

enable_espat()

def network_wiznet5k(): from network_wiznet5k import lan from machine import SPI from Maix import GPIO if lan.isconnected() == False: WIZNET5K_SPI_SCK = 21 WIZNET5K_SPI_MOSI = 8 WIZNET5K_SPI_MISO = 15 WIZNET5K_SPI_CS = 20 spi1 = SPI(4, mode=SPI.MODE_MASTER, baudrate=600 * 1000, polarity=0, phase=0, bits=8, firstbit=SPI.MSB, sck=WIZNET5K_SPI_SCK, mosi=WIZNET5K_SPI_MOSI, miso=WIZNET5K_SPI_MISO) for i in range(5): try: lan.reset(spi1, WIZNET5K_SPI_CS) print('try connect lan...') if lan.isconnected(): break except Exception as e: print(e) print('network state:', lan.isconnected(), lan.ifconfig())

network_wiznet5k()

import socket

ADDR = ("192.168.1.", 23)

sock = socket.socket() sock.connect(ADDR) sock.settimeout(1) clock = time.clock() while 1: sock.send(sensor.get_fb())

data = sock.recv(10) # old maxipy have bug (recv timeout no return last data)

#print(data) # fix
try:
  data = b""
  while True:
    tmp = sock.recv(1)
    print(tmp)
    if len(tmp) == 0:
        raise Exception('timeout or disconnected')
    data += tmp
except Exception as e:
  print("rcv:", len(data), data)
#time.sleep(2)

sock.close() ` What type of data should I send? I keep getting errors.(İMG CONVERT ??? Sensor.Snapshot() etc..)

Err Msg: "Traceback (most recent call last): File "", line 82, in OSError: [Errno 5] EIO"

sahinemreaslan commented 2 years ago

i am fixed.

BackMountainDevil commented 2 years ago

Helllo, have you met this error - ImportError: no module named 'network_esp32'? I try to run your code or network demo will got this error.

my info:

import network_esp32
print(network_esp32)
print(dir(network_esp32))

from network_esp32 import wifi
print(wifi)
sahinemreaslan commented 2 years ago

Hi, I'm telling you what to do in order.