Control ESP32 from ANYWHERE in the World - Step-By-Step Tutorial

แชร์
ฝัง
  • เผยแพร่เมื่อ 5 พ.ค. 2024
  • Learn how to control ESP32 GPIO pins in real-time with AWS API Gateway WebSockets. I will show you step-by-step how to create and build:
    - PlatformIO project with ESP32 WebSocket Client (C/C++)
    - Serverless Framework project utilizing AWS API Gateway WebSockets, AWS Lambda, and AWS DynamoDB to handle the communication between clients (TypeScript)
    - Web Application to control ESP32 from the browser (ReactJS)
    👍 Subscribe for more IoT and programming tutorials like this: / @tomasztarnowski4434
    Link to the code:
    ESP32 Project - github.com/ttarnowski/esp32-w...
    WebSocket Server Code - github.com/ttarnowski/esp32-w...
    ESP32 Control Panel (React) - github.com/ttarnowski/esp32-c...
    Serverless, AWS, TypeScript v2 template project - github.com/ttarnowski/serverl...
    React, TypeScript, TailwindCSS, Vite template project - github.com/ttarnowski/vite-re...
    How to get started with Serverless Framework:
    • Getting started with A...
    How to connect ESP32 to WiFi:
    • Connect ESP32 to WiFi ...
    How to build Web Chat with Serverless Framework and AWS API Gateway Websockets:
    • How to Build a Realtim...
    ESP32 Datasheet Specification: www.espressif.com/sites/defau...
    NodeMCU 32S Development Board Specification:
    circuits4you.com/2018/12/31/e...
    Parts and components used in this video (affiliate links):
    - NodeMCU-32S Development Board:
    eBay UK - ebay.us/fpZEVO
    eBay USA - ebay.us/7TqjQu
    eBay DE - ebay.us/SUf9t1
    AliExpress - s.click.aliexpress.com/e/_Dc9...
    - USB Type-C to Micro USB cable (tested and working):
    eBay UK - ebay.us/7z9AF6
    eBay USA - ebay.us/cwrWGo
    eBay DE - ebay.us/ixcU7P
    AliExpress - s.click.aliexpress.com/e/_Dm6...
    - LED Diode:
    eBay UK - ebay.us/8y6xEz
    eBay USA - ebay.us/38nwTv
    eBay DE - ebay.us/UQNXy5
    AliExpress - s.click.aliexpress.com/e/_DBE...
    - Resistor equal to or greater than 75Ω:
    eBay UK - ebay.us/a3nJTv
    eBay USA - ebay.us/4fSgND
    eBay DE - ebay.us/uael4z
    AliExpress - s.click.aliexpress.com/e/_Ddu...
    - Breadboard:
    eBay UK - ebay.us/Mcsgpn
    eBay USA - ebay.us/9Xr8uH
    eBay DE - ebay.us/lQJ4XI
    AliExpress - s.click.aliexpress.com/e/_Dlf...
    - Wires:
    eBay UK - ebay.us/jqCLLG
    eBay USA - ebay.us/7p2Bjj
    eBay DE - ebay.us/7MZ3Dc
    AliExpress - s.click.aliexpress.com/e/_Dms...
    Software used in the video:
    Visual Studio Code IDE: code.visualstudio.com/
    PlatformIO Extension: platformio.org/platformio-ide
    Clang-Format Extensions (Code Formatter): marketplace.visualstudio.com/...
    Social Media:
    Twitter: / t_tarnowski​
    Linkedin: / tomasz-ta...​
    GitHub: github.com/ttarnowski​
    Thank you for watching and see you soon!
    00:00 Intro
    00:11 What I'm going to build
    00:53 Hardware presentation
    01:10 ESP32 Project - Creating Project with PlatformIO
    02:11 ESP32 Project - Using ESP32 WiFi Connect Template
    03:49 ESP32 Project - Adding WebSocket Client to the Code
    07:55 ESP32 Project - Listening to WebSocket Client Events
    09:29 ESP32 Project - Handling WebSocket Events
    13:49 ESP32 Project - How to Validate and Parse WebSocket Message Event
    27:49 ESP32 Project - Handle Pin Mode Command
    33:20 ESP32 Project - Handle Digital Read&Write Commands
    36:14 ESP32 Project - Additional Error Handling
    37:38 ESP32 Project - Acknowledgement Message
    39:39 AWS WebSocket Server - Creating the Project
    41:57 AWS WebSocket Server - Infrastructure Configuration
    46:30 AWS WebSocket Server - Implementing WebSocket Handler with TypeScript
    51:15 AWS WebSocket Server - Client Connect Implementation
    53:36 AWS WebSocket Server - Client Disconnect Implementation
    55:40 AWS WebSocket Server - Pass the Message Implementation
    01:08:04 AWS WebSocket Server - Walk-through the code
    01:11:13 AWS WebSocket Server - Deployment to AWS
    01:11:37 ESP32 Project - Updating the Code with URL to WebSocket Server
    01:12:28 ESP32 Project - Deploying the Code to ESP32
    01:13:29 ReactJS Control Panel - Creating the Project
    01:16:23 ReactJS Control Panel - Importing WebSocket Client Hook
    01:18:09 ReactJS Control Panel - Building UI
    01:23:16 ReactJS Control Panel - Behaviour Implementation
    01:26:41 ReactJS Control Panel - Sending a Digital Write Message to the WebSocket Server
    01:29:00 ReactJS Control Panel - Pin Mode and Digital Read Behaviour
    01:41:11 Hardware - Wiring up the LED Diode
    01:42:16 Testing the Project Locally
    01:44:02 ReactJS Control Panel - Deployment to AWS S3
    01:47:50 Testing Newly Deployed Website
    01:48:35 The End
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 72

  • @user-gb3nn9li9w
    @user-gb3nn9li9w ปีที่แล้ว +1

    thank you so much I spend whole 24 hours to get it to work and it works you saved my life man good luck

  • @paulomarques742
    @paulomarques742 ปีที่แล้ว +3

    I'm very very glad that I managed to find your video. This will be of great help to my current project. Awesome work Tomasz, keep it up!

  • @hamidtb2740
    @hamidtb2740 ปีที่แล้ว +2

    I just started to see this video
    and can say PERFECT, PERFECT, PERFECT
    wish best for you and good luck 🍀

  • @ibzih
    @ibzih ปีที่แล้ว +2

    Very nice websocket tutorial, love your video quality!

  • @sametturhan5236
    @sametturhan5236 2 วันที่ผ่านมา

    Thank you so much. Very educated and professional coding. Could you also provide a documentation for controlling multiple ESP32s?

  • @Dragons927
    @Dragons927 4 หลายเดือนก่อน

    Браво братле!

  • @benjaminhobbs2923
    @benjaminhobbs2923 8 หลายเดือนก่อน

    amazing, thank you

  • @SarmadSohaib22
    @SarmadSohaib22 11 หลายเดือนก่อน +1

    Nice video. Just want to know if there is any limit on the max number of esp32 (at various locations) that we can connect using your explained method?

  • @TVmousa
    @TVmousa 2 หลายเดือนก่อน

    You are such an Angel thanks

  • @Remo2239
    @Remo2239 10 หลายเดือนก่อน

    Love it :) more sucg tutorials please :)

  • @jocimarsilva9425
    @jocimarsilva9425 7 หลายเดือนก่อน +1

    Novamente parabéns, conteúdo excelente, obrigado

  • @buffplums
    @buffplums 23 วันที่ผ่านมา

    Thank you for this it’s great thank you

  • @jocimarsilva9425
    @jocimarsilva9425 7 หลายเดือนก่อน

    Parabéns excelente vídeo

  • @node_python_lover454
    @node_python_lover454 ปีที่แล้ว +1

    Awesome tutorial! Thanks alot

  • @ezequielbarrera3306
    @ezequielbarrera3306 4 หลายเดือนก่อน +2

    Hello Tomasz! One question. When you started the project you selected "NodeMCU-32" board. The setup and the code Is the same if I use another ESP32 like ESP32 from espressif? I have a ESP32 devkit-v1
    Thanks, great video!

  • @noweare1
    @noweare1 7 หลายเดือนก่อน

    Real good video, thanks. I think you lost a lot of people on the json part. It can be confusing if people do not know json format. Maybe do a video on json format and sending back and forth between client and host

  • @hplownik
    @hplownik ปีที่แล้ว +1

    Stary, ratujesz mi życie, teraz jestem biedny, ale po wypłacie aż wynagrodzę Ci to jakimś szeklem, tylko prosze dalej rób to co robisz :D

  • @mr-strange-0w0
    @mr-strange-0w0 ปีที่แล้ว +1

    Great Video And Good Explaination 😁😁

  • @imjusttryingtobesafelol5909
    @imjusttryingtobesafelol5909 9 หลายเดือนก่อน +1

    Hey, Why didnt you use AsyncWebServer or AsyncWebServerSocket? are there separate use cases for async one?

  • @hassan19982008
    @hassan19982008 8 หลายเดือนก่อน

    Hi Tomasz,
    Thanks for your video and it very interest project .I was programing the three project and I had core problem the three program it the same project but the esp project I modify the program for esp8266 .
    But the api gateway websokets server not connect .
    The Wi-Fi connect is done already
    On the esp8266 on monitor the massage show : WS disconnect

  • @bartekbartoszewski1993
    @bartekbartoszewski1993 4 หลายเดือนก่อน

    Dziękuje ci, pomogłeś mi ogarnąć sterowanie robota przez telefon na olimpiadę z mechatroniki.

  • @tictecha2981
    @tictecha2981 ปีที่แล้ว

    Hi Tomasz,
    hope you're well.
    I am facing some issues when it comes to creating a path for the serverless AWS template. 00:41:00

  • @eransimoni2249
    @eransimoni2249 ปีที่แล้ว +1

    Hi Tomasz , thanks a lot for your great video, I learned a lot from you
    - do you have a tutorial how to make LittelFS run on ESP32 step by step (not ESP8266) from PlatformIO, I don't see any video for it on the network

    • @tomasztarnowski4434
      @tomasztarnowski4434  ปีที่แล้ว

      Hey Eran, I don't have yet but I've managed to configure LittleFS with ESP32 and I will make a video about it soon.

  • @tatekolton5717
    @tatekolton5717 7 หลายเดือนก่อน +1

    Hello! Do you have the exact version of the .yml file for serverless on github? I am getting the error: "Cannot resolve variable at "resources.Resources.ClientsTable.Properties.TableName": Value not found at "self" source" when I use yard deploy and I think my code is the same as yours

  • @edinetgrunhed6000
    @edinetgrunhed6000 17 วันที่ผ่านมา

    thanks for uploading this video, can you make update for this video using azure

  • @tareshgupta1095
    @tareshgupta1095 2 หลายเดือนก่อน

    hey ,can we establish a websockets connection using only soft AP on a esp32 without internet ?

  • @jgunthner
    @jgunthner 6 หลายเดือนก่อน

    Hi, I need to make this with ESP-IDF. Could you show this implementation, or just code?

  • @artigeniusStore
    @artigeniusStore 3 หลายเดือนก่อน

    very helpful video. thanks you

  • @EdwinMartin
    @EdwinMartin ปีที่แล้ว +2

    Nice walkthrough and explanation. Why don’t you have more subscribers and views? Is it too complex for most viewers? Is it too involved? Don’t you match what people are searching for?

    • @tomasztarnowski4434
      @tomasztarnowski4434  ปีที่แล้ว +1

      Thank you, Edwin. I think the channel is still too young as it's only been 16 months since I've started uploading videos. I hope the algorithms pick it up soon :)

  • @AjirogheneSunny
    @AjirogheneSunny 3 หลายเดือนก่อน +3

    As of today 16th January 2024, this code is no longer working. I have spent all day trying to make it work but no response. I went ahead to copy your code base, but still won't work. I think something has broken with the aws serverless

    • @linux1221
      @linux1221 5 วันที่ผ่านมา

      Do you have any other solution? Need some help

  • @Adityasingh-sq7gd
    @Adityasingh-sq7gd ปีที่แล้ว +1

    Hi Tomasz, I'm fairly new to this IOT stuff, i've one query, is all these web server using AWS, websocket free or we need to purchase some stuff? You didn't mention anything so it seems this all is free and we just need to purchase esp 32, led , resistor & breadboard.
    In addition to above, if I wish to create cool IOT interfaces controlling stuff online, I need to learn JavaScript, aws & Esp 32 languages with their several libraries etc, is that right, or something else is required?

    • @jamesgardner1647
      @jamesgardner1647 2 หลายเดือนก่อน

      You have to establish an AWS account. It has a small number of free connections per month but as volume goes up so does cost.

  • @zdzislawtycner539
    @zdzislawtycner539 ปีที่แล้ว +1

    Panie Tomaszu, panski project "Control ESP32 from Anywhere in the world" zwrocil moja uwage w zwiazku z tym ze tej zimy padly moje lithium battery zasilane przez solar panels i calkowicie stracilem mozliwosc wgladu na moja polane kilkaset kilometrow od domu. Postanowilem wiec kupic generator ktory moze byc odpalany przez remote control a to daje mozliwosc zainstalowania w nim ESP32 bo start jest automatyczny i choke jest automatyczny ....calosc zasilana z bateri 12v. Nie jestem z zawodu programista, kiedys naprawialem telewizory a arduino traktuje jako hobby . Moze to bylby jakis pomysl na przyszly projekt...dziekuje

    • @tomasztarnowski4434
      @tomasztarnowski4434  ปีที่แล้ว

      Witam, pomysl jak najbardziej ciekawy, dziekuje za zainteresowanie kanalem :)

  • @dienau6313
    @dienau6313 10 หลายเดือนก่อน

    Hi, I have a question about at 41:07, I do not use macbook, I use code in window 11 so where should I paste the template in vscode?, I also download git for windows, but still dont know how to paste it, since it says --template-url not command found

    • @jagdish9533
      @jagdish9533 18 วันที่ผ่านมา

      Same problem...... I didn't understand..... Hay if you solved it can you please tell me....

    • @reychristianmvillarin2296
      @reychristianmvillarin2296 13 วันที่ผ่านมา

      ​@@jagdish9533
      for windows
      npm install -g serverless
      npx serverless create --template-url github.com/ttarnowski/serverless-aws-nodejs-typescript-v2/tree/main --path websocket-server-api-gw

  • @hussinaljome5858
    @hussinaljome5858 ปีที่แล้ว +1

    Hi sir, I don't really have experience in Arduino, but can I apply what you explained in this video by using esp8266?

    • @tomasztarnowski4434
      @tomasztarnowski4434  ปีที่แล้ว

      Hi HUSSIN, yeah I think connecting to WiFi and using WebSocket client should be almost identical on ESP8266. You can also check my old videos about ESP8266 they might come useful to you.

  • @yojithkr17
    @yojithkr17 ปีที่แล้ว +1

    40:56
    Sir how to get that VS Code terminal in windows?
    Pls help

    • @tomasztarnowski4434
      @tomasztarnowski4434  ปีที่แล้ว

      hello,
      try either gitforwindows.org/ or ubuntu subsystem on windows: ubuntu.com/wsl

  • @dixit_sir
    @dixit_sir 6 วันที่ผ่านมา

    sir WS disconnected is poping again and again

  • @hamidtb2740
    @hamidtb2740 ปีที่แล้ว +1

    any alternative for aws?
    can use normal server?

    • @tomasztarnowski4434
      @tomasztarnowski4434  ปีที่แล้ว +2

      yeah, you can use a simple websocket server hosted somewhere on the internet to achieve the same results. BTW I'm working on something to simplify it so AWS won't be required :)

    • @hamidtb2740
      @hamidtb2740 ปีที่แล้ว +2

      @@tomasztarnowski4434 thanks alot
      I'm waiting for it...

  • @csigabigaboca1987
    @csigabigaboca1987 11 หลายเดือนก่อน

    How do I know my current home IP address? Without it I can't access my home network from anywhere...

  • @AaronAu-un3vi
    @AaronAu-un3vi ปีที่แล้ว +1

    I keep getting this error and not sure how to handle it:
    [128400][E][WiFiClient.cpp:313] setSocketOption(): fail on -1, errno: 9, "Bad file number"
    WS Disconnected

    • @tomasztarnowski4434
      @tomasztarnowski4434  ปีที่แล้ว

      Hi Aaron,
      this error: [128400][E][WiFiClient.cpp:313] setSocketOption(): fail on -1, errno: 9, "Bad file number"
      is most likely unrelated to "WS Disconnected"
      is your board connected to WiFi?

    • @AaronAu-un3vi
      @AaronAu-un3vi ปีที่แล้ว +1

      @@tomasztarnowski4434 Yes it is connected to wifi

    • @tomasztarnowski4434
      @tomasztarnowski4434  ปีที่แล้ว

      Hi Aaron,
      try to compile the project with the debug flags:
      in you platformio.ini file add:
      build_flags =
      -D DEBUG_WEBSOCKETS
      -D DEBUG_ESP_PORT=Serial
      and check what serial monitor returns

  • @user-iz2bv9zb4l
    @user-iz2bv9zb4l ปีที่แล้ว

    where's the code of serverless.yml?

  • @epictetus__
    @epictetus__ ปีที่แล้ว

    bookmark: 23:00

  • @azizismail1594
    @azizismail1594 ปีที่แล้ว +1

    Oh man, u are to late, i need this knowledge 3month ago

    • @tomasztarnowski4434
      @tomasztarnowski4434  ปีที่แล้ว

      there's more coming
      maybe you'll find something useful :)

  • @carlos.galhano
    @carlos.galhano ปีที่แล้ว +5

    Sorry but for beginners this is complety crazy...😢

    • @HiberNAT
      @HiberNAT 5 หลายเดือนก่อน

      I can tell a full beginners video for me would be a titanic masterclass on the inputs and outputs of the tcp/ip layers of like 20 hours series

    • @HiberNAT
      @HiberNAT 5 หลายเดือนก่อน

      Me, a lazy dude, would have made everything a function used one time 🤣 just for beginners legibility

    • @HiberNAT
      @HiberNAT 5 หลายเดือนก่อน

      Or a full library 😂

    • @carlos.galhano
      @carlos.galhano 5 หลายเดือนก่อน

      I justo do a DHT temperature and humidity being see on an internet Pages acessível to all.

  • @aliaskri982
    @aliaskri982 ปีที่แล้ว +2

    I give up! This is such a disastrous tutorial for a beginnner. It is ridiculously hard to follow with various components that you expect the viewer to know without ever specifying them.
    After sinking about 5 hours in this video, trying to understand what you say and then solving all the errors you haven't mentioned including how you have to setup an AWS account, configure that information with your personal computer and so on.
    At @42:16 , you just paste in code without every explaining where you got it from or how I can get it. Looking over your github repo, that code doesn't match as it contains addtional functions and leads to further several errors.
    I still have multitudes of questions and errors. For example, when I deploy program, I keep getting erros like secret-key is not defined and etc. I would try to solve it but I don't even know where to start. Only by watching your other vidoes can I even begin to complete the puzzle.
    As a self-learner with no knowledge of these concepts, you complete ruined the fun of the video. I have self-taught programming through online tutorials and I have never been left this confused and exhausted.
    Instead of learning something new, I want to cry from frustration sinking so much time into a video while nothing to show for it.
    What's most disappointing is that seeing your earlier video regarding hooking your esp32 to wifi and about platformio, I got so excited, but wasted my limited time on this 2 hour confusion fest.

    • @noweare1
      @noweare1 7 หลายเดือนก่อน

      This was a lot to know. Besides esp32, C and json, you have to know react, javascript and AWS. Thats a lot. One thing at a time then integrate them one by one.

    • @mtgstudios1556
      @mtgstudios1556 หลายเดือนก่อน

      I'm not sure that this video was geared towards beginners because of @noweare1's point
      at least from what I can tell by looking for a solution like this, trying to control the device from anywhere in the world is quite an advanced concept as I can't find a lot of people that have done it from absolutely anywhere. Mostly just on local networks.
      So if you are still into the IoT stuff I recommend starting a bit simpler than this. like trying to make it work with Low Bluetooth Energy.