I want to query the public IP address or geolocation of a device connected to Azure IoTHub. I found a question on this topic from almost 3 years ago here. But the answer is not really what I am looking for. Does anyone know if there is a new function directly in IoTHub or Azure Functions for this task by now?
The short answer is that there's no built-in functionality in Azure IoT Hub to achieve this. The answer previously given by Rita Han is still correct. I wanted to get into a little bit more detail though.
If you have access to GPS, you can store that in the reported properties of the device twin. If there is no GPS available, you can store the public IP of your device in the reported properties instead, and use an external API to resolve an approximate location.
As you mentioned in a comment, you could also send the IP in a telemetry message. This will work as well, but the benefit of the device twin is that it's available when the device is offline as well, without any storage resource (the device twin lives in the hub). Looking at the effort of both cases, they both take exactly one message to send the IP to IoT Hub. The difference is that if you're using MQTT, you can listen for a confirmation message in case you're updating reported properties.