eSIM API介绍#
以下接口均是以LPA方式实现,需要用户和卡商确认eSIM卡是否支持LPA功能。
获取EID#
用户可以通过如下按钮获取eSIM卡的ICCID。
接口如下:
esim.getEid()
示例
# -*- coding: UTF-8 -*-
#示例
from sim import esim
eid=esim.getEid()
print("Get Eid :{}".format(eid))
回调注册#
用户可以通过如下接口注册回调函数,用于通知应用层profile下载安装结果。
接口如下:
esim.setCallback(usrFun)
示例
# -*- coding: UTF-8 -*-
#示例
from sim import esim
def usrFun(result):
'''
:param result :OTA下载profile结果。
:type result :整型,0:成功 1:失败
'''
print("OTA result:{}".format(result))
esim.setCallback(usrFun)
查询当前SIM卡profile#
用户可通过如下接口获取当前eSIM卡中的profile信息,用户可以根据查询到的profile信息,选择启用相应的运营商网络功能。
接口如下:
esim.getProfileInfo(mode)
示例
# -*- coding: UTF-8 -*-
#示例
from sim import esim
# 列出配置文件中类别为2的配置文件
profile_list=esim.getProfileInfo(0)
print("Get class 2 profile :{}".format(profile_list))
#列出所有的配置文件
profile_list=esim.getProfileInfo(1)
print("Get all profile :{}".format(profile_list))
下载安装运营商profile#
用户可通过如下接口下载安装运营商的profile。如eSIM为空卡,请使用QEsimTool工具进行安装首个profile。为确保此接口可以正常下载profile信息,需eSIM卡当前启用的profile能够正常注网,并且可以正常和AccCode中的运营商服务器地址进行网络数据交互。在此接口调用后,必须等下载结果通知到达后才能调用eSIM接口进行别的操作,否则将影响下载安装结果。
接口如下:
esim.profileOTA(activationCode, confirmationCode)
示例
# -*- coding: UTF-8 -*-
#示例
from sim import esim
def usrFun(result):
'''
:param result :OTA下载profile结果。
:type result :整型,0:成功 1:失败
'''
print("OTA result:{}".format(result))
esim.setCallback(usrFun)
# activationCode请使用自己的数据,下述activationCode仅作示例参数。
esim.profileOTA('LPA:XXX','')
控制当前SIM卡profile#
用户可通过如下接口对指定的ICCID对应的profile进行启用、禁用、删除操作。
接口如下:
esim.profileHandle(profile_tag, iccid)
示例
# -*- coding: UTF-8 -*-
#示例,此示例要求eSIM卡中必须有profile
from sim import esim
def handle_profile(ICCID,mode):
esim.profileHandle(mode, ICCID)
# 获取当前profile ICCID
profile_list=list(esim.getProfileInfo(0))
# 更改profile的状态
if profile_list[1][0][1] == 1:
print("ICCID {} 已启用".format(profile_list[1][0]))
# disable this ICCID
esim.profileHandle(1, profile_list[1][0][0])
elif profile_list[1][0][1] == 0:
print("ICCID {} 已禁用".format(profile_list[1][0]))
# enable this ICCID
esim.profileHandle(0, profile_list[1][0][0])
else:
raise ValueError("profile_list is invalid")
# 删除profile
esim.profileHandle(2, profile_list[1][0][0])
获取待通知事件#
用户可通过如下接口查询本地已删除,但并未在服务器完成删除操作的profile信息。
接口如下:
esim.getProfileDelNotification()
示例
# -*- coding: UTF-8 -*-
#示例,此示例要求eSIM卡中必须有profile
from sim import esim
del_error_profile=esim.getProfileDelNotification()
print("本地已删除,未能正常上报服务器的profile信息: {}".format(del_error_profile))
上报通知事件#
用户可通过如下接口再次向服务器发起删除指定profile的请求,以确保服务端完成对profile信息的删除操作。
此函数参数需通过esim.getProfileDelNotification()获取。
接口如下:
esim.reportProfileDelNotification(iccid)
示例
# -*- coding: UTF-8 -*-
#示例,此示例要求eSIM卡中必须有profile
from sim import esim
del_error_profile=esim.getProfileDelNotification()
print("本地已删除,未能正常上报服务器的profile信息: {}".format(del_error_profile))
# 发起请求服务端删除此ICCID对应的profile
esim.reportProfileDelNotification(profile_list[1][0][0])
eSIM应用示例#
- 用户从运营商购买eSIM卡。
- 用户用一段时间后,想切换到别的运营商。
为解决上述问题,用户应用示例如下:
# -*- coding: UTF-8 -*-
#示例,此示例要求eSIM卡中必须有profile
try:
from sim import esim
except Exception as e:
print("this version no this modles")
import utime
import checkNet
import _thread
import atcmd
class pyesim():
def __init__(self):
self.stage, self.state = checkNet.waitNetworkReady(60)
if self.stage == 3 and self.state == 1:
print("network is success!")
self.debug_enbale = True
self.ota_result = False
pass
def esim_log(self,args):
if self.debug_enbale == True:
print("esim {}".format(args))
pass
def get_eid(self):
self.eid = esim.getEid()
self.esim_log("esim get id {} ".format(self.eid))
def get_profile_list(self,model = 0):
self.profile_list=esim.getProfileInfo(model)
self.esim_log("esim get_profile_list({}): {}".format(model,self.profile_list))
def profile_handle(self,profile_tag,iccid):
result = esim.profileHandle(profile_tag, iccid)
self.esim_log("esim profile_handle({},{}) = {}".format(profile_tag,iccid,result))
def profile_ota(self,activationCode,confirmationCode):
ret = esim.profileOTA(activationCode, confirmationCode)
self.esim_log("esim profileOTA('{}','{}') = {}".format(activationCode,confirmationCode,ret))
def wait_ota_result(self):
i_loop_nunmbers = 120
while self.ota_result == True or i_loop_nunmbers > 0:
i_loop_nunmbers = i_loop_nunmbers - 1
utime.sleep(1)
self.esim_log("wait ota ... {}".format(i_loop_nunmbers))
def callback(self,args):
if args == 0:
self.esim_log("esim callback OTA {} success".format(args))
self.ota_result = True
else:
self.esim_log("esim callback OTA {} failed".format(args))
self.ota_result = False
def set_callback(self):
ret = esim.setCallback(self.callback)
self.esim_log("esim set_callback Result {}".format(ret))
def get_profile_del_notification(self):
self.profile_notification = esim.getProfileDelNotification()
self.esim_log("esim get_profile_del_notification {}".format(self.profile_notification))
def report_profile_notification(self,iccid):
ret = esim.reportProfileDelNotification(iccid)
self.esim_log("esim report_profile_notification {}".format(ret))
esim_t = pyesim()
def run():
esim_t.get_eid()
esim_t.set_callback()
esim_t.esim_log("will OTA iccid ")
esim_t.esim_log("will display current info")
esim_t.esim_log("-------------------------------------------------")
esim_t.get_profile_list(0)
esim_t.esim_log("-------------------------------------------------")
# 先下载安装将要切换的运营商profile信息
# 下述activationCode仅作示例参数
esim_t.profile_ota('LPA:XXX','')
#等待下载结果
esim_t.wait_ota_result()
# 删除原来的运营商profile信息
uiccid = 'XXX'
esim_t.esim_log("will delelte uiccid {}".format(uiccid))
esim_t.profile_handle(2, uiccid)
esim_t.esim_log("will display delelte iccid info")
esim_t.esim_log("-------------------------------------------------")
esim_t.get_profile_list(0)
esim_t.esim_log("-------------------------------------------------")
if __name__ == '__main__':
_thread.start_new_thread(run,())
常见问题解答#
无法下载安装profile#
- AccCode是否错误,可向运营商进行确认。
- 当前的设备或PC机是否可以正常访问从AccCode中解析出的url地址。
- 是否重复下载安装profile。
- 是否运营商进行限制,同一个AccCode只能使用一次,需和运营商进行确定。
- 网络信号是否太弱,网络不稳定。
下载安装profile后无法上网#
如遇到下载安装profile成功后无法上网,请做一次CFUN=0/1的切换操作。如依然无法上网,请按如下方面进行检查。
- SIM卡状态是否异常
- 下载安装的profile是否已正常激活。
- 下载安装的profile是否有效,可向运营商确认。
- 是否设备未执行拨号操作(如设置设备不自动激活,请检查是否未执行激活操作)
提示eSIM卡未插卡#
请参考QuecPtyhon官网wik蜂窝无线网卡网络异常处理。
300

被折叠的 条评论
为什么被折叠?



