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.

Official Library

Tested with ESP32 + DHT11 against Devspace production.

Manual MQTT

Use any MQTT client if your board is not covered by the official library. Follow the MQTT topic and payload contract below.

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
Note: if you install Devspace from a GitHub ZIP, Arduino IDE may not install dependencies automatically. Install the libraries above manually.

3Create Device And Sensors

  1. Login to the Devspace client dashboard.
  2. Create a new device.
  3. Save the generated MQTT Client ID, MQTT Username, and MQTT Password.
  4. Add a temperature sensor and save its Sensor ID.
  5. Add a humidity sensor and save its Sensor ID.
Important: the MQTT Client ID in your firmware must exactly match the dashboard value. Random or autogenerated client IDs are rejected.

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:

DHT11ESP32
VCC3.3V
GNDGND
DATAGPIO 4

Update the configuration values in the example:

ESP32_DHT11.ino
1const char* WIFI_SSID = "your-wifi-ssid";
2const char* WIFI_PASSWORD = "your-wifi-password";
3
4const char* MQTT_BROKER = "mqtt.devspace.id";
5const uint16_t MQTT_PORT = 1883;
6
7const char* MQTT_CLIENT_ID = "devspace_your_client_id";
8const char* MQTT_USERNAME = "mqtt_your_username";
9const char* MQTT_PASSWORD = "your_mqtt_password";
10
11const char* TEMPERATURE_SENSOR_ID = "temperature_sensor_uuid";
12const char* HUMIDITY_SENSOR_ID = "humidity_sensor_uuid";
13
14const 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

  1. Select the correct board and USB port in Arduino IDE.
  2. Upload the sketch.
  3. Open Serial Monitor at 115200 baud.
  4. Confirm WiFi and MQTT connect successfully.
  5. Open the Devspace dashboard and check latest readings.
serial-monitor.txt
1[Devspace] WiFi connected.
2[Devspace] MQTT connected.
3[Devspace] Published status: online
4[Devspace] Sent data: {"sensorId":"...","value":25.5}

MQTT Reference

The official library builds topics automatically. For manual clients, follow this contract.

TopicDirectionDescription
devspace/{mqttClientId}/dataDevice to ServerPublish sensor data
devspace/{mqttClientId}/statusDevice to ServerOnline or offline status
payload.json
1{
2 "sensorId": "sensor-uuid-from-dashboard",
3 "value": 25.5
4}

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.

Need More Help?

Contact us if you need help connecting a new board or sensor to Devspace.