def lan_connect():
    from time import sleep_ms
    import network
    if "ETH_CLOCK_GPIO17_OUT" in dir(network):
        lan = network.LAN(mdc=machine.Pin(23),
                          mdio=machine.Pin(18),
                          phy_type=network.PHY_LAN8720,
                          phy_addr=1,
                          clock_mode=network.ETH_CLOCK_GPIO17_OUT)
    else:
        lan = network.LAN(mdc=machine.Pin(23),
                          mdio=machine.Pin(18),
                          phy_type=network.PHY_LAN8720,
                          phy_addr=1)

    lan.active(1)

    retry = 0
    while not lan.isconnected() or lan.ifconfig()[0] is '0.0.0.0':
        retry += 1
        sleep_ms(500)

        if retry > 20:
            break

    if not lan.isconnected():
        print("--- LAN: Connect error, check cable or DHCP server")
        return None

    print("--- LAN: OK")
    print('--- network config:', lan.ifconfig())
    return lan
Beispiel #2
0
def lan_init():
    global _lan_mode, lan_if
    if _lan_mode == 1:
        return True
    try:
        pp = settings.HW['lan-pwr']
        if pp <= -1:
            pp = None
        else:
            pp = machine.Pin(pp)
        lan_if = network.LAN(mdc=machine.Pin(settings.HW['lan-mdc']),
                             mdio=machine.Pin(settings.HW['lan-mdio']),
                             power=pp,
                             phy_type=settings.HW['lan-phy'],
                             phy_addr=settings.HW['lan-addr'],
                             clock_mode=settings.HW['lan-clk'])
        lan_if.active(True)
        if settings.Settings['LDHCP'] == False:
            lan_if.ifconfig(
                (settings.Settings['LIP'], settings.Settings['LMask'],
                 settings.Settings['LGW'], settings.Settings['LDNS']))
        else:
            try:
                lan_if.ifconfig('dhcp')
            except:
                pass
        _lan_mode = 1
    except Exception as e:
        print("LAN connection error ", str(e))
        lan_if = None
        _lan_mode = 0
Beispiel #3
0
def init_lan():
    lan = network.LAN(mdc=Pin(23),
                      mdio=Pin(18),
                      phy_type=network.PHY_LAN8720,
                      phy_addr=1)
    try:
        lan.active(1)
    except:
        print("Couldn't initialize LAN")
    return lan
def test_network():
    global lan
    lan = network.LAN()
    lan.active(True)
    # TODO: handle exception
    # OSError: timeout waiting for DHCP to get IP address
    lan.ifconfig('dhcp')
    result = lan.ifconfig()
    if result:
        print(result)
 def __init__(self, config, status_led=None):
     self.running = False
     self.config = config
     self.led = status_led
     self.lan = network.LAN(mdc=machine.Pin(23),
                            mdio=machine.Pin(18),
                            power=machine.Pin(12),
                            phy_type=network.PHY_LAN8720,
                            phy_addr=0,
                            clock_mode=network.ETH_CLOCK_GPIO17_OUT)
     self.wlan = network.WLAN(network.STA_IF)
     self.primary_if = self.select_interface()
     self.config.interface = self.primary_if
Beispiel #6
0
def start(port=21, verbose=0, splash=True):
    global ftpsocket, datasocket
    global verbose_l
    global client_list
    global client_busy
    global AP_addr, STA_addr

    alloc_emergency_exception_buf(100)
    verbose_l = verbose
    client_list = []
    client_busy = False

    ftpsocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    datasocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

    ftpsocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    datasocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)

    ftpsocket.bind(('0.0.0.0', port))
    datasocket.bind(('0.0.0.0', _DATA_PORT))

    ftpsocket.listen(0)
    datasocket.listen(0)

    datasocket.settimeout(10)
    ftpsocket.setsockopt(socket.SOL_SOCKET, _SO_REGISTER_HANDLER,
                         accept_ftp_connect)

    wlan = network.WLAN(network.AP_IF)
    if wlan.active():
        ifconfig = wlan.ifconfig()
        # save IP address string and numerical values of IP adress and netmask
        AP_addr = (ifconfig[0], num_ip(ifconfig[0]), num_ip(ifconfig[1]))
        if splash:
            print("FTP server started on {}:{}".format(ifconfig[0], port))
    wlan = network.WLAN(network.STA_IF)
    if wlan.active():
        ifconfig = wlan.ifconfig()
        # save IP address string and numerical values of IP adress and netmask
        STA_addr = (ifconfig[0], num_ip(ifconfig[0]), num_ip(ifconfig[1]))
        if splash:
            print("FTP server started on {}:{}".format(ifconfig[0], port))
    wlan = network.LAN()
    if wlan.active():
        ifconfig = wlan.ifconfig()
        # save IP address string and numerical values of IP adress and netmask
        STA_addr = (ifconfig[0], num_ip(ifconfig[0]), num_ip(ifconfig[1]))
        if splash:
            print("FTP server started on {}:{}".format(ifconfig[0], port))
Beispiel #7
0
def init():
    print("[LAN]: init")
    global eth, mac
    eth = network.LAN()
    mac = "".join(['{:02X}'.format(x) for x in eth.config('mac')])
Beispiel #8
0
import machine
import network
import socket
import time

# Connect to LAN if not already done by boot.py
try:
    lan
except:
    lan = network.LAN(mdc=machine.Pin(16),
                      mdio=machine.Pin(17),
                      power=None,
                      phy_type=network.PHY_LAN8720,
                      phy_addr=0)
    lan.active(1)

# Initialize light PWM, flash for 1/4 sec on boot
led = machine.Pin(23, machine.Pin.OUT)

# Wait for network
while lan.ifconfig()[0] == '0.0.0.0':
    print("Waiting for network connection...")
    time.sleep(2)
print("Network connection established, starting web server.")


# Web page HTML
def web_page():
    if led.value() == 1:
        gpio_state = "ON"
    else:
def setup():
    printOctopus()
    print("Hello, this will help you initialize your ESP")
    print("ver: " + ver + " (c)octopusLAB")
    print("Press Ctrl+C to abort")

    # TODO improve this
    # prepare directory
    if 'config' not in uos.listdir():
        uos.mkdir('config')

    run = True
    while run:
        sele = setupMenu()

        if sele == "q":
            print("all OK, press CTRL+D to soft reboot")
            run = False

        if sele == "w":
            from utils.wifi_connect import WiFiConnect
            w = WiFiConnect()

            sel_w = wifiMenu()

            if sel_w == "a":
                wifi_ssid = input("SSID: ")
                wifi_pass = input("PASSWORD: "******"r":
                wifi_ssid = input("SSID: ")
                w.remove_network(wifi_ssid)

            if sel_w == "s":
                print("Saved wifi networks")

                for k, v in w.config['networks'].items():
                    print("SSID: {0}".format(k))

        if sele == "cw":
            print("Connect WiFi >")
            from utils.wifi_connect import WiFiConnect
            w = WiFiConnect()
            if w.connect():
                print("WiFi: OK")
            else:
                print("WiFi: Connect error, check configuration")

        if sele == "cl":
            print("Connect LAN >")
            import network
            if "ETH_CLOCK_GPIO17_OUT" in dir(network):
                lan = network.LAN(mdc=machine.Pin(23),
                                  mdio=machine.Pin(18),
                                  phy_type=network.PHY_LAN8720,
                                  phy_addr=1,
                                  clock_mode=network.ETH_CLOCK_GPIO17_OUT)
            else:
                lan = network.LAN(mdc=machine.Pin(23),
                                  mdio=machine.Pin(18),
                                  phy_type=network.PHY_LAN8720,
                                  phy_addr=1)

            lan.active(1)
            retry = 0
            while not lan.isconnected() or lan.ifconfig()[0] is '0.0.0.0':
                retry += 1
                time.sleep_ms(500)

                if retry > 20:
                    break

            if lan.isconnected():
                print("LAN: OK")
            else:
                print("LAN: Connect error, check cable or DHCP server")

        if sele == "sd":
            shutil()
            deplUrl = "https://octopusengine.org/download/micropython/stable.tar"
            deploy(deplUrl)
Beispiel #10
0
sensor.reset()

sensor.set_pixformat(sensor.GRAYSCALE)
sensor.set_framesize(sensor.QVGA)

# Turn off the frame buffer connection to the IDE from the OpenMV Cam side.
#
# This needs to be done when manually compressing jpeg images at higher quality
# so that the OpenMV Cam does not try to stream them to the IDE using a fall back
# mechanism if the JPEG image is too large to fit in the IDE JPEG frame buffer on the OpenMV Cam.

omv.disable_fb(True)

# Setup Network Interface

network_if = network.LAN()
network_if.active(True)
network_if.ifconfig('dhcp')

# Setup RTSP Server

server = rtsp.rtsp_server(network_if)

# For the call back functions below:
#
# `pathname` is the name of the stream resource the client wants. You can ignore this if it's not
# needed. Otherwise, you can use it to determine what image object to return. By default the path
# name will be "/".
#
# `session` is random number that will change when a new connection is established. You can use
# session with a dictionary to differentiate different accesses to the same file name.
Beispiel #11
0
import network

lan = network.LAN()
lan.config(trace=7)
lan.active(1)

RCC_BASE = 0x58024400
RCC_AHB1RSTR = 0x080
RCC_AHB1ENR = 0x0D8
RCC_APB4ENR = 0x0F4
RCC_AHB1LPENR = 0x100

ETH_BASE = 0x40028000
ETH_MACCR = 0x0000
ETH_DMAMR = 0x1000


@micropython.asm_thumb
def reg_read(r0):
    ldr(r0, [r0, 0])


@micropython.asm_thumb
def reg_write(r0, r1):
    str(r1, [r0, 0])


@micropython.asm_thumb
def reg_bit_set(r0, r1):
    ldr(r2, [r0, 0])
    orr(r2, r1)
print('Found DS devices: ', roms)

if len(roms)!=0:
    ds_sensor.convert_temp()

    for rom in roms:
        print(rom)
        print(ds_sensor.read_temp(rom))



adc = machine.ADC(machine.Pin(35))

adc.atten(machine.ADC.ATTN_11DB)

lan = network.LAN(mdc = machine.Pin(23), mdio = machine.Pin(18), power=machine.Pin(12), phy_type = network.PHY_LAN8720, phy_addr=0, clock_mode=network.ETH_CLOCK_GPIO17_OUT)

mac = ubinascii.hexlify(network.LAN().config('mac'),':').decode()
print(mac)

if lan.active(1):
    print("LAN Active")
    print(lan.ifconfig())
else:
    print("lan not active")
    
print("ipAdress:",lan.ifconfig()[0])



gotIP = False
Beispiel #13
0
import network, time

print("Configuring interface...")
l = network.LAN(mdc=machine.Pin(23),
                mdio=machine.Pin(18),
                power=machine.Pin(12),
                phy_type=network.PHY_LAN8720,
                phy_addr=1,
                clk_type=3)

print("Enabling interface...")
l.active(True)

print("Waiting for connection...")
while not l.isconnected():
    time.sleep(0.1)

print("Waiting for ip address...")
while not l.hasip():
    time.sleep(0.1)

print("Ifconfig:", l.ifconfig())
import network
import machine
import os
import upip
from time import sleep_ms

lan = network.LAN(mdc = machine.Pin(23), mdio = machine.Pin(18), power=machine.Pin(12), phy_type = network.PHY_LAN8720, phy_addr=0, clock_mode=network.ETH_CLOCK_GPIO17_OUT)
lan.active(True)
timer = 0
while not lan.isconnected():
    timer += 1
    if timer > 300000:                                   # Well, this is sketchy AF
        raise Exception ("Network took too long")
sleep_ms(5000)
upip.install("micropython-uasyncio")
upip.install("micropython-uasyncio.queues")
upip.install("micropython-utarfile")

if "tmp" not in os.listdir():
    os.mkdir("tmp")

if "firmware" not in os.listdir():
    os.mkdir("firmware")

import utarfile
for fn in os.listdir():
    if fn.endswith(".tar"):
        t = utarfile.TarFile(fn)
        for i in t:
            print(i)
            if i.type == utarfile.DIRTYPE:
Beispiel #15
0
#GPIO22 - EMAC_TXD1   : TX1
#GPIO25 - EMAC_RXD0   : RX0
#GPIO26 - EMAC_RXD1   : RX1
#GPIO27 - EMAC_RX_DV  : CRS
#GND                  : GND
#3V3                  : VCC

# press RESET or power ON/OFF ESP32 several times until it boots
# speed: ftp get from ESP32 flash is 300KB/s (3Mbps)

# some free pins recommended for ESP32 to be used as JTAG programmer

#GPIO23 JTAG_TDI
#GPIO34 JTAG_TDO (was 19)
#GPIO18 JTAG_TCK
#GPIO5  JTAG_TMS (was 21)

import network
from machine import Pin
lan = network.LAN(mdc=Pin(16),
                  mdio=Pin(17),
                  power=None,
                  id=None,
                  phy_addr=1,
                  phy_type=network.PHY_LAN8720)
lan.active(True)
# by default (no parameters), ifconfig() will request DHCP
lan.ifconfig()
# set fixed IP (address, netmask, gateway, dns)
#lan.ifconfig(('192.168.18.190', '255.255.255.0', '192.168.18.254', '192.168.18.254'))
Beispiel #16
0
'''

from machine import Pin
from uosc.client import Client
import time
import network
print("main.py loaded")

button1 = Pin(34, Pin.IN)
button2 = Pin(35, Pin.IN)

console = Client('192.168.1.162', 53000)
#ESP32-GATEWAY board rev C and above require the clock_mode parameter in network setup
nic = network.LAN(mdc=Pin(23),
                  mdio=Pin(18),
                  phy_type=network.PHY_LAN8720,
                  phy_addr=0,
                  clock_mode=network.ETH_CLOCK_GPIO17_OUT)


def networkConnect():
    if not nic.isconnected():
        nic.active(True)
        nic.ifconfig(
            ('192.168.1.254', '255.255.255.0', '192.168.1.1', '192.168.1.1'))
    print(nic.ifconfig())


#DRY, eh? Hah!

Beispiel #17
0
def setup():
    mainOctopus()
    print("Hello, this will help you initialize your ESP")
    print("ver: " + ver + " (c)octopusLAB")
    print("Press Ctrl+C to abort")

    # TODO improve this
    # prepare directory
    if 'config' not in uos.listdir():
        uos.mkdir('config')

    run = True
    while run:
        sele = setupMenu()

        if sele == "q":
            print("Setup - quit >")
            time.sleep_ms(1000)
            print("all OK, press CTRL+D to soft reboot")
            run = False

        if sele == "si":  #system_info()
            from util.sys_info import sys_info
            sys_info()

        if sele == "ds":
            print("Device setting:")
            print("   board_type  | soc_type (system on the board)")
            i = 0
            for di in devices:
                print(str(i) + ": " + str(di[0]) + " | " + str(di[1]))
                i = i + 1

            print()
            sd = input("select: ")
            #print(str(devices[int(sd)]))
            print("> " + str(devices[int(sd)][0]) + " | " +
                  str(devices[int(sd)][1]))

            dc = {}
            dc['board_type'] = str(
                devices[int(sd)][0]
            )  #input("Board type ('oLAB RobotBoard1' or 'oLAB IoTBoard1'): ")
            dc['soc_type'] = str(devices[int(
                sd)][1])  #input("SoC type ('esp32' or 'esp8266'): ")

            print("Writing to file config/device.json")
            with open('config/device.json', 'w') as f:
                ujson.dump(dc, f)
                # ujson.dump(wc, f, ensure_ascii=False, indent=4)

        if sele == "ios":
            print("I/O setting:")
            # io menu
            ioMenu()

        if sele == "iot":
            print("Testing I/O")
            from util import io_test
            io_test.all()

        if sele == "w":
            from util.wifi_connect import WiFiConnect
            w = WiFiConnect()

            sel_w = wifiMenu()

            if sel_w == "a":
                wifi_ssid = input("SSID: ")
                wifi_pass = input("PASSWORD: "******"r":
                wifi_ssid = input("SSID: ")
                w.remove_network(wifi_ssid)

            if sel_w == "s":
                print("Saved wifi networks")

                for k, v in w.config['networks'].items():
                    print("SSID: {0}".format(k))

        if sele == "cw":
            print("Connect WiFi >")
            from util.wifi_connect import WiFiConnect
            w = WiFiConnect()
            if w.connect():
                print("WiFi: OK")
            else:
                print("WiFi: Connect error, check configuration")

        if sele == "cl":
            print("Connect LAN >")
            import network
            lan = network.LAN(mdc=machine.Pin(23),
                              mdio=machine.Pin(18),
                              phy_type=network.PHY_LAN8720,
                              phy_addr=1,
                              clock_mode=network.ETH_CLOCK_GPIO17_OUT)
            lan.active(1)
            retry = 0
            while not lan.isconnected() or lan.ifconfig()[0] is '0.0.0.0':
                retry += 1
                time.sleep_ms(500)

                if retry > 20:
                    break

            if lan.isconnected():
                print("LAN: OK")
            else:
                print("LAN: Connect error, check cable or DHCP server")

        if sele == "mq":
            print("mqtt setup >")
            try:
                print()
                from util.mqtt import mqtt
                mqtt()
            except:
                print("Err.mqtt() or 'util.mqtt.py' does not exist")

        if sele == "st":
            print("Time setting >")
            rtc = machine.RTC()
            print(str(rtc.datetime()))
            setdatetime = input(
                "input 6 numbers - format: RRRRR,M,D,wd,h,m > ") + (",0,0")
            dt_str = setdatetime.split(",")
            print(str(dt_str))
            dt_int = [int(numeric_string) for numeric_string in dt_str]
            rtc.init(dt_int)
            print(str(rtc.datetime()))

        if sele == "sd":
            shutil()
            deplUrl = "https://octopusengine.org/download/micropython/stable.tar"
            deploy(deplUrl)

        if sele == "sde":
            shutil()
            deplUrl = "https://octopusengine.org/download/micropython/examples.tar"
            deploy(deplUrl)

        if sele == "sdp":
            shutil()
            deplUrl = "http://iot.petrkr.net/olab/latest.tar"
            deploy(deplUrl)

        if sele == "sdo":
            shutil()
            deplUrl = "https://octopusengine.org/download/latest.tar"
            deploy(deplUrl)

        if sele == "sdh":
            shutil()
            deplUrl = "https://octopusengine.org/download/hydroponics.tar"
            deploy(deplUrl)

        if sele == "wr":
            print("under reconstruction <")
            import esp
            esp.osdebug(None)
            import webrepl
            webrepl.start()