W6300-EVB-Pico2 connected to ThingsBoard through MQTT
W6300-EVB-Pico2 Connected to ThingsBoard via MQTT

Wiznet - W6300-EVB-Pico2
x 1
This project tutorial demonstrates how to connect the W6300-EVB-Pico2 Ethernet development board with a DHT22 temperature and humidity sensor, and send real-time sensor data to ThingsBoard using the MQTT protocol. The W6300-EVB-Pico2, which combines the WIZnet W6300 Ethernet controller and Raspberry Pi Pico RP2040, enables reliable and low-latency Ethernet communication. In this tutorial, the DHT22 sensor is interfaced with the Pico2 to periodically read temperature and humidity data. The microcontroller formats the data into JSON and publishes it to the ThingsBoard cloud platform via MQTT. On ThingsBoard, the data is visualized using dynamic dashboards, allowing users to monitor environmental conditions in real time. This project is suitable for anyone interested in building IoT solutions for smart environments, leveraging wired Ethernet stability and the powerful visualization tools provided by ThingsBoard.
This project demonstrates the integration of the W6300-EVB-Pico2 Ethernet development board with the ThingsBoard IoT platform using the MQTT protocol. The W6300-EVB-Pico2, built around the WIZnet W6300 Ethernet controller and Raspberry Pi Pico form factor, serves as a low-cost and reliable solution for wired IoT connectivity.
The system is programmed to:
Collect sensor data (temperature, humidity from DHT22),
Establish an MQTT connection to a ThingsBoard server using static IP or DHCP,
Format data in JSON,
Publish telemetry data at set intervals to ThingsBoard via MQTT.
ThingsBoard provides real-time data visualization through customizable dashboards, allowing users to monitor device performance and sensor trends remotely. This project is ideal for industrial or smart building applications requiring stable Ethernet connectivity, and it highlights how embedded systems with minimal resources can participate in cloud-based IoT ecosystems.
#include <Arduino.h>
#include "Adafruit_Sensor.h"
#include "DHT.h"
#include <SPI.h>
#include <W6300lwIP.h>
#include "PubSubClient.h"
#include "ArduinoJson.h"
// Fill in the hostname of your IoT broker
#define SECRET_BROKER "demo.thingsboard.io"
#define MQTT_PORT 1883
#define TOKEN ""
#define MQTT_USERNAME ""
#define MQTT_PASSWORD ""
// Fill in the publisher and subscriber topic
#define PUBLISH_TOPIC "v1/devices/me/telemetry"
#define SUBSCRIBE_TOPIC "v1/devices/me/rpc/request/+"
void callback(char* topic, byte* payload, unsigned int length);
void reconnect();
void publish_data();
void publish_relay_status(const char* status);
Wiznet6300lwIP eth(1 /*chip select*/);
WiFiClient net;
PubSubClient mqttClient(net);
#define DHTPIN 2
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
long lastData = 0;
void callback(char* topic, byte* payload, unsigned int length)
{
Serial.print("Message received on topic: ");
Serial.println(topic);
Serial.print("Message:");
String message;
for (unsigned int i = 0; i < length; i++){
//Convert *byte to string
message += (char)payload[i];
}
if (String(topic).startsWith("v1/devices/me/rpc/request/"))
{
JsonDocument doc;
DeserializationError error = deserializeJson(doc, message);
if (error)
{
Serial.print("JSON parse failed: ");
Serial.println(error.c_str());
return;
}
const char* status = doc["params"]["status"];
if (strcmp(status, "on") == 0)
{
digitalWrite(14, HIGH); // relay on
publish_relay_status("ON");
}
else if (strcmp(status, "off") == 0)
{
digitalWrite(14, LOW);
publish_relay_status("OFF");
}
}
}
void reconnect()
{
//Try to connect mqtt broker
while (!mqttClient.connected()){
Serial.println("Attempting to connect MQTT");
if (mqttClient.connect(TOKEN, MQTT_USERNAME, MQTT_PASSWORD))
{
Serial.println("Connected to MQTT broker");
//digitalWrite(LED_BUILTIN, HIGH);
mqttClient.subscribe(SUBSCRIBE_TOPIC, 1);
}
else{
//digitalWrite(LED_BUILTIN, LOW);
Serial.print("failed, rc=");
Serial.print(mqttClient.state());
Serial.println("Disconnected to MQTT broker");
delay(5000);
}
}
}
void publish_data(){
JsonDocument doc;
static char data[256];
float t = dht.readTemperature();
float h = dht.readHumidity();
if (isnan(t) || isnan(h))
{
Serial.println("Failed to read sensor");
return;
}
doc["temperature"] = t;
doc["humidity"] = h;
serializeJsonPretty(doc, data);
long now = millis();
if (now - lastData > 15000)
{
lastData = now;
Serial.println(data);
mqttClient.publish(PUBLISH_TOPIC, data);
}
}
// Function to publish relay status
void publish_relay_status(const char* status) {
String payload = "{\"relayStatus\":\"" + String(status) + "\"}";
Serial.print("Publishing relay status: ");
Serial.println(payload);
mqttClient.publish(PUBLISH_TOPIC, payload.c_str()); // Publish relay status telemetry
}
void setup() {
// Set up SPI pinout to match your HW
SPI.setRX(0);
SPI.setCS(1);
SPI.setSCK(2);
SPI.setTX(3);
dht.begin();
Serial.begin(115200);
delay(5000);
Serial.println();
Serial.println();
Serial.println("Starting Ethernet port");
//Start the Ethernet port
if (!eth.begin())
{
Serial.println("No wired Ethernet hardware detected. Check pinouts, wiring.");
while (1)
{
delay(1000);
}
}
while (!eth.connected()) {
Serial.print(".");
delay(500);
}
Serial.println("");
Serial.println("Ethernet connected");
Serial.println("IP address: ");
Serial.println(eth.localIP());
mqttClient.setServer(SECRET_BROKER, MQTT_PORT);
mqttClient.setCallback(callback);
}
void loop() {
if (!mqttClient.connected())
{
reconnect();
}
mqttClient.loop();
publish_data();
}
-
Arduino W6300-EVB-Pico2 MQTT