This Changes Everything! - ESP32 Micropython Open Socket Tutorial with Code

Поделиться
HTML-код
  • Опубликовано: 16 ноя 2024

Комментарии • 30

  • @capiberra4118
    @capiberra4118 4 года назад

    Interesting stuff! Not much info out there on this at this level. Thanks for sharing this. Excellent work.

  • @davebeckham5429
    @davebeckham5429 5 лет назад

    Nice tutorial Clayton Darwin. Thanks for sharing.

  • @bennguyen1313
    @bennguyen1313 4 года назад +1

    How much of the webserver is built-in / configurable? For example, in theory, could the ESP32 's RTOS SDK (TCP/IP stack) be modified to serve a custom webpage that plots/charts.js data? For example, could the esp32 serve a webpage using real-time data that comes from from a host connected to the esp32 via Uart or Spi?

    • @ClaytonDarwin
      @ClaytonDarwin  4 года назад +1

      Sure. You can serve static content, or integrate some functions into the server to serve dynamic content. The thing you have to contend with will be slower processing, a little slower transfer, and maybe adding an SD for storage space. You'll probably have to do some low-level http stuff, like sending the right headers, encoding changes, etc. I can't remember how much of that I did in the demo scripts.

    • @ClaytonDarwin
      @ClaytonDarwin  4 года назад +2

      I should set one up that folks could visit. Maybe. In my spare time.

  • @willix3766
    @willix3766 4 года назад +3

    Hello !
    I'm a french guy studying in informatic school and i found your project, really useful btw.
    However, I struggle with something. I manage to connect my desktop (client) to esp32(server), but your program doesn't send 'Data Line X'. It only disconnects 10 seconds after connection, because no data is received. Did i miss something ?

    • @ClaytonDarwin
      @ClaytonDarwin  4 года назад

      Yes. The server script has a "client_timeout" variable. It is set at 10 seconds. The idea is that you don't want to keep a socket open if there is no communication (maybe the client quit and didn't tell you). So, after the timeout it closes the socket. Just send a byte of information from the client to the server every few seconds and it will stay open. You can also make the timeout longer. Or you could completely remove it if you want.

    • @willix3766
      @willix3766 4 года назад

      @@ClaytonDarwin Oh thanks for replying that fast !
      And I think i understood that part, the problem I have is that in your video, when you run the script, both (server and client) are sending and receiving 'Data Line X'.
      In my case, server doesn't receive 'Data Line X' whereas connection between them is established.
      I apologize if it's something obvious, I've just started MicroPython like 2 days ago, thank you again for your help :)

    • @ClaytonDarwin
      @ClaytonDarwin  4 года назад

      Do you have both screens open so that you can see them connect? I mean, are you watching the ESP32 printout and the desktop printout?

    • @willix3766
      @willix3766 4 года назад

      Yes both are open, esp32's terminal shows me that my desktop managed to connect (it shows desktop's IP and other stuff about connection) but it doesn't receive data at all. That's why timeout appears and closes the socket, I watched all the video and did exactly what you did.
      If it's something you've never encounter, i'll keep trying, but i really have no clue about the problem :(

    • @ClaytonDarwin
      @ClaytonDarwin  4 года назад

      Okay, I just downloaded the script and tried them. Here is exactly what I did:
      1) Edit "opensocket_server_example.py" and set the essid and password to your local values.
      2) Load "main.py", "nettools.py", "opensocket_server.py" and "opensocket_server_example.py" onto the ESP32.
      3) Reboot the ESP32 and watch that it connects to wifi. Also watch for the IP address.
      Watch for this line: "OpenSocket Server listening on addr ('0.0.0.0', 8888)."
      4) Edit "opensocket_client.py" and add the IP address to the ESP32.
      5) Run "opensocket_client.py". I recommend using the command line.
      6) Watch for the following lines to show up:
      On ESP32: "Client 1 - OPEN - IP:192.168.254.10" # IP address will be different.
      On Desktop: "SOCKET CONNECTED"
      On ESP32: "APP LINEIN: b'_client:1'"
      On ESP32: "APP LINEIN: b'_ip:192.168.254.10'" # IP address will be different.
      On Desktop: "SENT: Data Line 1."
      On ESP32: "APP LINEIN: b'Data Line 1.'"
      On ESP32: "RETURN: b'BOUNCE Data Line 1.'"
      On Desktop: "GET: b'L1 BOUNCE Data Line 1.'"
      This works for me. If you aren't getting the same output, copy and paste the output you get.

  • @bokkenka
    @bokkenka 4 года назад

    > What movie is this from?
    Monty Python and the Holy Grail
    "Your mother was a hamster and your father smelled of elder berries!"

  • @americocherubini1489
    @americocherubini1489 4 года назад

    This is really interesting stuff! If you don't mind I would like to ask something: I am trying to set up an exp32 as an access point for an esp8266 and use an open socket for Communication. I successfully managed to use the esp32 ad an Hotspot and connect the esp8266 to it, but I just can't make the sockets work. On the server side, it seems to work fine (socket is binded to the Andress and It should be succesfully listening and waiting for clients); but on the client side (esp8266) I can't mange to connect the socket to the server. I run the command: s.connect((server_ip, server_port)) where s is the socket object, server_ip is the esp32 ip (got it by running this command on the esp32 end: wlan.ifconfig ()[0] ), and server_port is the same to the one the server socket is binded to. By running it I get: "OSerror [115]: EINPROGRESS" on first run, and then "OSerror [9] EBADF". I can't figure out if the problem is on the server side or the client side. Any suggestions?

    • @ClaytonDarwin
      @ClaytonDarwin  4 года назад

      I haven't done much with using an ESP as an access point, but the error might be related to the IP. The access point doesn't really have any real IP address. Instead they use 192.168.4.1 as the address to any sockets it runs. Are you using that?

    • @ClaytonDarwin
      @ClaytonDarwin  4 года назад

      And the access point server socket shouldn't be bound to an address: sock.bind('',80)

    • @ClaytonDarwin
      @ClaytonDarwin  4 года назад

      Here is a tutorial (not mine): randomnerdtutorials.com/micropython-esp32-esp8266-access-point-ap/

    • @americocherubini1489
      @americocherubini1489 4 года назад +1

      @@ClaytonDarwin Yes i am using 192.168.4.1 as the ip address. I am gonna quickly try out that tutorial. Thanks for answering ☺

    • @americocherubini1489
      @americocherubini1489 4 года назад

      @@ClaytonDarwin Omg cant believe it's actually working. Thank you so much!😀

  • @活久见-q3f
    @活久见-q3f 3 года назад

    Why not to use UDP to transfer data ?

    • @ClaytonDarwin
      @ClaytonDarwin  3 года назад +2

      You would have to devise your own handshake and error checking protocol if you wanted to be equally reliable to TCP, and at that point you would be reducing the speed advantage of UDP. So I stayed with TCP.

    • @活久见-q3f
      @活久见-q3f 3 года назад

      @@ClaytonDarwin OK,got it

    • @活久见-q3f
      @活久见-q3f 3 года назад

      @@ClaytonDarwin one more thing, how about OTA function for micropython ?

    • @ClaytonDarwin
      @ClaytonDarwin  3 года назад

      Not for the core OS. You can update application scripts.

  • @osamadz5884
    @osamadz5884 5 лет назад

    ty you helped me a lot
    i try build my weather station (MicroPython) for my graduation project and i try all of ways( i mean Ways that I know) and i can't get any result my project is IoT weather station with my database (my database not firebase or something like that ) and web server ( not local host ) / can u give me some sources to help me and ty