How to dynamically assign new devices to new users

How to dynamically assign new devices to new users

@Enrique Camarotti

Hi all, I really hope you can help me with this. I have been looking at tutorials and at the posts in the community, and I cannot seem to find an answer to the problem I´m facing. I have created a blueprint dashboard, where each user will see sensor data from his/her device (or filter with the dropdown in case they have more than one). When the user logs in for the first time, they go to a form where they add their device (creating a new fantasy name and scanning a QR code that contains a serial number defined by me), and then I need a way to map this device to this user.

Previous to that, in the factory, I had to create the device in Tago so that I can obtain the token to put in the firmware of my device, and I also stored a tag called serial_number in the device with the value of the serial number of this device (which will later be obained by the user scanning the QR code in the phisical device).

When the user that acquired a new device fills the “Add new device” form, there should be some sort of analysis that maps this user to the device, based on the serial number. I was thinking of using as an internal_mapping_tag the email of the user. So what I´m struggling now is with how to implement the following in the analysis:

  1. new user email has to be mapped to tag internal_mapping_tag inside the user.
  2. when user does the process of adding a device, then I have to find the device filtered by serial_number that the user scanned, and then that device has to get its name changed by the one the user created, and the tag internal_mapping_tag of the device has to have the value=user email.

I would appreciate if you can point me in the right direction of how to implement this easily.

Regards,
Enrique