M5Stack (basic/grey) as WiFi AP ?



  • Hello!;
    Sorry, I'm bit lost here. Can't find example with UIFlow (Micropyton) to run M5Stack as WiFi access point. Wanted to try simple web server.
    There's a working example with Arduino IDE, but I wanted to try with .py.
    All examples from UIFlow requier internet connection and work through M5Stack.com server which is unacceptable for me.
    I know it is possible with ESP modules, did same with regular esp8266 and esp32 boards.

    Thanks



  • Its not true its req connection to m5stack. Grab UIFlow-Desktop-IDE
    https://m5stack.com/pages/download

    Change stack device to usb mode and go play with it without api =]



  • Thanks Mati, but Im doing that since day 1, problem is there's no code examples/blocks/anything to set up wifi ap with it


  • M5Stack

    Hi @Thrasher I'm not sure whether this is exactly what you are trying to do but I wrote a simple web server program in micropython, maybe it can help you https://www.hackster.io/lukasmaximus89/m5stack-micropython-simple-web-server-20a4c4



  • @lukasmaximus said in M5Stack (basic/grey) as WiFi AP ?:

    Hi @Thrasher I'm not sure whether this is exactly what you are trying to do but I wrote a simple web server program in micropython, maybe it can help you https://www.hackster.io/lukasmaximus89/m5stack-micropython-simple-web-server-20a4c4

    Hi lukasmaximus, yes, I saw your project yesterday, problem is it requiers router/access point so M5Stack connects to it as client first. I want M5Stack to be access point itself (e.g. when you configure M5Stack at first boot to connect, M5Stack creates access point with web server)


  • M5Stack

    Hi @Thrasher I was able to configure the AP of the M5Stack with the following code but as of yet have been unable to setup the webserver on it maybe you will be more successfull than me:

    from m5stack import *
    from m5ui import *
    from uiflow import *
    import socket
    import network
    ap = network.WLAN(network.AP_IF)
    ap.active(True)
    ap.config(essid='ESP32Luke')
    ap.config(authmode=3, password='123456789')
    


  • @lukasmaximus oh great Lukas, thanks! I will start trying now, couldnt find those those commands documented anywhere.
    Thanks!
    However, where's DHCP settings? Like IP range and such? :)


  • M5Stack

    check the network and wlan pages in the official micropython docs
    https://docs.micropython.org/en/latest/library/network.WLAN.html



  • @lukasmaximus Ok, thank you, digging it



  • Im bumping this, couldnt find anything there.. Need an example of webserver (as simple as possible..)


  • M5Stack

    If you had taken the time to try and combine the code I gave you for the AP connection and the webserver code from my hackster project, you'd find it wasn't that hard. Even a guy with my limited abilities was able to bust out a quick concept in a few minutes.

    from m5stack import *
    from m5ui import *
    from uiflow import *
    import network
    
    try:
        import usocket as socket
    except:
        import socket
    
    def web_page():
        html = """<html><body>M5Stack AP Server</body></html>"""
        return html
    
    ap = network.WLAN(network.AP_IF)
    ap.active(True)
    ap.config(essid='ESP32Luke')
    ap.config(authmode=3, password='123456789')
    lcd.clear()
    
    response = None
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.bind(('192.168.4.1',80))
    s.listen(5)
    
    while True:
        conn, addr = s.accept()
        request = conn.recv(1024)
        request = str(request)
        print ('Content = %s' % request)
        lcd.print('Content = %s' % request,0,50,0xffffff)
        if ap.isconnected() == True:
            lcd.print('connected',0,0,0xffffff)
        else:
            lcd.print('not connected',0,0,0xffffff)
        response = web_page()
        conn.send('HTTP/1.1 200 OK\n')
        conn.send('Content-Type: text/html\n')
        conn.send('Connection: close\n\n')
        conn.sendall(response)
        conn.close()
    


  • @lukasmaximus
    Thanks, I've tried this code and it workes great.
    I've edited it a bit to fit my project,
    I made a simple htlm page to display
    it has 4 field to input string data.
    Now question is - how do I obtain entered data? I know old solution with parsing resulted url to obtain data from it (its not much convinient and pretty primeval way but still working)
    Im new to micropython, is it possible to get submitted data directly into variables so I can use them in my future code?
    Thanks

    upd: I've found uRequests library, but I can't think realise how to implent it within m5stack ecosystem


  • M5Stack

    @Thrasher glad you got it to work and sorry if I may have come across rude, bad day at work. I haven't tried to have any input fields on the pages I have created I'm afraid so cant help you there. I have seen various info about urequests it seems like a simpler and more robust way to implement this sort of stuff, I am currently researching it. If I come up with anything I will be sure to post it here.



  • @lukasmaximus
    No prob, I was just bit upset with some M5Stack features aswell, its all good, Im still new to ESP32 itself and as usual lacking time to discover it.
    uRequests seem to be fine for this task, I'm trying to work with VS Code but most of examples lead to M5Stack and UIFlow libraries,
    Guess I should start with something eaasy like blinking leds first :D

    Overall idea is:
    I got couple devices (maybe 3 of them) driven by own controllers (Atmega family)
    I want M5Stack to connect to them through i2c
    M5Stack runs webserver, whenever I connect it, I got 2 buttons like read and write, once I press read it gets atmega devies statuses and shows in browser, than I can edit them, press write and it will send new parameters.
    I've got atmega devices ready, html page, m5stacks, wires but can't figure out how to combine it all together
    I did similar job with atmegas some years ago and I remember I used to parse url to get params from it (GET method), but thought there's some advanced libraries already exist. I'd go MQTT but it requiers broker device which I dont want to have

    Thanks