Windows10环境下未注册设备MQTT上报至ThingsBoard网关报错求助
Alright, let's break down what's going wrong here and get your ThingsBoard setup working smoothly.
First, fix the ThingsBoard server's "Invalid message received" error
The root cause here is the MQTT topic you're using. The default JsonMqttAdaptor in ThingsBoard expects telemetry data to be sent to a specific topic format—v1/devices/me/telemetry. When you publish to your custom sensors topic, the server can't parse the message structure it expects, hence the "invalid message" log entries.
Update your Mosquitto publish command to use the correct topic:
mosquitto_pub -h localhost -p 1883 -u "XXXXXXXX" -t "v1/devices/me/telemetry" -m '{"serialNumber":"TB-GW-SN-001","model":"TB-GW-T1000","temperature":35.2}'
(Note: The XXXXXXXX username should be the access token of an active device you've created in ThingsBoard—double-check this token matches what's in your device profile.)
Next, resolve the gateway's connection failure
Your gateway is trying to connect to the server's MQTT port with anonymous credentials, but your server clearly requires authentication (you're using -u "XXXXXXXX" in your Mosquitto command). The server rejects the anonymous connection attempt, leading to the Connection lost and EOFException errors in the gateway logs.
Modify your mqtt-config.json to use the same authentication as your publish command:
"brokers": [ { "host": "localhost", "port": 1883, "ssl": false, "retryInterval": 3000, "credentials": { "type": "basic", "username": "XXXXXXXX", "password": "" // Leave empty if you're only using the access token as the username } } ]
Restart the ThingsBoard gateway after making this change, and the connection errors should disappear.
A quick sanity check on your setup
Wait—do you actually need the gateway for your use case? If you're directly sending device data to the ThingsBoard server via MQTT (like your Mosquitto command does), the gateway isn't necessary. The gateway is designed to bridge external MQTT brokers (or other protocols) to ThingsBoard. If you do need the gateway, consider adjusting your setup:
- Run a separate MQTT broker (e.g., another Mosquitto instance) on a different port (like 1884)
- Configure the gateway to connect to this 1884 broker
- Publish your Mosquitto messages to port 1884, and let the gateway forward them to ThingsBoard
This avoids conflicts between direct device connections and gateway connections to the server's MQTT port.
Final verification steps
- Run
netstat -ano | findstr :1883in Command Prompt to confirm only the ThingsBoard server is using port 1883 - Ensure the device linked to your
XXXXXXXXaccess token is active in the ThingsBoard UI - Restart both the server and gateway after any configuration changes
内容的提问来源于stack exchange,提问作者MaMuDragon

