Connect Hardware To Devspace
Use the official Devspace Arduino library to connect your board, publish MQTT sensor data, and monitor readings in the dashboard.
1Getting Started
The recommended path is the official devspace-arduino library. It handles WiFi, MQTT credentials, Devspace topics, status messages, Last Will, and sensor data payloads.
2Install Tools And Libraries
Install the Arduino board package that matches your hardware. For the current ESP32_DHT11 example, install esp32 by Espressif Systems from Arduino IDE Boards Manager.
Install these libraries from Arduino IDE Library Manager before compiling the examples:
- PubSubClientby Nick O'Leary
- ArduinoJson by Benoit Blanchon
- DHT sensor library by Adafruit
- Adafruit Unified Sensor
3Create Device And Sensors
- Login to the Devspace client dashboard.
- Create a new device.
- Save the generated
MQTT Client ID,MQTT Username, andMQTT Password. - Add a temperature sensor and save its
Sensor ID. - Add a humidity sensor and save its
Sensor ID.
4ESP32 + DHT11 Example
Install the Devspace library from GitHub ZIP, restart Arduino IDE if needed, then open File -> Examples -> Devspace -> ESP32_DHT11.
Default wiring for the example:
| DHT11 | ESP32 |
|---|---|
| VCC | 3.3V |
| GND | GND |
| DATA | GPIO 4 |
Update the configuration values in the example:
1const char* WIFI_SSID = "your-wifi-ssid";2const char* WIFI_PASSWORD = "your-wifi-password";34const char* MQTT_BROKER = "mqtt.devspace.id";5const uint16_t MQTT_PORT = 1883;67const char* MQTT_CLIENT_ID = "devspace_your_client_id";8const char* MQTT_USERNAME = "mqtt_your_username";9const char* MQTT_PASSWORD = "your_mqtt_password";1011const char* TEMPERATURE_SENSOR_ID = "temperature_sensor_uuid";12const char* HUMIDITY_SENSOR_ID = "humidity_sensor_uuid";1314const uint8_t DHT_PIN = 4;
For local Devspace, replace MQTT_BROKER with your laptop or server LAN IP. Do not use localhost in board firmware.
5Upload And Verify
- Select the correct board and USB port in Arduino IDE.
- Upload the sketch.
- Open Serial Monitor at 115200 baud.
- Confirm WiFi and MQTT connect successfully.
- Open the Devspace dashboard and check latest readings.
1[Devspace] WiFi connected.2[Devspace] MQTT connected.3[Devspace] Published status: online4[Devspace] Sent data: {"sensorId":"...","value":25.5}
MQTT Reference
The official library builds topics automatically. For manual clients, follow this contract.
| Topic | Direction | Description |
|---|---|---|
| devspace/{mqttClientId}/data | Device to Server | Publish sensor data |
| devspace/{mqttClientId}/status | Device to Server | Online or offline status |
1{2 "sensorId": "sensor-uuid-from-dashboard",3 "value": 25.54}
Troubleshooting
MQTT connect fails
- Check MQTT host and port.
- Use the exact dashboard MQTT Client ID.
- Check MQTT username and password.
- For local Devspace, use your laptop or server LAN IP.
Device online but no data
- Check that each Sensor ID belongs to this device.
- Check DHT11 wiring and the configured data pin.
- Make sure sensor data is not published as retained.