Interactively parsing eSIM Activation from LPA in QRCode...

In 7.18, there are new eSIM commands & new serialize/deserialize fixes. While I have no idea what modems or hardware supports them. But from a discussion in another thread about eSIM support, I cleaned the example to using “ask” to prompt for the needed information.
:global activateEsimFromQr do={
:local samplelpa “LPA:1$EXAMPLE.COM$XYZ123$$1$$”
:local qrlpa [/terminal/ask “eSIM activation code (decoded from QR):” preinput=$samplelpa]
:local activationcode
:local parsedlpa ([:deserialize from=dsv delimiter=“$” $qrlpa options=dsv.plain]->0)
:if ([:len $parsedlpa]<3) do={ :error “ERROR - invalid eSIM activation code” }
:put “\tparsed:”
:put [:serialize to=json $parsedlpa options=json.pretty]
:if (($parsedlpa->4) = 1) do={
:set activationcode [/terminal/ask “Confirmation Code Required (provided by eSIM carrier):” ]
:put “The esim provision (no confirmation code required) command should be:”
:put “/interface/lte/esim/provision interface=[find] sm-dp-plus="$($parsedlpa->1)" matching-id="$($parsedlpa->2)" confirmation-code="$activationcode"”
} else={
:put “The esim provision with confirmation code command should be:”
:put “/interface/lte/esim/provision interface=[find] sm-dp-plus="$($parsedlpa->1)" matching-id="$($parsedlpa->2)"”
}
}

[amm0@bigdude] > $activateEsimFromQr
eSIM activation code (decoded from QR):
LPA:1$EXAMPLE.COM$XYZ123$$1$$
parsed:
[
“LPA:1”,
EXAMPLE.COM”,
“XYZ123”,
“”,
1,
“”,
“”
]
Confirmation Code Required (provided by eSIM carrier):
jhjhkhd
The esim provision (no confirmation code required) command should be:
/interface/lte/esim/provision interface=[find] sm-dp-plus=“EXAMPLE.COM” matching-id=“XYZ123” confirmation-code=“jhjhkhd”
[amm0@bigdude] > $activateEsimFromQr
eSIM activation code (decoded from QR):
LPA:1$EXAMPLE.COM$XYZ123$
parsed:
[
“LPA:1”,
EXAMPLE.COM”,
“XYZ123”,
“”
]
The esim provision with confirmation code command should be:
/interface/lte/esim/provision interface=[find] sm-dp-plus=“EXAMPLE.COM” matching-id=“XYZ123”

Now what modem support those commands, IDK. And annoyed about that part. But the [:serialize] / [:deserialize] / [/terminal/ask] do make quick work of the, theoretical, problem — especially using a CLI with strings that contain $ — which eSIM activations do. i.e. “LPA:1$example.com$abc$123”, and the spec uses a dollar sign $ as a separator, instead of a , comma or something normal.

For context, @Larsa has documented the overall manual process of eSIM activations:

  1. Get the eSIM SM-DP+ address and activation code (or QR code) from your mobile operator.
  2. Log in to your MikroTik router via WebFig or WinBox.
  3. Go to Interfaces > LTE > eSIM Management.
  4. Add new eSIM profile and enter the SM-DP+ address and activation code. These values can be extracted from the QR code, just scan it to get a string like “LPA:1$<SM-DP+ address>$”.
  5. Apply and wait for the profile to activate.
  6. Verify that the LTE interface is registered and working.

And MikroTik has improved their docs on eSIM since original post for more context on eSIM: https://help.mikrotik.com/docs/spaces/ROS/pages/30146563/LTE#LTE-LTEeSIM

The difference is the above script lets you parse it automatically, and use the CLI to apply an eSIM profile. @Larsa’s steps are for WinBox/WebFig UI, but you can use script to parse the data needed – since script just SHOWS* the CLI command but does not run it. *To make it RUN the eSIM provisioning, just remove the

:put

and quotes on the 2 x “/interface/lte/esim/ …” lines near end in your copy of the script.