No video

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

  Рет қаралды 12,244

Clayton Darwin

Clayton Darwin

4 жыл бұрын

Here is some info and code on keeping a socket open long term to pass code and commands between a desktop and an ESP32. The code includes both a server for the ESP32 and a client application for the desktop. Everything is in MicroPython. Should be easy to adapt to different situations. This just keeps the socket open for passing data. There is no protocol beyond that. Do whatever makes sense to you and your application.
Here is a link to the code: drive.google.com/open?id=1-qg...
And the answer is... Monty Python and the Holy Grail

Пікірлер: 30
@capiberra4118
@capiberra4118 4 жыл бұрын
Interesting stuff! Not much info out there on this at this level. Thanks for sharing this. Excellent work.
@davebeckham5429
@davebeckham5429 4 жыл бұрын
Nice tutorial Clayton Darwin. Thanks for sharing.
@ClaytonDarwin
@ClaytonDarwin 4 жыл бұрын
Thanks Dave. 👍
@bennguyen1313
@bennguyen1313 4 жыл бұрын
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 жыл бұрын
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 жыл бұрын
I should set one up that folks could visit. Maybe. In my spare time.
@osamadz5884
@osamadz5884 4 жыл бұрын
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
@willix3766
@willix3766 4 жыл бұрын
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.
@americocherubini1489
@americocherubini1489 3 жыл бұрын
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 3 жыл бұрын
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 3 жыл бұрын
And the access point server socket shouldn't be bound to an address: sock.bind('',80)
@ClaytonDarwin
@ClaytonDarwin 3 жыл бұрын
Here is a tutorial (not mine): randomnerdtutorials.com/micropython-esp32-esp8266-access-point-ap/
@americocherubini1489
@americocherubini1489 3 жыл бұрын
@@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 3 жыл бұрын
@@ClaytonDarwin Omg cant believe it's actually working. Thank you so much!😀
@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!"
@ClaytonDarwin
@ClaytonDarwin 4 жыл бұрын
Some call me... Tim!
@user-gz4qb2sd6w
@user-gz4qb2sd6w 3 жыл бұрын
Why not to use UDP to transfer data ?
@ClaytonDarwin
@ClaytonDarwin 3 жыл бұрын
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.
@user-gz4qb2sd6w
@user-gz4qb2sd6w 3 жыл бұрын
@@ClaytonDarwin OK,got it
@user-gz4qb2sd6w
@user-gz4qb2sd6w 3 жыл бұрын
@@ClaytonDarwin one more thing, how about OTA function for micropython ?
@ClaytonDarwin
@ClaytonDarwin 3 жыл бұрын
Not for the core OS. You can update application scripts.
Using MicroPython in the wild
31:55
PyCon AU
Рет қаралды 35 М.
MicroPython #5 - JSON & Network Modules + Practical Example
19:15
Unexpected Maker
Рет қаралды 29 М.
НРАВИТСЯ ЭТОТ ФОРМАТ??
00:37
МЯТНАЯ ФАНТА
Рет қаралды 3,7 МЛН
Пранк пошел не по плану…🥲
00:59
Саша Квашеная
Рет қаралды 5 МЛН
Despicable Me Fart Blaster
00:51
_vector_
Рет қаралды 25 МЛН
Now THIS is entertainment! 🤣
00:59
America's Got Talent
Рет қаралды 39 МЛН
ESP32 Web Server - Async Micropython Tutorial
34:06
Bhavesh Kakwani
Рет қаралды 12 М.
ESP32 LoBo MicroPython WebSocket Server with ReactJS & MST
24:32
015 - ESP32 MicroPython: Web Server | Station Mode | Sockets
16:51
TechToTinker
Рет қаралды 26 М.
The NGINX Crash Course
50:53
Laith Academy
Рет қаралды 479 М.
Writing fast and efficient MicroPython
31:42
PyCon AU
Рет қаралды 67 М.
Learn MicroPython #1 - Introduction & Installation
19:59
Invent Box Tutorials
Рет қаралды 68 М.
ESP32 MicroPython OLED Tutorial with ADC & FTP
18:05
rdagger68
Рет қаралды 25 М.
ESP32 MicroPython Web Server
19:28
rdagger68
Рет қаралды 72 М.
Python Socket Programming Tutorial
49:43
Tech With Tim
Рет қаралды 1 МЛН
НРАВИТСЯ ЭТОТ ФОРМАТ??
00:37
МЯТНАЯ ФАНТА
Рет қаралды 3,7 МЛН