Getting a product serial number in prepare-device for amd64 classic

Hi @rahul-tt,

I’m assuming that you are mixing MODEL_APIKEY and Serial Number. The model api key is gathered manually from the Serial Vault and given to the gadget snap during the building. However, the mentioned registration.proposed-serial is a dynamic configuration that can be set by using snapctl set registration.proposed-serial="" in your prepare-device hook. E.g. you could use device’s mac address(assuming that every device has a unique MAC Address) as of your serial number.

product_serial=\$(cat /sys/class/net/enp1s0/address)
snapctl set registration.proposed-serial="\"\${product_serial}\""

So when you flash your image to your device, prepare-device hook will run on the device not your host computer, then snapd will read registration.proposed-serial configuration and register it as of your serial number.

Thanks for the info, So if I add this

product_serial=\$(cat /sys/class/net/enp1s0/address)

in my prepare device hook then that should automatically set mac address as my proposed serial during the first boot right?

That’s true. But you also need to define network-observe interface in your snapcraft.yaml file. E.g.

hooks:
  prepare-device:
    plugs:
    - network-observe

Finally, make sure that network-observe is automatically connected by using the connections definition in the gadget.yaml file. E.g.

connections:
  - plug: your-gadget-snap-id:network-observe

Thank you very much this is what i wanted

But cant i do the autoconnect in the brand store with viewer permissions too?

I believe, if you are a collaborator or the Publisher for the gadget snap, you could use the available UI in https://dashboard.snapcraft.io/ to enable this initial auto-connection. I believe that the accounts with viewer roles can only download snaps from your own IoT App Store (a.k.a Brand Store)

To autoconnect via the Dashboard you must have role Reviewer in the store in which the snap is publised. Note also that only a subset of snapd interface interfaces are exposed.