This is a demo ESP32 application which takes temperature and humidity readings and broadcasts them live to clients using the WebSocket protocol.
The application also acts as a webserver, serving a frontend Svelte application, which provides a basic interface for viewing the temperature and humidity readings sent from the server, as well as controls to change the rate at which the server broadcasts updates.
Open the project using the PlatformIO VSCode Extension.
In the frontend directory:
- Install dependencies:
npm install
- Build the frontend application:
This will copy over the build artifacts to the
npm run build
backend/datadirectory, ready for upload to your ESP32.
In the backend directory:
-
Create a
secrets.hfile inside theincludedirectory and paste the following, substituting your WIFI SSID and password:#define WIFI_SSID <Your WIFI SSID> #define WIFI_PASSWORD <Your WIFI password>
In the PlatformIO Extension:
-
Click
Upload Filesystem Imageto upload the front-end code (Svelte app) to your ESP32's filesystem. -
Click
Upload and Monitorto upload the backend code to your ESP32, and start the application. -
Your ESP32 will start the application which will:
- Connect to your WIFI network using the credentials you supplied in the
secrets.hfile - Print its local IP address to the terminal
- Serve the front-end application at that IP address
- Allow a WebSocket connection from the front-end application.
Go to the local IP address in your web browser to start the front-end application.
- Connect to your WIFI network using the credentials you supplied in the