This project contains ESP32 examples for connecting to Wi-Fi and NETPIE over MQTT.
The repository was reorganized from older .txt examples into cleaner source files that are easier to read, modify, and upload.
esp32_connect_netpie.inoBasic ESP32 example for connecting to Wi-Fi and NETPIE and subscribing to an MQTT topicsend_dht_to_netpie.inoESP32 example that readsDHT22data and publishes temperature and humidity to NETPIE as JSONesp32_connect_netpie.txtArchived plain-text version of the basic connection examplesend_dht_to_netpie.txtArchived plain-text version of the DHT publishing example
ESP32board- Arduino IDE or PlatformIO
- Libraries:
WiFi(included with the ESP32 core)PubSubClientDHT sensor library
Update these values in the .ino files before uploading:
const char* WIFI_SSID = "YOUR_WIFI_SSID";
const char* WIFI_PASSWORD = "YOUR_WIFI_PASSWORD";
const char* MQTT_CLIENT_ID = "YOUR_CLIENT_ID";
const char* MQTT_USERNAME = "YOUR_TOKEN";
const char* MQTT_PASSWORD = "YOUR_SECRET";Also verify these settings:
MQTT_BROKERis usuallybroker.netpie.ioMQTT_PORTis usually1883MQTT_TOPICorMQTT_SUB_TOPICshould match your use case
send_dht_to_netpie.ino publishes data in this format:
{
"temperature": 28.50,
"humidity": 64.20
}- Install the
ESP32board package in Arduino IDE. - Install the
PubSubClientlibrary. - Install the
DHT sensor library. - Open the example file you want to use.
- Replace the Wi-Fi, Client ID, Token, Secret, and topic values.
- Select the correct board and serial port.
- Upload the sketch to your ESP32.
- Open Serial Monitor at
115200 baud.
- Converted plain text examples into ready-to-use source files
- Used clearer constant names and function structure
- Separated Wi-Fi and MQTT connection logic
- Added reconnect handling for lost Wi-Fi or MQTT connections
- Added
mqttClient.loop()to keep MQTT communication alive - Replaced simple
delay()-based publishing with amillis()timer
These examples use Arduino and ESP32 libraries and classes, which are C++-based rather than plain C.
Because of that, .ino or .cpp is a better fit than .c.