I'm trying to use an MQTT client to send device telemetry to an IoT Central instance. To do this, I think I need to know the hostname of the underlying IoTHub instance. I have a hostname of the form iotc-{a bunch of letters and numbers}.azure-devices.net, but I can't remember where I got it from or how to generate it again. I get a "connection refused: server unavailable" error when trying to connect to port 8883. I have tried both SAS and x509 certificate authentication, so either I'm getting the authentication wrong with both methods, or I'm getting the hostname wrong. Does anyone have any suggestions for retrieving the underlying IoT Hub hostname?
CodePudding user response:
IoT Central uses the Device Provisioning Service to handle device provisioning - this approach replaces the use of connection strings as described in the previous answer.
You can use MQTT to interact with IoT Central's DPS instance and retrieve device connection details. This article provides the information you need: https://docs.microsoft.com/azure/iot-dps/iot-dps-mqtt-support
Alternatively, you could run a separate script to generate a connection string for your device to use. For an example of the type of code the script should run, see https://github.com/Azure/azure-iot-sdk-node/blob/main/device/samples/javascript/pnp_simple_thermostat.js. In particular the provisionDevice function.
CodePudding user response:
Such feature is not available anymore. It was possible to get hostname of IoT Hub used in IoT Central some time ago, but from Jan 31 2020 it was depreciated. https://github.com/Azure/dps-keygen#retrieve-hub-connection-string-deprecated
You can use Azure IoT Central Device Bridge for your case https://docs.microsoft.com/en-us/azure/iot-central/core/howto-build-iotc-device-bridge But you'll need to have some additional services running on Azure.
