Refactored setting credentials for mqtt.