CGI-FR / IoT-Hub-Portal

IoT Hub Portal is a solution for handling IoT Devices easily. It leverages on Azure IoT Hub / AWS IoT Core for connectivity and device management.
https://cgi-fr.github.io/IoT-Hub-Portal/stable/
MIT License
32 stars 10 forks source link

Bug: Azure IoT Hub <> Portal sync doesn't work as expected #2833

Open Metal-Mighty opened 6 months ago

Metal-Mighty commented 6 months ago

Expected Behavior

Since the introduction of the database cache for the portal, I expect it to stay up to date with what's actually in the IoT Hub on Azure (models, devices, etc).

Current Behavior

The portal doesn't fully synchronize with IoT Hub. It adds elements from IoT Hub to its db, but if elements are deleted directly from the IoT Hub without using the portal, elements stay in the DB and sometimes can't even be removed from the portal. Same goes if the IoT Hub is deleted and created again: The portal still has the old data. It can also lead to errors in automated deployment tasks: We use the API to check for existing models and we create or update them depending on the result, but since it doesn't return the actual Azure data, it doesn't always properly create or update elements. This is also especially problematic on elements with unique IDs, connection keys, etc. (e.g., Edge Devices credentials).

Steps to Reproduce

  1. Add something (e.g. device model) to the portal
  2. Remove the element from Azure directly
  3. The element is still in the portal

Context (Environment)

Portal version: 4.13.2.170 LoRaWAN Stack version: N/A

Logs

Additional Information

kbeaugrand commented 6 months ago

@Metal-Mighty the portal has a synchronization scheduler. I could take some minutes to reflect Azure IoT Hub changes to the portal directly.

I encourage you to not change devices directly on IoT Hub while using the portal to limit the apparition to this issue.

By the way, the refresh timeout is by default set to 5 minute. You can adapt it in your settings to reduce it in case it is necessary: (See: https://cgi-fr.github.io/IoT-Hub-Portal/stable/dev-guide/#application-settings:~:text=Job__SyncDatabaseJobRefreshIntervalInMinutes for more details).

Ar you able to reproduce it after the sync timeout?

Metal-Mighty commented 6 months ago

Hi @kbeaugrand ! I can confirm it's still an issue after a sync timeout since I realized this afternoon that device models (in IoT Hub > Configurations + Deployments) were missing, even though they were in the portal since Friday. Sadly this comes after having to recreate the IoT Hub because it wasn't properly created on Azure, and it was the only thing to do according to our contact at Microsoft, so not something we could have done in the Portal ;)

What I could have done would be to delete everything from the Portal prior to deleting the IoT Hub, but I didn't think about it back then!

Metal-Mighty commented 6 months ago

We're having the same issue today in another use case: We have and IoT Hub, and an Azure-hosted IoT Portal connected to it and a number of devices (and edge devices) + their associated models declared. We started a Portal locally on a development machine with a local db (= not the one used by the portal on Azure), but connected to the same Azure IoT Hub as our Azure Portal.

=> The local Portal didn't sync the data from IoT Hub into the development portal's DB. Only the Dashboard has correct information (and we did wait much more than 5 minutes 😉) The dev instance is started using the code in the main branch.

image image

kbeaugrand commented 6 months ago

I In this case, I assume that this problem occurs because device models are not created in the development environment.

Could you check that all models are also created in the development environment because they should be present to be able to synchronize their devices.

Note that since models are not a supported feature on Azure IoT hub, they could not be synchronized anyway.