|
|
# Self-Learning: Make the ESP32 an IoT Device
|
|
|
|
|
|
## Goal
|
|
|
|
|
|
> The goal of this section is to send data cyclically (every 1 second) from the ESP32 to a public MQTT broker. Additionally, we aim to subscribe to the sent data packet from your PC and visualize it.
|
|
|
|
|
|
## Establishing WiFi Connection with the ESP32
|
|
|
|
|
|
> There are numerous libraries available that help quickly establish a connection to your router. To develop a consistent solution during the workshop, we will use a specific library. The ESP32 has a built-in WiFi antenna. Using the WiFi.h library, a WiFi connection can be established in a few steps.
|
|
|
|
|
|
### Define your WiFi Network
|
|
|
|
|
|
```cpp
|
|
|
#include <WiFi.h>
|
|
|
|
|
|
const char *SSID = "BaristaBandwidth"; // This is the name of Your Router
|
|
|
const char *PWD = "oneEspressoPLEASE"; // This is the password of Your WiFi-Network
|
|
|
|
|
|
TimeHandle_t wifiReconnectTimer; // Never mind!
|
|
|
|
|
|
// The SSID refers to the name of the WiFi network you want to connect your ESP32 to.
|
|
|
// PWD is the password for the WiFi network.
|
|
|
```
|
|
|
|
|
|
```cpp
|
|
|
💡 ❗ By convention, CONSTANTS are written in uppercase letters.
|
|
|
```
|
|
|
|
|
|
### Connection InitWiFi
|
|
|
|
|
|
> To keep the code more organized, a function initWiFi() is defined:
|
|
|
|
|
|
```
|
|
|
void initWiFi() {
|
|
|
WiFi.mode(WIFI_STA);
|
|
|
WiFi.begin(SSID, PWD);
|
|
|
Serial.print("Connecting to WiFi ..");
|
|
|
while (WiFi.status() != WL_CONNECTED) {
|
|
|
Serial.print('.');
|
|
|
delay(1000);
|
|
|
}
|
|
|
Serial.println(WiFi.localIP());
|
|
|
}
|
|
|
```
|
|
|
|
|
|
> Include this function in your code to connect your ESP with the WiFi. This function must be placed outside and above the `setup()` function.
|
|
|
|
|
|
// Setup WiFi To own Network // Send Data from ESP32 over MQTT to PC with Node-red // Wokwi
|
|
|
|
|
|
# Self-Learning Make the ESP32 an IoT-Device
|
... | ... | @@ -400,3 +447,39 @@ Node-Red can help you ensure that the data is being sent correctly and received |
|
|
Make sure to explore Node-Red and other available tools to enhance your understanding and capability in handling MQTT communications effectively.
|
|
|
|
|
|
Node-Red
|
|
|
|
|
|
After the installation of Node-red we´re going to start the programm via the Commandline.
|
|
|
|
|
|
To Do that search for cmd on your pc and start the terminal.
|
|
|
|
|
|
Just enter node-red and hit enter.
|
|
|
|
|
|
After that node-red is running on your pc.
|
|
|
|
|
|
Now go to your browser enter [localhost:1880](http://localhost:1880) and hit enter.
|
|
|
|
|
|
Now your ready to Evaluate your ESP32 DSataCommunication.
|
|
|
|
|
|
On the left side you should see the Dropdownmenu network. Inside of it the should be an mqtt in Block.
|
|
|
|
|
|
Drag and drop it on your emtpy flowpanel.
|
|
|
|
|
|
Now we gonna configure the broker and topic we want to subscribe to.
|
|
|
|
|
|
Server: test.mosquitto.org Port: 1883 Protocoll MQTT V3.1.1
|
|
|
|
|
|
Now add a debug-Node und Connect the to blocks.
|
|
|
|
|
|
After that you can deploy your flow and check the Communication.
|
|
|
|
|
|
We now build an esp32 DataSource for getting data to the cloud. This should be a basic implementation we can use in our pratical Session. If you have not a single glue what happend in manner of systemarchitecture und embedded System programming. Use our tutorial parse it chatgpt and request a detailed explanation. In our Experience in the last couple of years this can really help unterstanding this kind of Projects without any previous knowledge.
|
|
|
|
|
|
We are now a point you should got deep enough into out IoT-World to handle low-Cost Data Aquisitoin.
|
|
|
|
|
|
Everything else will be done in the practical session. Nevertheless at the end of the virtual course we gonna provide you the Task for out summerschool. Of Course you can explore additoinal neccessary programing on your own if you dont feel comforable.
|
|
|
|
|
|
Practise in Programming is always the key. Maybe you wanna add some ledstrips or displays or button to your now developed simulation.
|
|
|
|
|
|
Another Part is the DeepLearning Topic.
|
|
|
|
|
|
Link DeepLearning |
|
|
\ No newline at end of file |