The frequent disconnects could be due to the fact that 2 MQTT clients are fighting over the same client ID,i.e, you're unknowingly performing clientId stealing.
You should probably start with the NodeRed console on the raspberry and check what logs do say about the disconnections
You can go to device connection logs in the device drill down panel to get a confirmation on this. You might see something in the lines of "The client ID was reused".