Example #1
0
def octopus_demo():
    print()
    #global notInitServo
    notInitServo = True
    global oled
    global fet
    ###beep(pwm0,500,100) # start beep
    #tim.init(period=1000, mode=Timer.ONE_SHOT, callback=lambda t:print("test timer - thread delay"))
    #tim.init(period=2000, mode=Timer.PERIODIC, callback=lambda t:print(2))
    printOctopus()
    print("Hello, this is basic octopusLAB example")
    print(" (Press Ctrl+C to abort | CTRL+D to soft reboot)")
    print()

    time.sleep_us(10)  # sleep for 10 microseconds
    led.blink(500)
    time.sleep_ms(300)  # 1s
    start = time.ticks_ms()

    run = True
    while run:
        sel = mainMenu()
        piezzo.beep(1000, 50)

        if sel == "a":
            print("analog input test: ")
            pin_an = Pin(pinout.ANALOG_PIN, Pin.IN)
            adc = machine.ADC(pin_an)
            an = adc.read()
            print("RAW: " + str(an))
            # TODO improve mapping formula, doc: https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/peripherals/adc.html
            print("volts: {0:.2f} V".format(an / 4096 * 10.74), 20, 50)

        if sel == "b":
            count = 5
            for _ in range(count):
                piezzo.beep(500, 100)
                led.blink(500)

        if sel == "bt":
            butt1 = Pin(pinout.BUTT1_PIN, Pin.IN, Pin.PULL_UP)
            butt2 = Pin(pinout.BUTT2_PIN, Pin.IN, Pin.PULL_UP)
            butt3 = Pin(pinout.BUTT3_PIN, Pin.IN, Pin.PULL_UP)
            count = 10
            for _ in range(count):
                print("b1-" + str(butt1.value())),
                print("b2-" + str(butt2.value())),
                print("b3-" + str(butt3.value()))
                piezzo.beep(500, 100)
                led.blink(500)

        if sel == "c":
            clt()
            printOctopus()

        if sel == "f":
            print("file info /dir/ls:")  #
            print(os.listdir())
            print("> lib: " + str(os.listdir("lib")))
            print("> util: " + str(os.listdir("util")))
            print("> pinouts: " + str(os.listdir("pinouts")))

            i2c_scann()

        if sel == "i":
            print("System info:")
            print("> octopus() ver: " + ver)
            from util.sys_info import sys_info
            sys_info()

        if sel == "m":
            time.sleep_ms(500)
            from util.buzzer.melody import mario
            piezzo.play_melody(mario)
            piezzo.nosound()

        if sel == "r1": RGBtest()
        if sel == "r8":
            np = rgb_init(8)
            Rainbow()

        if sel == "r80":
            NUMBER_LED = 8
            np = rgb_init(NUMBER_LED)
            for i in range(NUMBER_LED):
                np[i] = (1, 0, 0)
                time.sleep_ms(1)  # REVIEW:
            np.write()

        if sel == "s":
            from util.setup import setup
            setup()

        if sel == "t":
            print("temperature >")
            from lib.temperature import TemperatureSensor
            ts = TemperatureSensor(pinout.ONE_WIRE_PIN)
            temp = ts.read_temp()
            # print to console
            print(temp)

        if sel == "w":
            w_connect()

        if sel == "wr1":
            w_connect()
            np = rgb_init(1)
            import urequests
            import json
            url1 = "http://octopuslab.cz/api/ws.json"
            print(url1)
            r1 = urequests.post(url1)
            j = json.loads(r1.text)
            time.sleep_ms(2000)
            print(j["r"])
            np[0] = (j["r"], j["g"], j["b"])  #R
            np.write()

        if sel == "q":
            print("machine.reset() and Exit")
            time.sleep_ms(1000)
            machine.reset()
            run = False

        if sel == "d":
            printOctopus()
            print(">>> Display test submenu")
            print('=' * 30)
            print("--- [od] --- oled display test")
            print("--- [os] --- oled 3segment")
            print("--- [oi] --- oled display image")
            print("--- [m7] --- max display 8x7-segm")
            print("--- [m8] --- max display 8x8-matrix")
            print("--- [sd] --- serial display")
            print("-+- [nd] -+- Nextion display")
            print("-+- [id] -+- ink display")
            print('=' * 30)
            sel_d = input("select: ")

            if sel_d == "od":
                print("oled display test >")
                oled_intit()

                oled.fill(1)
                oled.show()
                time.sleep_ms(300)
                oled.fill(0)  # reset display
                oled.show()

                # write text on x, y
                oled.text('OLED test', 25, 10)
                oled.text(get_hhmm(":", rtc), 45, 29)  #time HH:MM
                oled.hline(0, 50, 128, 1)
                oled.text("octopusLAB 2018", 5, 55)  #time HH:MM
                oled.show()
                time.sleep_ms(1000)

            if sel_d == "os":
                print("oled segment test >")
                oled_intit()
                #from util.display_segment import * #???
                for num in range(10):
                    threeDigits(oled, 20 + num, True, True)
                    time.sleep_ms(50)

            if sel_d == "oi":
                print("oled image test >")
                oled_intit()
                import framebuf

                IMAGE_WIDTH = 63
                IMAGE_HEIGHT = 63

                with open('assets/octopus_image.pbm', 'rb') as f:
                    f.readline()  # Magic number
                    f.readline()  # Creator comment
                    f.readline()  # Dimensions
                    data = bytearray(f.read())
                    fbuf = framebuf.FrameBuffer(data, IMAGE_WIDTH,
                                                IMAGE_HEIGHT,
                                                framebuf.MONO_HLSB)
                    # To display just blit it to the display's framebuffer (note you need to invert, since ON pixels are dark on a normal screen, light on OLED).
                    oled.invert(1)
                    oled.blit(fbuf, 0, 0)

                oled.text("Octopus", 66, 6)
                oled.text("Lab", 82, 16)
                oled.text("Micro", 74, 35)
                oled.text("Python", 70, 45)
                oled.show()

            if sel_d == "m7":
                from lib.max7219_8digit import Display
                #spi = SPI(-1, baudrate=100000, polarity=1, phase=0, sck=Pin(14), mosi=Pin(13), miso=Pin(2))
                #ss = Pin(15, Pin.OUT)
                d7 = Display(spi, ss)
                d7.write_to_buffer('12345678')
                d7.display()

            if sel_d == "m8":
                from lib.max7219 import Matrix8x8
                d8 = Matrix8x8(spi, ss, 1)  #1/4
                #print("SPI device already in use")

                count = 6
                for i in range(count):
                    d8.fill(0)
                    d8.text(str(i), 0, 0, 1)
                    d8.show()
                    print(i)
                    time.sleep_ms(500)

                d8.fill(0)
                d8.show()

            if sel_d == "sd":
                from machine import UART
                uart = UART(2, 9600)  #UART2 > #U2TXD(SERVO1/PWM1_PIN)
                uart.write('C')  #test quick clear display

                uart.write('W7')  #change color
                uart.write('h30')  #horizontal line
                uart.write('h230')  #horizontal line

                uart.write('R0')
                uart.write('W2')  #color
                uart.write('QoctopusLAB - UART2 test*')
                time.sleep_ms(100)
                uart.write('R2')
                uart.write('W1')  #color
                uart.write('QESP32 & ROBOTboard*')
                time.sleep_ms(100)

                uart.write('R5')
                uart.write('W2')  #color

                num = 9
                for i in range(num):
                    uart.write('Q')
                    uart.write(str(num - i - 1))
                    uart.write('*')
                    time.sleep_ms(500)

        if sel == "r":
            printOctopus()
            print()
            print('=' * 30)
            print(">>> Boards special test")
            print('.' * 30)
            print("    Robot board")
            print("--- [dc] --- dc motor test")
            print("--- [se] --- servo")
            print("--- [sm] --- step motor")
            print('.' * 30)
            print("    IoT board")
            print("--- [re] --- relay test")
            print("--- [fa] --- pwm fan test")
            print("--- [li] --- led fade in")
            print("--- [lo] --- led fade out")
            print("--- [lp] --- led pulse")
            print('=' * 30)

            sel_r = input("select: ")
            if sel_r == "dc":
                print("dc motor test >")
                a1 = Pin(pinout.MOTOR_1A, Pin.OUT)
                a2 = Pin(pinout.MOTOR_2A, Pin.OUT)
                a12 = Pin(pinout.MOTOR_12EN, Pin.OUT)
                a3 = Pin(pinout.MOTOR_3A, Pin.OUT)
                a4 = Pin(pinout.MOTOR_4A, Pin.OUT)
                a34 = Pin(pinout.MOTOR_34EN, Pin.OUT)

                a34.value(0)
                a12.value(1)

                print("a12:10")
                a1.value(1)
                a2.value(0)
                time.sleep_ms(3000)
                print("a12:01")
                a1.value(0)
                a2.value(1)
                time.sleep_ms(3000)

                a12.value(0)
                a34.value(1)

                print("a34:01")
                a3.value(0)
                a4.value(1)
                time.sleep_ms(3000)
                print("a12:10")
                a3.value(1)
                a4.value(0)
                time.sleep_ms(3000)
                a34.value(0)

            if sel_r == "se":
                print("servo1 test >")
                #pwm_center = int(pinout.SERVO_MIN + (pinout.SERVO_MAX-pinout.SERVO_MIN)/2)
                pwm_center = 60

                #if notInitServo:
                print("init-servo:")
                pin_servo1 = Pin(pinout.PWM1_PIN, Pin.OUT)
                servo1 = PWM(pin_servo1, freq=50, duty=pwm_center)
                print("OK")
                time.sleep_ms(1500)
                #notInitServo = False

                time.sleep_ms(1500)
                servo1.duty(SERVO_MAX)
                time.sleep_ms(1500)
                servo1.duty(SERVO_MIN)
                time.sleep_ms(1500)

                print("degree45")
                set_degree(servo1, 45)

            if sel_r == "sm":
                from lib.sm28byj48 import SM28BYJ48
                #PCF address = 35 #33-0x21/35-0x23
                ADDRESS = 0x23
                # motor id 1 or 2
                MOTOR_ID1 = 1
                #MOTOR_ID2 = 2

                i2c_sda = Pin(pinout.I2C_SDA_PIN, Pin.IN, Pin.PULL_UP)
                i2c_scl = Pin(pinout.I2C_SCL_PIN, Pin.OUT, Pin.PULL_UP)

                i2c = machine.I2C(scl=i2c_scl, sda=i2c_sda,
                                  freq=100000)  # 100kHz as Expander is slow :(
                motor1 = SM28BYJ48(i2c, ADDRESS, MOTOR_ID1)

                # turn right 90 deg
                motor1.turn_degree(90)
                # turn left 90 deg
                motor1.turn_degree(90, 1)

            if sel_r == "re":
                print("relay test >")
                rel = Pin(pinout.RELAY_PIN, Pin.OUT)
                rel.value(1)
                time.sleep_ms(3000)
                rel.value(0)

            if sel_r == "li":
                if not fet:
                    fet = Pin(pinout.MFET_PIN, Pin.OUT)

                print("led - pwm fade in - test >")
                #lf = PWM(Pin(pinout.MFET_PIN))
                #lf.duty(0)
                #lf.freq(5000)
                #time.sleep_ms(1000)
                #for i in range(100):
                #     lf.duty(i*10)
                #     time.sleep_ms(20)
                fade_in(fet, 500, 5)

            if sel_r == "lo":
                if not fet:
                    fet = Pin(pinout.MFET_PIN, Pin.OUT)

                print("led - pwm fade out - test >")
                #lf = PWM(Pin(pinout.MFET_PIN))
                #lf.duty(1000)
                #lf.freq(5000)
                #time.sleep_ms(1000)
                #for i in range(100):
                #      lf.duty(1000-i*10)
                #      time.sleep_ms(20)
                fade_out(fet, 500, 5)

            if sel_r == "lp":
                lf = PWM(Pin(pinout.MFET_PIN))
                for i in range(5):
                    pulse(lf, 200)

        if sel == "p":
            printOctopus()
            print()
            print(">>> Projects submenu")
            print('=' * 30)
            print("--- [1] --- temporary")
            print("--- [2] --- todo")
            print("--- [3] --- ")
            print('=' * 30)

            sel_p = input("select: ")
            if sel_p == "1":
                print("project 1 >")

    delta = time.ticks_diff(time.ticks_ms(), start)  # compute time difference
    print("> delta time: " + str(delta))
    piezzo.beep(2000, 50)
    print("all OK, press CTRL+D to soft reboot")
    led.blink(50)
def setup():
    mainOctopus()
    print("Hello, this will help you initialize your ESP")
    print(ver)
    print("Press Ctrl+C to abort")
    

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

    run= True
    while run:
        sele = setupMenu()

        if sele == "e":
            print("Setup - exit >")
            time.sleep_ms(2000)
            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 == "sw":
            print("Set WiFi >")
            print()
            wc = {}
            wc['wifi_ssid'] = input("SSID: ")
            wc['wifi_pass'] = input("PASSWORD: "******"Writing to file config/wifi.json")
            with open('config/wifi.json', 'w') as f:
                ujson.dump(wc, f)
                # ujson.dump(wc, f, ensure_ascii=False, indent=4)

        if sele == "cw":
              print("Connect WiFi >")
              from util.wifi_connect import read_wifi_config, WiFiConnect
              time.sleep_ms(1000)
              wifi_config = read_wifi_config()
              print("config for: " + wifi_config["wifi_ssid"])
              w = WiFiConnect()
              w.connect(wifi_config["wifi_ssid"], wifi_config["wifi_pass"])
              print("WiFi: OK")

        if sele == "mq":
            print("Set mqtt >")
            print()
            mq = {}
            mq['mqtt_broker_ip'] = input("BROKER IP: ")
            mq['mqtt_ssl'] = input("> SSL (0/1): ")
            mq['mqtt_port'] = input("> PORT (1883/8883/?): ")
            mq['mqtt_clientid_prefix'] = input("CLIENT PREFIX: ")
            mq['mqtt_root_topic'] = input("ROOT TOPIC: ")

            # TODO improve this
            if 'config' not in uos.listdir():
                uos.makedirs('config')

            print("Writing to file config/mqtt.json")
            with open('config/mqtt.json', 'w') as f:
                ujson.dump(mq, f)

        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 == "sdp":
            shutil()
            deplUrl = "http://iot.petrkr.net/olab/latest.tar"
            deploy(deplUrl)

        if sele == "sdo":
            shutil()
            #deplUrl = "http://octopuslab.cz/download/latest.tar"
            deplUrl = "http://octopusengine.org/download/latest.tar"
            deploy(deplUrl)

        if sele == "o":
            from util.octopus import octopus
            octopus()    
Example #3
0
def mqtt():
    mainOctopus()
    print("Hello, this will help you initialize MQTT client")
    print("ver: " + ver + " (c)octopusLAB")
    print("id: " + esp_id)
    print("Press Ctrl+C to abort")

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

    run = True
    while run:
        sele = setupMenu()

        if sele == "x":
            print("Setup - exit >")
            time.sleep_ms(2000)
            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 == "cv":
            print("------- Set 0/1/str for settings ------")
            wc = {}
            wc['name'] = input("device (host)name/describe: ")
            wc['time'] = int(input("get time from server? [1/0]: "))
            wc['mysql'] = int(input("send data to mysql db [1/0]: "))
            if wc['mysql']: wc['mysqlURL'] = input("mysql Write URL: ")
            wc['mqtt'] = int(input("mqtt client [1/0]: "))
            wc['influx'] = int(input("send data to influx db [1/0]: "))
            if wc['influx']: wc['influxWriteURL'] = input("influx Write URL: ")
            wc['timer'] = int(input("timer: "))

            print("Writing to file config/mqtt_io.json")
            with open('config/mqtt_io.json', 'w') as f:
                ujson.dump(wc, f)

        if sele == "ms":
            print("Set mqtt >")
            print()
            mq = {}
            mq['mqtt_broker_ip'] = input("BROKER IP: ")
            mq['mqtt_ssl'] = int(input("> SSL (0/1): "))
            mq['mqtt_port'] = int(input("> PORT (1883/8883/?): "))
            mq['mqtt_clientid_prefix'] = input("CLIENT PREFIX: ")
            mq_user = input("Username: "******"" else mq_user
            mq_pass = input("Password: "******"" else mq_pass
            mq['mqtt_root_topic'] = input("ROOT TOPIC: ")

            print("Writing to file config/mqtt.json")
            with open('config/mqtt.json', 'w') as f:
                ujson.dump(mq, f)

        def mqtt_sub(topic, msg):
            print("MQTT Topic {0}: {1}".format(topic, msg))

        if sele == "mt":
            print("mqtt simple test:")

            print("wifi_config >")
            wifi = WiFiConnect(250)
            wifi.events_add_connecting(connecting_callback)
            wifi.events_add_connected(connected_callback)
            print("wifi.connect")
            wifi_status = wifi.connect()

            # url config: TODO > extern.

            print("mqtt_config >")
            mqtt_clientid_prefix = read_mqtt_config()["mqtt_clientid_prefix"]
            mqtt_host = read_mqtt_config()["mqtt_broker_ip"]
            mqtt_root_topic = read_mqtt_config()["mqtt_root_topic"]
            mqtt_ssl = read_mqtt_config()["mqtt_ssl"]
            mqtt_user = read_mqtt_config()["mqtt_user"]
            mqtt_pass = read_mqtt_config()["mqtt_pass"]

            mqtt_clientid = mqtt_clientid_prefix + esp_id
            c = MQTTClient(mqtt_clientid,
                           mqtt_host,
                           ssl=mqtt_ssl,
                           user=mqtt_user,
                           password=mqtt_pass)
            c.set_callback(mqtt_sub)
            print("mqtt.connect to " + mqtt_host)
            c.connect()
            """
            # c.subscribe("/octopus/device/{0}/#".format(esp_id))
            subStr = mqtt_root_topic+"/"+esp_id+"/#"
            print("subscribe (root topic + esp id):" + subStr)
            c.subscribe(subStr)
            """

            mqtt_log_topic = mqtt_root_topic + "/log"
            print("mqtt log > " + mqtt_log_topic)

            print(mqtt_log_topic)
            # mqtt_root_topic_temp = "octopus/device"
            c.publish(mqtt_log_topic,
                      esp_id)  # topic, message (value) to publish
Example #4
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()
def setup():
    print("Hello, this will help you initialize your ESP")
    print("Press Ctrl+C to abort")
    print()

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

    run= True
    while run:
        sele = setupMenu()

        if sele == "e":
            print("Setup - exit >")
            time.sleep_ms(2000)
            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 == "sw":
            print("Set WiFi >")
            print()
            wc = {}
            wc['wifi_ssid'] = input("SSID: ")
            wc['wifi_pass'] = input("PASSWORD: "******"Writing to file config/wifi.json")
            with open('config/wifi.json', 'w') as f:
                ujson.dump(wc, f)
                # ujson.dump(wc, f, ensure_ascii=False, indent=4)

        if sele == "cw":
              print("Connect WiFi >")
              from util.wifi_connect import read_wifi_config, WiFiConnect
              time.sleep_ms(1000)
              wifi_config = read_wifi_config()
              print("config for: " + wifi_config["wifi_ssid"])
              w = WiFiConnect()
              w.connect(wifi_config["wifi_ssid"], wifi_config["wifi_pass"])
              print("WiFi: OK")

        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":
            print("System download > (initial octopus modules)")
            import upip
            print("Installing shutil")
            upip.install("micropython-shutil")
            print("Running deploy")
            #deplUrl = "http://iot.petrkr.net/olab/latest.tar"
            #deplUrl = "http://octopuslab.cz/download/latest.tar"
            deplUrl = "http://octopusengine.org/download/latest.tar"
            deploy(deplUrl)