From 8d5bf3fc2f223ef45bd7d1c0e2e6115fe04756b2 Mon Sep 17 00:00:00 2001 From: "burols.wang" Date: Tue, 9 Jul 2024 19:02:23 +0800 Subject: [PATCH 01/14] =?UTF-8?q?=20(utime):=20=E4=BF=AE=E6=94=B9uti?= =?UTF-8?q?me.localtime()=EF=BC=8Cutime.mktime()=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E7=9A=84=E6=8F=8F=E8=BF=B0=E3=80=82=E6=B7=BB=E5=8A=A0=E6=96=B0?= =?UTF-8?q?=E7=9A=84=E6=8E=A5=E5=8F=A3utime.localtime=5Fex()=EF=BC=8Cutime?= =?UTF-8?q?.mktime=5Fex()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 固件版本: N 是否需要文案翻译: 是 --- docs/API_reference/zh/stdlib/utime.md | 95 ++++++++++++++++++++++++++- 1 file changed, 92 insertions(+), 3 deletions(-) diff --git a/docs/API_reference/zh/stdlib/utime.md b/docs/API_reference/zh/stdlib/utime.md index aac41d04..48df3731 100644 --- a/docs/API_reference/zh/stdlib/utime.md +++ b/docs/API_reference/zh/stdlib/utime.md @@ -36,14 +36,16 @@ if __name__ == '__main__': ### `utime.localtime` ```python +utime.localtime() utime.localtime(secs) ``` -将一个以秒为单位的时间转换为一个日期格式的时间并返回,或者返回本地RTC的时间,取决于参数`secs`是否提供。 +如有参数,secs需为UTC时间戳,此接口将UTC时间戳转换为UTC日期时间加8时区后的日期时间格式。 **参数描述:** -- `secs`-int类型,一个以秒为单位的时间。 +- 无参数。返回本地日期时间,即UTC日期时间加设备所设置的时区后的日期时间。 +- 有参数,`secs`-int类型,单位秒。返回UTC日期时间加8时区后的日期时间。 **返回值描述:** @@ -60,6 +62,10 @@ utime.localtime(secs) | weekday | int型,周一到周日是0~6 | 星期 | | yearday | int型 | 一年中的第多少天 | +**注意** + +有参数的模式下,如期望参数secs转换为设备所设置的时区的本地时间,请调用utime.localtime_ex(secs)接口。 + **示例**: ```python @@ -70,13 +76,60 @@ utime.localtime(secs) (1990, 7, 2, 14, 5, 36, 0, 183) ``` +### utime.localtime_ex + +```python +utime.localtime_ex() +utime.localtime_ex(secs) +``` + +如有参数,secs需为UTC时间戳。 + +**参数描述:** + +- 无参数。返回当前本地时间(UTC+时区)。 +- 有参数,`secs`-int类型,单位秒。返回secs代表的UTC日期时间加设备设置的时区后的日期时间,例如,当前设备时区为3,secs转成UTC时间日期为2024-07-09 16:30:00,这此函数返回时间为,2024-07-09 19:30:00 。 + +**返回值描述:** + +`(year, month, day, hour, minute, second, weekday, yearday)`-类型为元组,包含了年、月、日、时、分、秒、星期、一年中第几天。当提供参数`secs`时,返回转换后的时间。当参数`secs`没有提供时,则返回本地RTC的时间。返回值含义如下: + +| 元组成员 | 范围及类型 | 含义 | +| ------- | -------------- | -------- | +| year | int型 | 年份 | +| month | int型,1~12 | 月份 | +| day | int型,1~31 | 日,当月多少号 | +| hour | int型,0~23 | 小时 | +| minute | int型,0~59 | 分钟 | +| second | int型,0~59 | 秒 | +| weekday | int型,周一到周日是0~6 | 星期 | +| yearday | int型 | 一年中的第多少天 | + +**示例**: + +```python +>>> import utime +>>> utime.setTimeZone(3) +0 +>>> utime.getTimeZone() +3 +>>> date=utime.localtime_ex() +>>> date +(2024, 7, 9, 13, 59, 30, 1, 191) +>>> utime.mktime_ex(date) +1720522770 +>>> utime.localtime_ex(1720522770) +(2024, 7, 9, 13, 59, 30, 1, 191) +>>> +``` + ### `utime.mktime` ```python utime.mktime(date) ``` -将一个存放在元组中的日期格式的时间转换为以秒为单位的时间并返回。 +date需为UTC日期时间加8时区后的日期时间,此接口将8时区的日期时间转换为UTC时间戳。 **参数描述:** @@ -86,6 +139,10 @@ utime.mktime(date) int类型。 +**注意** + +如date不为8时区日期时间,期望按照模组的本地时间转换成UTC时间戳,请调用接口utime.mktime_ex(date)。 + **示例**: ```python @@ -95,6 +152,38 @@ int类型。 1601340882 ``` +### utime.mktime_ex + +```python +utime.mktime_ex(date) +``` + +date需为设备的本地时间,此接口将date转换为UTC时间戳。例如,当前时区为3,输入日期为2024-07-09 19:30:00,此函数将返回1720542600,此时间戳为UTC时间戳,UTC时间为2024-07-09 16:30:00。 + +**参数描述:** + +- `date`-日期格式的时间,类型为元组,格式:(year, month, mday, hour, minute, second, weekday, yearday)。 + +**返回值描述:** + +int类型。 +**示例**: + +```python +>>> import utime +>>> utime.setTimeZone(3) +0 +>>> utime.getTimeZone() +3 +>>> date=utime.localtime_ex() +>>> date +(2024, 7, 9, 13, 59, 30, 1, 191) +>>> utime.mktime_ex(date) +1720522770 +>>> utime.localtime_ex(1720522770) +(2024, 7, 9, 13, 59, 30, 1, 191) +>>> +``` ### `utime.time` ```python -- Gitee From 7ed92295f06d85dca36f1b1cf0449306a05f4da7 Mon Sep 17 00:00:00 2001 From: "burols.wang" Date: Mon, 29 Jul 2024 15:45:34 +0800 Subject: [PATCH 02/14] =?UTF-8?q?=20(lwm2m):=20=E6=B7=BB=E5=8A=A0lwm?= =?UTF-8?q?2m=E7=9A=84api=E4=BD=BF=E7=94=A8=E6=8F=8F=E8=BF=B0=E6=96=87?= =?UTF-8?q?=E6=A1=A3=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 固件版本: N 是否需要文案翻译: 否 --- docs/API_reference/en/cloudlib/Lwm2m.md | 445 ++++++++++++++++++++ docs/API_reference/en/cloudlib/Lwm2m.mdbak | 447 ++++++++++++++++++++ docs/API_reference/en/cloudlib/README.md | 8 + docs/API_reference/en/sidebar.yaml | 7 +- docs/API_reference/zh/cloudlib/Lwm2m.md | 453 +++++++++++++++++++++ docs/API_reference/zh/cloudlib/README.md | 1 + docs/API_reference/zh/sidebar.yaml | 4 +- 7 files changed, 1363 insertions(+), 2 deletions(-) create mode 100644 docs/API_reference/en/cloudlib/Lwm2m.md create mode 100644 docs/API_reference/en/cloudlib/Lwm2m.mdbak create mode 100644 docs/API_reference/en/cloudlib/README.md create mode 100644 docs/API_reference/zh/cloudlib/Lwm2m.md diff --git a/docs/API_reference/en/cloudlib/Lwm2m.md b/docs/API_reference/en/cloudlib/Lwm2m.md new file mode 100644 index 00000000..371a765e --- /dev/null +++ b/docs/API_reference/en/cloudlib/Lwm2m.md @@ -0,0 +1,445 @@ +# LWM2M - Lightweight Internet of Things + +## Create object + +> lw=lwm2m() + +- Parameters + No + +- Return value + Lwm2m object + +- Example + + ```python + >>> import lwm2m + >>> lw=lwm2m() + >>> + ``` + +## Initialize object + +> lw.init() + +- Parameters + No + +- Return value + Success: 0 + Failed: -1 + +- Example + +```python +>>> lw.init() +0 +>>> +``` + +## Configure objects + +> lw.config(config_type,config_list) + +- Parameters + config_type: Configuration type + config_list : List type, configuration parameter list. + +- Return value + Success: 0 + Failed: -1 + Not supported: -2 + +Introduction to fields in the config_list parameter list + +| Field Name | Field Type | Field Description | +| --------------- | ---------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| serverID | integer | 0 Bootstrap server
1 DM server
| +| SSID | integer | 100 Bootstrap server
1000 Diagnostics server
| +| server_addr | string | Server Address, in the format of "address: port", supports a maximum length of 256 | +| bootstrap | integer | 0. No need to use bootstrap (only if server ID is not 0)
1. Use bootstrap (only if server ID is 0) | +| security_mode | integer | encryption method:
0 Pre share key mode
3 No security mode | +| psk_id | string | useful when secure_mode is 0 | +| psk_key | string | useful when secure_mode is 0 | +| life_time | integer | lifetime, value range 1~86400, default value 86400, unit: seconds | +| pmin | integer | pmin default period, value range 1~86400, default value 86400, unit: seconds | +| pmax | integer | pmax default period, value range 1~86400, default value 86400, unit: seconds | +| disable_timeout | integer | The time interval from disconnecting from the LwM2M server to the next connection. The range is 1-86400, with a default value of 86400 and a unit of seconds. After testing the port, it can be immediately connected. Invalid (sent to the server, not restricted by the server) | +| storing | integer | Whether to save server information
0. Do not save
1. Save | +| binding_mode | string | Server Connection Method
"U" - UDP Method
"UQ" - UDP with Queue Mode
"S" - SMS Method
"SQ" - SMS with Queue Mode
"US" - UDP and SMS Methods
"UQS" - UDP and SMS with Queue Mode | +| mode | integer | terminal device name format
3 format: urn: imei: xxxxx
lwm2mserver configuration epname format | +| download | Integer | Download Mode
0 Manual Download
1 Automatic Download | +| update | integer | update mode
0 Manual update
1 Automatic update | +| URC_onoff | Integer | Enable URC reporting for LWm2m
0 Disable URC reporting
1 Enable URC reporting | + +Introduction to config_type parameter configuration type + +| Configuration type name | Corresponding config_list parameter | Remarks | +| ----------------------- | -------------------------------------------------------------------- | --------------------------------------------------------------- | +| Epnamemode | [mode] | | +| Reset | [] | Empty list | +| Security | [serverID, SSID,server_addr,bootstrap,security_mode,psk_id,psk_key] | | +| Server | [serverID, life_time,pmin,pmax,disable_timeout,storing,binding_mode] | | +| Urc | [URC_onoff] | If you want to capture URC, you must configure it to be enabled | +| Fota | [download, update] | If you want to crawl URLs, configure them to not be automatic | + +- Example + +```python +>>> config=[0,100," coaps://InteropBootstrap.dm.iot.att.com:5694 ",1,0,"urn:imei:864430010001095","313233343536"] +>>> lw.config(lw.Security,config) +0 +>>>   +``` + +## Register + +> lw.register() + +- Parameters + nothing + +- Return value + Return 0 for successful execution and -1 for failed execution. The registration result needs to be queried by calling the query interface. + +- Example + +```python +>>> lw.register() +0 +``` + +## Unregister + +> lw.unregister() + +- Parameters + nothing + +- Return value + Return 0 for successful execution and -1 for failed execution. The cancellation result needs to be queried by calling the query interface. + +- Example + +```python +>>> lw.unregister() +0 +``` + +## Check registration status + +> lw.stat() + +- Parameters + nothing + +- Return value + 0 Unregistered
1 Registering
2 Registered
3 Cancelling
+ 4 login failures + +- Example + +```python +>>> lw.stat() +0 +>>> lw.register() +0 +>>> lw.stat() +one +>>> lw.unregister() +0 +>>> lw.stat() +three +>>> +``` + +## Send heartbeat + +> lw.update(SSID) + +- Parameters + SSID : The configured SSID, or the SSID issued by BS. + +- Return value + Command success returns 0, command failure returns -1. The success or failure of the update is determined based on the "+QLWURC:" update "event. + +- Example + +```python +>>> lw.update(1) +0 +``` + +## Register callback function + +> lw.register_call(usrfun) + +- Parameters + Usrfun: function + Prototype of usrfun: usrfun (list) + Usrfun parameter: type list + List description: + + | Parameter Description | Parameter Type | Remarks | + | --------------------- | -------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | + | List [0] | int | Event type (can be ignored without processing) | + | List [1] | int | Event encoding (can be ignored without processing) | + | List [2] | string | The URC string data captured (please refer to [Event Description](#Event description) for specific event descriptions), and use this parameter to determine the connection event of Lwm2m | + +- Return value + Success returns 0, failure returns -1 + Note that if you want to delete a registered callback function, pass the parameter None + +- Example + +```python +>>> import lwm2m +>>> lw=lwm2m() +>>> def lwm2m_call(args): +... print('args{}'.format(args)) +... +... +... +>>> +>>> lw.register_call(lwm2m_call) +0 +>>> +>>> lw.register_call(None) +0 +>>> +>>> +``` + +## Support platform + +| Support Platform | Remarks | +| --------------------------------------- | ---------------------------------------------------------------- | +| EC600UEU_AC | Public version is not supported, customized models are supported | +| BG95M8 | | +| BG95M3 | | +| EC200AAU_HA | | +| EG915NEA_AC | Public version is not supported, customized models are supported | +| EG912NEN_AA | | + +## Event description + +| Event type | Description | Remarks | +| ------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- | +| +QLWURC: "pdp active",result,APN | PDP activation result. Before sending a registration request to LwM2M, the PDP server should be activated | Result: string type
"successful"
"failed"
APN: string type
APN value | +| +QLWURC: "initial",result,SSID | The initialization result of the connection between the client and LwM2M server | Result: string type
"successful"
"failed"
SSID: shape type
0- all servers
other values - other special servers | +| +QLWURC: "dtls",result,SSID | DTLS handshake result when using encryption method | Same as above | +| +QLWURC: "bootstraping" | When Bootstrap is working, this URC will be reported | | +| +QLWURC: "bootstrap",result,SSID | Bootstrap's working result | Same as above | +| +QLWURC: "registering" | This URC will be reported when the client registers on the LwM2M server | Same as above | +| +QLWURC: "ready",result,SSID | The registration result after sending a registration request to the LwM2M server | Same as above | +| +QLWURC: "update",result,SSID | The update result after sending an update request to the LwM2M server | Same as above | +| +QLWURC: "deregister",SSID,code
+QLWURC: "deregister",code | The logout result after sending a logout request to the LwM2M server | SSID: Shaping type
0- All servers
Other values - Other special servers
Code: Shaping
0- Success
1- Failure
3- Unknown error | +| +QLWURC: "fota/pkgurl",url | The URL address issued by LWM2M. | | +| +QLWURC: "apn_changed",APN | APN value issued by LWM2M. | | +| +QLWURC: "user_name_changed",user | User issued by LWM2M. | | +| +QLWURC: "secret_changed",password | Password issued by LWM2M | | +| +QLWURC: "authentication_type_changed", | Authentication issued by LWM2M. | | +| +QLWURC: "lifetime_changed",lifetime | The lifetime issued by LWM2M | | +| +QLWURC: "current_time_changed",data_time | The data_time issued by LWM2M is added with UTC_OFFSET. | | + +###### Example usage + +```python +import utime +import lwm2m +import modem +import net +import checkNet +from machine import Pin +import _thread + +class lwm2m_client(): + + def __init__(self): + + self.lwm2m = lwm2m() + self.network_wait_time = 60 + self.host = "220.180.239.212" + self.port = "5563" + self.connect_state = 0 # 0 -init, 1- registing, 2-register failed, 3-register success. + self.connect_server_type = 0 # 0 - server, 1 - bsserver + self.imei = modem.getDevImei() + self.security_mode = 3 # 3 - no Pre-share key mode, 0 Pre-share key mode , 2 - x509 + self.epname_mode = 3 # 3 - urn:imei:+imei . 1 - user define epname + self.support_security_mode=[0,2,3] + + self.psk="urn:imei:{}".format(self.imei) + self.key="30313233343536373839" + + if self.security_mode == 3: + self.url = "coap://"+self.host +":"+ self.port + else: + self.url = "coaps://"+self.host +":"+ self.port + + self.config_security =[1,1000,self.url,self.connect_server_type,3] + self.config_epname = ["testname"] # only self.epname_mode = 1 will use it + self.config_epnamemde = [self.epname_mode] + self.config_foat = [0,1] + self.config_server = [1, 60, 2, 60, 86400, 1, "U"] + stage, state = checkNet.waitNetworkReady(30) + if stage == 3 and state == 1: + self.log('Network connection successful.') + else: + self.log('Network connection failed, stage={}, state={}'.format(stage, state)) + + def log(self,args): + print("[Lwm2m_client Info] {}".format(args)) + + def lwm2m_set_psk(self,psk="testname"): + if self.security_mode == 0: + self.psk = psk + else: + self.log("security_mode:{},not support config psk!".format(self.security_mode)) + + def lwm2m_set_key(self,key="30313233343536373839"): + if self.security_mode == 0: + self.key = key + else: + self.log("security_mode:{},not support config key!".format(self.security_mode)) + + + def lwm2m_set_server_host(self,url="220.180.239.212"): + self.host = url + self.lwm2m_update_connect_url() + + def lwm2m_update_connect_url(self): + if self.security_mode == 3: + self.url = "coap://"+self.host +":"+ self.port + else: + self.url = "coaps://"+self.host +":"+ self.port + + def lwm2m_set_epname(self,epname): + if self.epname_mode == 1: + self.config_epname = [epname] + else: + self.log("epname_mode :{},the mode not support set epame!!".format(self.epname_mode)) + + def lwm2m_set_server_port(self,port="5563"): + self.port = port + self.lwm2m_update_connect_url() + + def lwm2m_set_security_mode(self,mode=3): + if mode in self.support_security_mode: + self.security_mode = mode + self.lwm2m_update_connect_url() + else: + self.log("the security_mode {} not support !!".format(mode)) + self.log("current support security_mode :{}".format(self.support_security_mode)) + + def lwm2m_mesage_callback(self,args): + self.log("Get Lwm2m Server Data :{}".format(args)) + result=args[2] + if '"ready","successfully"' in result: + self.log('Connect Success!') + elif '"ready","failed"' in result: + self.log('Connect Failed!') + else: + pass + + def lwm2m_display_current_info(self): + self.log("/---display config information---\\") + self.log("lw.Security :{}".format(self.config_security)) + self.log("lw.config_server :{}".format(self.config_server)) + self.log("lw.Epnamemode :{}".format(self.config_epnamemde)) + if self.epname_mode == 1: + self.log("lw.epname :{}".format(self.config_epname)) + self.log("lw.Fota :{}".format(self.config_foat)) + self.log("\\---display config information---/") + + + def lwm2m_config_prepare(self): + config=[] + self.lwm2m.config(self.lwm2m.Reset,config) + config=[1] + self.lwm2m.config(self.lwm2m.Security,config) + config=[0] + self.lwm2m.config(self.lwm2m.Security,config) + + def lwm2m_set_connect_type(self,connect_type): + if connect_type == 1 or connect_type == 0: + self.connect_server_type = connect_type + else: + self.log("connect_type :{},not support!".format(connect_type)) + + def register_all_callback(self): + self.lwm2m.register_call(self.lwm2m_mesage_callback) + + def lwm2m_set_epname_mode(self,epname_mode = 3): + if epname_mode == 1 or epname_mode == 3: + self.epname_mode = epname_mode + else: + self.log("epname_mode :{},not support!".format(epname_mode)) + + def lwm2m_update_all_config(self): + + if self.connect_server_type == 0 : + # connect server + self.config_security=[1,1000,self.url,self.connect_server_type,self.security_mode] + if self.connect_server_type == 1 : + # connect bsserver + self.config_security=[0,100,self.url,self.connect_server_type,self.security_mode] + + if self.security_mode == 0: + # need psk + self.config_security.append(self.psk) + self.config_security.append(self.key) + self.config_epnamemde=[self.epname_mode] + + def lwm2m_config(self): + self.lwm2m_display_current_info() + self.log("wait 1s ,will start config profile infomation!") + utime.sleep(1) + + self.lwm2m.config(self.lwm2m.Security,self.config_security) + self.lwm2m.config(self.lwm2m.Server,self.config_server) + self.lwm2m.config(self.lwm2m.Epnamemode,self.config_epnamemde) + if self.epname_mode == 1: + self.lwm2m.config(self.lwm2m.Epname,self.config_epname) + self.lwm2m.config(self.lwm2m.Fota,self.config_foat) + + + def lwm2m_befor_run(self): + + # must clear dirty config,always run this function + self.lwm2m_config_prepare() + + # config security_mode :3-no PSK ,0 -psk + self.lwm2m_set_security_mode(0) + + # config lwm2mserver ip address + self.lwm2m_set_server_host("lwm2m-test.avsystem.io") + self.lwm2m_set_server_port("5684") + # config epname format : 3 - urn:imei:imei + epname_mode = 3 + self.lwm2m_set_epname_mode(epname_mode) + self.lwm2m_set_psk("urn:imei:869339060001965") + self.lwm2m_set_key("30313233343536373839") + + # config connect server or bsserver 0 - server 1 -bsserver + self.lwm2m_set_connect_type(0) + + # update config set + self.lwm2m_update_all_config() + self.lwm2m_config() + self.register_all_callback() + + def lwm2m_run(self): + self.lwm2m_befor_run() + self.lwm2m.register() + +lw=lwm2m_client() + +def th_lwm2m(args): + print('thread th_func1 {} is running, heap_size {}'.format(args,_thread.get_heap_size())) + global lw + lw.lwm2m_run() + +if __name__ == '__main__': + + _thread.start_new_thread(th_lwm2m, (list("r"))) +``` diff --git a/docs/API_reference/en/cloudlib/Lwm2m.mdbak b/docs/API_reference/en/cloudlib/Lwm2m.mdbak new file mode 100644 index 00000000..4ef2c193 --- /dev/null +++ b/docs/API_reference/en/cloudlib/Lwm2m.mdbak @@ -0,0 +1,447 @@ +# LWM2M - Lightweight Internet of Things + +## Create object + +> lw=lwm2m() + +- Parameters + No + +- Return value + Lwm2m object + +- Example + + ```python + >>> import lwm2m + >>> lw=lwm2m() + >>> + ``` + +## Initialize object + +> lw.init() + +- Parameters + No + +- Return value + Success: 0 + Failed: -1 + +- Example + +```python +>>> lw.init() +0 +>>> +``` + +## Configure objects + +> lw.config(config_type,config_list) + +- Parameters + config_type: Configuration type + config_list : List type, configuration parameter list. + +- Return value + Success: 0 + Failed: -1 + Not supported: -2 + +Introduction to fields in the config_list parameter list + +| Field Name | Field Type | Field Description | +| --------------- | ---------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| serverID | integer | 0 Bootstrap server
1 DM server
| +| SSID | integer | 100 Bootstrap server
1000 Diagnostics server
| +| server_addr | string | Server Address, in the format of "address: port", supports a maximum length of 256 | +| bootstrap | integer | 0. No need to use bootstrap (only if server ID is not 0)
1. Use bootstrap (only if server ID is 0) | +| security_mode | integer | encryption method:
0 Pre share key mode
3 No security mode | +| psk_id | string | useful when secure_mode is 0 | +| psk_key | string | useful when secure_mode is 0 | +| life_time | integer | lifetime, value range 1~86400, default value 86400, unit: seconds | +| pmin | integer | minimum response period, value range 1~86400, default value 86400, unit: seconds | +| pmax | integer | Maximum response period, value range 1~86400, default value 86400, unit: seconds | +| disable_timeout | integer | The time interval from disconnecting from the LwM2M server to the next connection. The range is 1-86400, with a default value of 86400 and a unit of seconds. After testing the port, it can be immediately connected. Invalid (sent to the server, not restricted by the server) | +| storing | integer | Whether to save server information
0. Do not save
1. Save | +| binding_mode | string | Server Connection Method
"U" - UDP Method
"UQ" - UDP with Queue Mode
"S" - SMS Method
"SQ" - SMS with Queue Mode
"US" - UDP and SMS Methods
"UQS" - UDP and SMS with Queue Mode | +| mode | integer | terminal device name format
3 format: urn: imei: xxxxx
lwm2mserver configuration epname format | +| download | Integer | Download Mode
0 Manual Download
1 Automatic Download | +| update | integer | update mode
0 Manual update
1 Automatic update | +| URC_onoff | Integer | Enable URC reporting for LWm2m
0 Disable URC reporting
1 Enable URC reporting | + +Introduction to config_type parameter configuration type + +| Configuration type name | Corresponding config_list parameter | Remarks | +| ----------------------- | -------------------------------------------------------------------- | --------------------------------------------------------------- | +| Epnamemode | [mode] | | +| Reset | [] | Empty list | +| Security | [serverID, SSID,server_addr,bootstrap,security_mode,psk_id,psk_key] | | +| Server | [serverID, life_time,pmin,pmax,disable_timeout,storing,binding_mode] | | +| Urc | [URC_onoff] | If you want to capture URC, you must configure it to be enabled | +| Fota | [download, update] | If you want to crawl URLs, configure them to not be automatic | + +- Example + +```python +>>> config=[0,100," coaps://InteropBootstrap.dm.iot.att.com:5694 ",1,0,"urn:imei:864430010001095","313233343536"] +>>> lw.config(lw.Security,config) +0 +>>>   +``` + +## Register + +> lw.register() + +- Parameters + nothing + +- Return value + Return 0 for successful execution and -1 for failed execution. The registration result needs to be queried by calling the query interface. + +- Example + +```python +>>> lw.register() +0 +``` + +## Unregister + +> lw.unregister() + +- Parameters + nothing + +- Return value + Return 0 for successful execution and -1 for failed execution. The cancellation result needs to be queried by calling the query interface. + +- Example + +```python +>>> lw.unregister() +0 +``` + +## Check registration status + +> lw.stat() + +- Parameters + nothing + +- Return value + 0 Unregistered
1 Registering
2 Registered
3 Cancelling
+ 4 login failures + +- Example + +```python +>>> lw.stat() +0 +>>> lw.register() +0 +>>> lw.stat() +one +>>> lw.unregister() +0 +>>> lw.stat() +three +>>> +``` + +## Send heartbeat + +> lw.update(SSID) + +- Parameters + SSID : The configured SSID, or the SSID issued by BS. + +- Return value + Command success returns 0, command failure returns -1. The success or failure of the update is determined based on the "+QLWURC:" update "event. + +- Example + +```python +>>> lw.update(1) +0 +``` + +## Register callback function + +> lw.register_call(usrfun) + +- Parameters + Usrfun: function + Prototype of usrfun: usrfun (list) + Usrfun parameter: type list + List description: + + | Parameter Description | Parameter Type | Remarks | + | --------------------- | -------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | + | List [0] | int | Event type (can be ignored without processing) | + | List [1] | int | Event encoding (can be ignored without processing) | + | List [2] | string | The URC string data captured (please refer to [Event Description](#Event description) for specific event descriptions), and use this parameter to determine the connection event of Lwm2m | + +- Return value + Success returns 0, failure returns -1 + Note that if you want to delete a registered callback function, pass the parameter None + +- Example + +```python +>>> import lwm2m +>>> lw=lwm2m() +>>> def lwm2m_call(args): +... print('args{}'.format(args)) +... +... +... +>>> +>>> lw.register_call(lwm2m_call) +0 +>>> +>>> lw.register_call(None) +0 +>>> +>>> +``` + +## Support platform + +| Support Platform | Remarks | +| ---------------- | ------- | +| EC600UEU_AC_WS | | +| BG95M8_SANX | | +| BG95M8 | | +| EC200AAU_HA_SANX | | +| EC200AAU_HA | | +| EG915NEA_AC_SANX | | +| EG912NEN_AA_SANX | | +| EG912NEN_AA | | + +## Event description + +| Event type | Description | Remarks | +| ------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- | +| QLWURC: "pdp active", result, APN | PDP activation result. Before sending a registration request to LwM2M, the PDP server should be activated | Result: string type
"successful"
"failed"
APN: string type
APN value | +| QLWURC: "initial", result, SSID | The initialization result of the connection between the client and LwM2M server | Result: string type
"successful"
"failed"
SSID: shape type
0- all servers
other values - other special servers | +| +QLWURC: "dtls", result, SSID | DTLS handshake result when using encryption method | Same as above | +| QLWURC: "Bootstrap" | When Bootstrap is working, this URC will be reported | | +| QLWURC: "Bootstrap", result, SSID | Bootstrap's working result | Same as above | +| QLWURC: "registering" | This URC will be reported when the client registers on the LwM2M server | Same as above | +| QLWURC: "ready", result, SSID | The registration result after sending a registration request to the LwM2M server | Same as above | +| +QLWURC: "update", result, SSID | The update result after sending an update request to the LwM2M server | Same as above | +| +QLWURC: "registry", SSID, code
+QLWURC: "registry", code | The logout result after sending a logout request to the LwM2M server | SSID: Shaping type
0- All servers
Other values - Other special servers
Code: Shaping
0- Success
1- Failure
3- Unknown error | +| +QLWURC: "fota/pkghurl", URL | The URL address issued by LWM2M. | | +| +QLWURC: "apn_changed", APN | APN value issued by LWM2M. | | +| +QLWURC: "user_name_changed", user | User issued by LWM2M. | | +| QLWURC: "secret_changed", password | Password issued by LWM2M | | +| +QLWURC: "authentication_type_changed", | Authentication issued by LWM2M. | | +| QLWURC: "lifetime_changed", lifetime | The lifetime issued by LWM2M | | +| +QLWURC: "Current_time_changed", data_time | The data_time issued by LWM2M is added with UTC_OFFSET. | | + +###### Example usage + +```python +import utime +import lwm2m +import modem +import net +import checkNet +from machine import Pin +import _thread + +class lwm2m_client(): + + def __init__(self): + + self.lwm2m = lwm2m() + self.network_wait_time = 60 + self.host = "220.180.239.212" + self.port = "5563" + self.connect_state = 0 # 0 -init, 1- registing, 2-register failed, 3-register success. + self.connect_server_type = 0 # 0 - server, 1 - bsserver + self.imei = modem.getDevImei() + self.security_mode = 3 # 3 - no Pre-share key mode, 0 Pre-share key mode , 2 - x509 + self.epname_mode = 3 # 3 - urn:imei:+imei . 1 - user define epname + self.support_security_mode=[0,2,3] + + self.psk="urn:imei:{}".format(self.imei) + self.key="30313233343536373839" + + if self.security_mode == 3: + self.url = "coap://"+self.host +":"+ self.port + else: + self.url = "coaps://"+self.host +":"+ self.port + + self.config_security =[1,1000,self.url,self.connect_server_type,3] + self.config_epname = ["testname"] # only self.epname_mode = 1 will use it + self.config_epnamemde = [self.epname_mode] + self.config_foat = [0,1] + self.config_server = [1, 60, 2, 60, 86400, 1, "U"] + stage, state = checkNet.waitNetworkReady(30) + if stage == 3 and state == 1: + self.log('Network connection successful.') + else: + self.log('Network connection failed, stage={}, state={}'.format(stage, state)) + + def log(self,args): + print("[Lwm2m_client Info] {}".format(args)) + + def lwm2m_set_psk(self,psk="testname"): + if self.security_mode == 0: + self.psk = psk + else: + self.log("security_mode:{},not support config psk!".format(self.security_mode)) + + def lwm2m_set_key(self,key="30313233343536373839"): + if self.security_mode == 0: + self.key = key + else: + self.log("security_mode:{},not support config key!".format(self.security_mode)) + + + def lwm2m_set_server_host(self,url="220.180.239.212"): + self.host = url + self.lwm2m_update_connect_url() + + def lwm2m_update_connect_url(self): + if self.security_mode == 3: + self.url = "coap://"+self.host +":"+ self.port + else: + self.url = "coaps://"+self.host +":"+ self.port + + def lwm2m_set_epname(self,epname): + if self.epname_mode == 1: + self.config_epname = [epname] + else: + self.log("epname_mode :{},the mode not support set epame!!".format(self.epname_mode)) + + def lwm2m_set_server_port(self,port="5563"): + self.port = port + self.lwm2m_update_connect_url() + + def lwm2m_set_security_mode(self,mode=3): + if mode in self.support_security_mode: + self.security_mode = mode + self.lwm2m_update_connect_url() + else: + self.log("the security_mode {} not support !!".format(mode)) + self.log("current support security_mode :{}".format(self.support_security_mode)) + + def lwm2m_mesage_callback(self,args): + self.log("Get Lwm2m Server Data :{}".format(args)) + result=args[2] + if '"ready","successfully"' in result: + self.log('Connect Success!') + elif '"ready","failed"' in result: + self.log('Connect Failed!') + else: + pass + + def lwm2m_display_current_info(self): + self.log("/---display config information---\\") + self.log("lw.Security :{}".format(self.config_security)) + self.log("lw.config_server :{}".format(self.config_server)) + self.log("lw.Epnamemode :{}".format(self.config_epnamemde)) + if self.epname_mode == 1: + self.log("lw.epname :{}".format(self.config_epname)) + self.log("lw.Fota :{}".format(self.config_foat)) + self.log("\\---display config information---/") + + + def lwm2m_config_prepare(self): + config=[] + self.lwm2m.config(self.lwm2m.Reset,config) + config=[1] + self.lwm2m.config(self.lwm2m.Security,config) + config=[0] + self.lwm2m.config(self.lwm2m.Security,config) + + def lwm2m_set_connect_type(self,connect_type): + if connect_type == 1 or connect_type == 0: + self.connect_server_type = connect_type + else: + self.log("connect_type :{},not support!".format(connect_type)) + + def register_all_callback(self): + self.lwm2m.register_call(self.lwm2m_mesage_callback) + + def lwm2m_set_epname_mode(self,epname_mode = 3): + if epname_mode == 1 or epname_mode == 3: + self.epname_mode = epname_mode + else: + self.log("epname_mode :{},not support!".format(epname_mode)) + + def lwm2m_update_all_config(self): + + if self.connect_server_type == 0 : + # connect server + self.config_security=[1,1000,self.url,self.connect_server_type,self.security_mode] + if self.connect_server_type == 1 : + # connect bsserver + self.config_security=[0,100,self.url,self.connect_server_type,self.security_mode] + + if self.security_mode == 0: + # need psk + self.config_security.append(self.psk) + self.config_security.append(self.key) + self.config_epnamemde=[self.epname_mode] + + def lwm2m_config(self): + self.lwm2m_display_current_info() + self.log("wait 1s ,will start config profile infomation!") + utime.sleep(1) + + self.lwm2m.config(self.lwm2m.Security,self.config_security) + self.lwm2m.config(self.lwm2m.Server,self.config_server) + self.lwm2m.config(self.lwm2m.Epnamemode,self.config_epnamemde) + if self.epname_mode == 1: + self.lwm2m.config(self.lwm2m.Epname,self.config_epname) + self.lwm2m.config(self.lwm2m.Fota,self.config_foat) + + + def lwm2m_befor_run(self): + + # must clear dirty config,always run this function + self.lwm2m_config_prepare() + + # config security_mode :3-no PSK ,0 -psk + self.lwm2m_set_security_mode(0) + + # config lwm2mserver ip address + self.lwm2m_set_server_host("lwm2m-test.avsystem.io") + self.lwm2m_set_server_port("5684") + # config epname format : 3 - urn:imei:imei + epname_mode = 3 + self.lwm2m_set_epname_mode(epname_mode) + self.lwm2m_set_psk("urn:imei:869339060001965") + self.lwm2m_set_key("30313233343536373839") + + # config connect server or bsserver 0 - server 1 -bsserver + self.lwm2m_set_connect_type(0) + + # update config set + self.lwm2m_update_all_config() + self.lwm2m_config() + self.register_all_callback() + + def lwm2m_run(self): + self.lwm2m_befor_run() + self.lwm2m.register() + +lw=lwm2m_client() + +def th_lwm2m(args): + print('thread th_func1 {} is running, heap_size {}'.format(args,_thread.get_heap_size())) + global lw + lw.lwm2m_run() + +if __name__ == '__main__': + + _thread.start_new_thread(th_lwm2m, (list("r"))) +``` diff --git a/docs/API_reference/en/cloudlib/README.md b/docs/API_reference/en/cloudlib/README.md new file mode 100644 index 00000000..521809f1 --- /dev/null +++ b/docs/API_reference/en/cloudlib/README.md @@ -0,0 +1,8 @@ +# QuecPython IoT Platform + +> The QuecPython IoT platform library includes the Lwm2m platform. + + +## QuecPython IoT Platform Library List + +- [Lwm2m IoT Platform](./Lwm2m.md) diff --git a/docs/API_reference/en/sidebar.yaml b/docs/API_reference/en/sidebar.yaml index 0f83995d..06c83190 100644 --- a/docs/API_reference/en/sidebar.yaml +++ b/docs/API_reference/en/sidebar.yaml @@ -209,10 +209,15 @@ items: file: gnsslib/wifilocator.md - label: wifiScan - Wi-Fi Scan file: gnsslib/wifiScan.md +- label: Cloud Platform + file: cloudlib/README.md + items: + - label: Lwm2m Platform + file: cloudlib/Lwm2m.md - label: Component Library file: componentlib/README.md items: - label: uasyncio - Aoroutine file: componentlib/uasyncio.md - label: ErrorCode - file: errcode/README.md \ No newline at end of file + file: errcode/README.md diff --git a/docs/API_reference/zh/cloudlib/Lwm2m.md b/docs/API_reference/zh/cloudlib/Lwm2m.md new file mode 100644 index 00000000..037e170e --- /dev/null +++ b/docs/API_reference/zh/cloudlib/Lwm2m.md @@ -0,0 +1,453 @@ +# lwm2m-轻型物联网 + +## 创建对象 + +> lw=lwm2m() + +* 参数 + 无 +- 返回值 + lwm2m对象 + +- 示例 + +```python +>>> import lwm2m +>>> lw=lwm2m() +>>> +``` + +## 初始化对象 + +> lw.init() + +- 参数 + 无 + +- 返回值 + 成功: 0 + 失败: -1 + +- 示例 + +```python +>>> lw.init() +0 +>>> +``` + +## 配置对象 + +> lw.config(config_type,config_list) + +- 参数 + config_type:配置类型 + config_list : 列表类型,配置参数列表。 + +- 返回值 + 成功: 0 + 失败: -1 + 不支持:-2 + +用于config_list参数列表中的字段介绍 + +| 字段名 | 字段类型 | 字段说明 | +| --------------- | ---- | --------------------------------------------------------------------------------------------------------------------------------------------------- | +| serverID | 整型 | 0 Bootstrap server
1 DM server
| +| SSID | 整型 | 100 Bootstrap server
1000 Diagnostics server
| +| server_addr | 字符串 | 服务器地址,格式为:"address:port",最长支持256。 | +| bootstrap | 整型 | 0 不用bootstrap(仅当serverID不为0)
1 使用bootstrap (仅当serverID为0) | +| security_mode | 整型 | 加密方法:
0 Pre-share key mode
3 No security mode | +| psk_id | 字符串 | security_mode为0时有用 | +| psk_key | 字符串 | security_mode为0时有用 | +| life_time | 整型 | 生存时间,取值范围1~86400,默认值86400,单位秒 | +| pmin | 整型 | pmin默认周期,取值范围1~86400,默认值86400,单位秒 | +| pmax | 整型 | pmax默认周期,取值范围1~86400,默认值86400,单位秒 | +| disable_timeout | 整型 | 与 LwM2M 服务器断开连接后到下一个连接的时间间隔。范围为 1-86400,默认值为 86400,单位为秒
实测端口后可以立马连接。无效(上送给服务端的,服务端未限制)。 | +| storing | 整型 | 是否保存服务器信息
0.不保存
1.保存 | +| binding_mode | 字符串 | 和服务器连接方式
"U" - UDP方式
"UQ" - UDP有队列模式方式
"S" - SMS方式
"SQ" - SMS有队列模式方式
“US” - UDP和SMS方式
"UQS" - UDP和SMS有队列模式方式 | +| mode | 整型 | 终端设备名字格式
3 格式为: urn:imei:xxxxx
lwm2mserver配置epname格式 | +| download | 整型 | 下载模式
0 手动下载
1 自动下载 | +| update | 整型 | 更新模式
0 手动更新
1 自动更新 | +| URC_onoff | 整型 | 是否开启LWm2m的urc上报
0 禁用URC上报
1 启用URC上报 | + +config_type参数配置类型介绍 + +| 配置类型名 | 对应的config_list参数 | 备注 | +| ---------- | ------------------------------------------------------------------- | ----------------- | +| Epnamemode | [mode] | | +| Reset | [] | 空list | +| Security | [serverID,SSID,server_addr,bootstrap,security_mode,psk_id,psk_key] | | +| Server | [serverID,life_time,pmin,pmax,disable_timeout,storing,binding_mode] | | +| Urc | [URC_onoff] | 如果要抓取URC,必须配置开启 | +| Fota | [download,update] | 如果要抓取URL,配置成均不自动。 | + +- 示例 + +```python +>>> config=[0,100,"coaps://InteropBootstrap.dm.iot.att.com:5694",1,0,"urn:imei:864430010001095","313233343536"] +>>> lw.config(lw.Security,config) +0 +>>>   +``` + +## 注册 + +> lw.register() + +- 参数 + 无 + +- 返回值 + 执行成功返回0,执行失败返回-1。注册结果需要调用查询接口进行查询。 + +- 示例 + +```python +>>> lw.register() +0 +``` + + + +## 注销 + +> lw.unregister() + +- 参数 + 无 + +- 返回值 + 执行成功返回0,执行失败返回-1。注销结果需要调用查询接口进行查询。 + +- 示例 + +```python +>>> lw.unregister() +0 +``` + + + +## 查询注册状态 + +> lw.stat() + +- 参数 + 无 + +- 返回值 + 0 未注册
1 注册中
2 已注册
3 注销中
+ 4 登录失败 + +- 示例 + +```python +>>> lw.stat() +0 +>>> lw.register() +0 +>>> lw.stat() +1 +>>> lw.unregister() +0 +>>> lw.stat() +3 +>>> +``` + +## 发送心跳 + +> lw.update(SSID) + +- 参数 + SSID : 配置的SSID,或者BS下发的SSID。 + +- 返回值 + 指令成功返回0,指令失败返回-1.更新成功或失败结果根据“+QLWURC: "update"事件进行判断。 + +- 示例 + +```python +>>> lw.update(1) +0 +``` + + + +## 注册回调函数 + +> lw.register_call(usrfun) + +- 参数 + usrfun:函数 + usrfun原型:usrfun(list) + usrfun参数:类型list + list说明: + +| 参数明 | 参数类型 | 备注说明 | +| ------- | ------ | ------------------------------------------------------- | +| list[0] | int | 事件类型(可以不处理忽略) | +| list[1] | int | 事件编码(可以不处理忽略) | +| list[2] | string | 抓取到的URC字符串数据(具体事件说明请参考[事件说明](#事件说明)),以此参数判断Lwm2m的连接事件为准 | + +- 返回值 + 成功返回0,失败返回-1. + 注意如果要删除已经注册的回调函数,传入参数None. + +- 示例 + +```python +>>> import lwm2m +>>> lw=lwm2m() +>>> def lwm2m_call(args): +... print('args{}'.format(args)) +... +... +... +>>> +>>> lw.register_call(lwm2m_call) +0 +>>> +>>> lw.register_call(None) +0 +>>> + +>>> +``` + +## 支持平台 + +| 支持平台 | 备注 | +| ----------- | ---------------------------- | +| EC600UEU_AC | 公版不支持,定制型号支持 | +| BG95M8 | | +| BG95M3 | | +| EC200AAU_HA | | +| EG915NEA_AC | 公版不支持,定制型号支持 | +| EG912NEN_AA | | + +## 事件说明 + +| 事件类型 | 说明 | 备注 | +| -------------------------------------------------------------- | --------------------------------------- | ------------------------------------------------------------------------------------------------ | +| +QLWURC: "pdp active",result,APN | PDP的激活结果。在向 LwM2M 发送注册请求之前,应激活 PDP 服务器。 | result:string类型
"successfully"
"failed"
APN:string类型
APN值 | +| +QLWURC: "initial",result,SSID | 客户端与LwM2M服务器连接的初始化结果。 | result:string类型
"successfully"
"failed"
SSID:整形类型
0-所有的服务器
其他值-其他的特殊服务器 | +| +QLWURC: "dtls",result,SSID | 使用加密方法时的 DTLS 握手结果。 | 同上 | +| +QLWURC: "bootstraping" | 当 Bootstrap 工作时,将报告此 URC。 | | +| +QLWURC: "bootstrap",result,SSID | Bootstrap 的工作结果。 | 同上 | +| +QLWURC: "registering" | 当客户端在 LwM2M 服务器上注册时将报告此 URC。 | 同上 | +| +QLWURC: "ready",result,SSID | 向LwM2M服务器发送注册请求后的注册结果。 | 同上 | +| +QLWURC: "update",result,SSID | 向LwM2M服务器发送更新请求后的更新结果。 | 同上 | +| +QLWURC: "deregister",SSID,code
+QLWURC: "deregister",code | 向LwM2M服务器发送注销请求后的注销结果。 | SSID:整形类型
0-所有的服务器
其他值-其他的特殊服务器
Code:整形
0-成功
1-失败
3-未知错误 | +| +QLWURC: "fota/pkgurl",url | LWM2M下发的url地址。 | | +| +QLWURC: "apn_changed",APN | LWM2M下发的APN值。 | | +| +QLWURC: "user_name_changed",user | LWM2M下发的user。 | | +| +QLWURC: "secret_changed",password | LWM2M下发的password。 | | +| +QLWURC: "authentication_type_changed", | LWM2M下发的Authentication。 | | +| +QLWURC: "lifetime_changed",lifetime | LWM2M下发的lifetime。 | | +| +QLWURC: "current_time_changed",data_time | LWM2M下发的data_time加UTC_OFFSET。 | | + + + +###### 使用示例 + +```python +import utime +import lwm2m +import modem +import net +import checkNet +from machine import Pin +import _thread + +class lwm2m_client(): + + def __init__(self): + + self.lwm2m = lwm2m() + self.network_wait_time = 60 + self.host = "220.180.239.212" + self.port = "5563" + self.connect_state = 0 # 0 -init, 1- registing, 2-register failed, 3-register success. + self.connect_server_type = 0 # 0 - server, 1 - bsserver + self.imei = modem.getDevImei() + self.security_mode = 3 # 3 - no Pre-share key mode, 0 Pre-share key mode , 2 - x509 + self.epname_mode = 3 # 3 - urn:imei:+imei . 1 - user define epname + self.support_security_mode=[0,2,3] + + self.psk="urn:imei:{}".format(self.imei) + self.key="30313233343536373839" + + if self.security_mode == 3: + self.url = "coap://"+self.host +":"+ self.port + else: + self.url = "coaps://"+self.host +":"+ self.port + + self.config_security =[1,1000,self.url,self.connect_server_type,3] + self.config_epname = ["testname"] # only self.epname_mode = 1 will use it + self.config_epnamemde = [self.epname_mode] + self.config_foat = [0,1] + self.config_server = [1, 60, 2, 60, 86400, 1, "U"] + stage, state = checkNet.waitNetworkReady(30) + if stage == 3 and state == 1: + self.log('Network connection successful.') + else: + self.log('Network connection failed, stage={}, state={}'.format(stage, state)) + + def log(self,args): + print("[Lwm2m_client Info] {}".format(args)) + + def lwm2m_set_psk(self,psk="testname"): + if self.security_mode == 0: + self.psk = psk + else: + self.log("security_mode:{},not support config psk!".format(self.security_mode)) + + def lwm2m_set_key(self,key="30313233343536373839"): + if self.security_mode == 0: + self.key = key + else: + self.log("security_mode:{},not support config key!".format(self.security_mode)) + + + def lwm2m_set_server_host(self,url="220.180.239.212"): + self.host = url + self.lwm2m_update_connect_url() + + def lwm2m_update_connect_url(self): + if self.security_mode == 3: + self.url = "coap://"+self.host +":"+ self.port + else: + self.url = "coaps://"+self.host +":"+ self.port + + def lwm2m_set_epname(self,epname): + if self.epname_mode == 1: + self.config_epname = [epname] + else: + self.log("epname_mode :{},the mode not support set epame!!".format(self.epname_mode)) + + def lwm2m_set_server_port(self,port="5563"): + self.port = port + self.lwm2m_update_connect_url() + + def lwm2m_set_security_mode(self,mode=3): + if mode in self.support_security_mode: + self.security_mode = mode + self.lwm2m_update_connect_url() + else: + self.log("the security_mode {} not support !!".format(mode)) + self.log("current support security_mode :{}".format(self.support_security_mode)) + + def lwm2m_mesage_callback(self,args): + self.log("Get Lwm2m Server Data :{}".format(args)) + result=args[2] + if '"ready","successfully"' in result: + self.log('Connect Success!') + elif '"ready","failed"' in result: + self.log('Connect Failed!') + else: + pass + + def lwm2m_display_current_info(self): + self.log("/---display config information---\\") + self.log("lw.Security :{}".format(self.config_security)) + self.log("lw.config_server :{}".format(self.config_server)) + self.log("lw.Epnamemode :{}".format(self.config_epnamemde)) + if self.epname_mode == 1: + self.log("lw.epname :{}".format(self.config_epname)) + self.log("lw.Fota :{}".format(self.config_foat)) + self.log("\\---display config information---/") + + + def lwm2m_config_prepare(self): + config=[] + self.lwm2m.config(self.lwm2m.Reset,config) + config=[1] + self.lwm2m.config(self.lwm2m.Security,config) + config=[0] + self.lwm2m.config(self.lwm2m.Security,config) + + def lwm2m_set_connect_type(self,connect_type): + if connect_type == 1 or connect_type == 0: + self.connect_server_type = connect_type + else: + self.log("connect_type :{},not support!".format(connect_type)) + + def register_all_callback(self): + self.lwm2m.register_call(self.lwm2m_mesage_callback) + + def lwm2m_set_epname_mode(self,epname_mode = 3): + if epname_mode == 1 or epname_mode == 3: + self.epname_mode = epname_mode + else: + self.log("epname_mode :{},not support!".format(epname_mode)) + + def lwm2m_update_all_config(self): + + if self.connect_server_type == 0 : + # connect server + self.config_security=[1,1000,self.url,self.connect_server_type,self.security_mode] + if self.connect_server_type == 1 : + # connect bsserver + self.config_security=[0,100,self.url,self.connect_server_type,self.security_mode] + + if self.security_mode == 0: + # need psk + self.config_security.append(self.psk) + self.config_security.append(self.key) + self.config_epnamemde=[self.epname_mode] + + def lwm2m_config(self): + self.lwm2m_display_current_info() + self.log("wait 1s ,will start config profile infomation!") + utime.sleep(1) + + self.lwm2m.config(self.lwm2m.Security,self.config_security) + self.lwm2m.config(self.lwm2m.Server,self.config_server) + self.lwm2m.config(self.lwm2m.Epnamemode,self.config_epnamemde) + if self.epname_mode == 1: + self.lwm2m.config(self.lwm2m.Epname,self.config_epname) + self.lwm2m.config(self.lwm2m.Fota,self.config_foat) + + + def lwm2m_befor_run(self): + + # must clear dirty config,always run this function + self.lwm2m_config_prepare() + + # config security_mode :3-no PSK ,0 -psk + self.lwm2m_set_security_mode(0) + + # config lwm2mserver ip address + self.lwm2m_set_server_host("lwm2m-test.avsystem.io") + self.lwm2m_set_server_port("5684") + # config epname format : 3 - urn:imei:imei + epname_mode = 3 + self.lwm2m_set_epname_mode(epname_mode) + self.lwm2m_set_psk("urn:imei:869339060001965") + self.lwm2m_set_key("30313233343536373839") + + # config connect server or bsserver 0 - server 1 -bsserver + self.lwm2m_set_connect_type(0) + + # update config set + self.lwm2m_update_all_config() + self.lwm2m_config() + self.register_all_callback() + + def lwm2m_run(self): + self.lwm2m_befor_run() + self.lwm2m.register() + +lw=lwm2m_client() + +def th_lwm2m(args): + print('thread th_func1 {} is running, heap_size {}'.format(args,_thread.get_heap_size())) + global lw + lw.lwm2m_run() + +if __name__ == '__main__': + + _thread.start_new_thread(th_lwm2m, (list("r"))) +``` diff --git a/docs/API_reference/zh/cloudlib/README.md b/docs/API_reference/zh/cloudlib/README.md index 6afbfdd2..cbf3d344 100644 --- a/docs/API_reference/zh/cloudlib/README.md +++ b/docs/API_reference/zh/cloudlib/README.md @@ -7,3 +7,4 @@ - [aLiYun - 阿里 IoT 平台](./aLiYun.md) - [TenCentYun- 腾讯 IoT 平台](./TenCentYun.md) +- [Lwm2m IoT 平台](./Lwm2m.md) diff --git a/docs/API_reference/zh/sidebar.yaml b/docs/API_reference/zh/sidebar.yaml index 1aebaeba..3105ab97 100644 --- a/docs/API_reference/zh/sidebar.yaml +++ b/docs/API_reference/zh/sidebar.yaml @@ -217,10 +217,12 @@ items: file: cloudlib/aLiYun.md - label: TenCentYun- 腾讯 IoT 平台 file: cloudlib/TenCentYun.md + - label: Lwm2m - Lwm2m 平台 + file: cloudlib/Lwm2m.md - label: 开源组件 file: componentlib/README.md items: - label: uasyncio - 协程 file: componentlib/uasyncio.md - label: 错误码 - file: errcode/README.md \ No newline at end of file + file: errcode/README.md -- Gitee From 8dd8e5e5594781e4f1d50c02bff1de97f6c5c7a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=9B=BD=E4=BC=9F?= Date: Mon, 29 Jul 2024 08:48:12 +0000 Subject: [PATCH 03/14] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20do?= =?UTF-8?q?cs/API=5Freference/en/cloudlib/Lwm2m.mdbak?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/API_reference/en/cloudlib/Lwm2m.mdbak | 447 --------------------- 1 file changed, 447 deletions(-) delete mode 100644 docs/API_reference/en/cloudlib/Lwm2m.mdbak diff --git a/docs/API_reference/en/cloudlib/Lwm2m.mdbak b/docs/API_reference/en/cloudlib/Lwm2m.mdbak deleted file mode 100644 index 4ef2c193..00000000 --- a/docs/API_reference/en/cloudlib/Lwm2m.mdbak +++ /dev/null @@ -1,447 +0,0 @@ -# LWM2M - Lightweight Internet of Things - -## Create object - -> lw=lwm2m() - -- Parameters - No - -- Return value - Lwm2m object - -- Example - - ```python - >>> import lwm2m - >>> lw=lwm2m() - >>> - ``` - -## Initialize object - -> lw.init() - -- Parameters - No - -- Return value - Success: 0 - Failed: -1 - -- Example - -```python ->>> lw.init() -0 ->>> -``` - -## Configure objects - -> lw.config(config_type,config_list) - -- Parameters - config_type: Configuration type - config_list : List type, configuration parameter list. - -- Return value - Success: 0 - Failed: -1 - Not supported: -2 - -Introduction to fields in the config_list parameter list - -| Field Name | Field Type | Field Description | -| --------------- | ---------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| serverID | integer | 0 Bootstrap server
1 DM server
| -| SSID | integer | 100 Bootstrap server
1000 Diagnostics server
| -| server_addr | string | Server Address, in the format of "address: port", supports a maximum length of 256 | -| bootstrap | integer | 0. No need to use bootstrap (only if server ID is not 0)
1. Use bootstrap (only if server ID is 0) | -| security_mode | integer | encryption method:
0 Pre share key mode
3 No security mode | -| psk_id | string | useful when secure_mode is 0 | -| psk_key | string | useful when secure_mode is 0 | -| life_time | integer | lifetime, value range 1~86400, default value 86400, unit: seconds | -| pmin | integer | minimum response period, value range 1~86400, default value 86400, unit: seconds | -| pmax | integer | Maximum response period, value range 1~86400, default value 86400, unit: seconds | -| disable_timeout | integer | The time interval from disconnecting from the LwM2M server to the next connection. The range is 1-86400, with a default value of 86400 and a unit of seconds. After testing the port, it can be immediately connected. Invalid (sent to the server, not restricted by the server) | -| storing | integer | Whether to save server information
0. Do not save
1. Save | -| binding_mode | string | Server Connection Method
"U" - UDP Method
"UQ" - UDP with Queue Mode
"S" - SMS Method
"SQ" - SMS with Queue Mode
"US" - UDP and SMS Methods
"UQS" - UDP and SMS with Queue Mode | -| mode | integer | terminal device name format
3 format: urn: imei: xxxxx
lwm2mserver configuration epname format | -| download | Integer | Download Mode
0 Manual Download
1 Automatic Download | -| update | integer | update mode
0 Manual update
1 Automatic update | -| URC_onoff | Integer | Enable URC reporting for LWm2m
0 Disable URC reporting
1 Enable URC reporting | - -Introduction to config_type parameter configuration type - -| Configuration type name | Corresponding config_list parameter | Remarks | -| ----------------------- | -------------------------------------------------------------------- | --------------------------------------------------------------- | -| Epnamemode | [mode] | | -| Reset | [] | Empty list | -| Security | [serverID, SSID,server_addr,bootstrap,security_mode,psk_id,psk_key] | | -| Server | [serverID, life_time,pmin,pmax,disable_timeout,storing,binding_mode] | | -| Urc | [URC_onoff] | If you want to capture URC, you must configure it to be enabled | -| Fota | [download, update] | If you want to crawl URLs, configure them to not be automatic | - -- Example - -```python ->>> config=[0,100," coaps://InteropBootstrap.dm.iot.att.com:5694 ",1,0,"urn:imei:864430010001095","313233343536"] ->>> lw.config(lw.Security,config) -0 ->>>   -``` - -## Register - -> lw.register() - -- Parameters - nothing - -- Return value - Return 0 for successful execution and -1 for failed execution. The registration result needs to be queried by calling the query interface. - -- Example - -```python ->>> lw.register() -0 -``` - -## Unregister - -> lw.unregister() - -- Parameters - nothing - -- Return value - Return 0 for successful execution and -1 for failed execution. The cancellation result needs to be queried by calling the query interface. - -- Example - -```python ->>> lw.unregister() -0 -``` - -## Check registration status - -> lw.stat() - -- Parameters - nothing - -- Return value - 0 Unregistered
1 Registering
2 Registered
3 Cancelling
- 4 login failures - -- Example - -```python ->>> lw.stat() -0 ->>> lw.register() -0 ->>> lw.stat() -one ->>> lw.unregister() -0 ->>> lw.stat() -three ->>> -``` - -## Send heartbeat - -> lw.update(SSID) - -- Parameters - SSID : The configured SSID, or the SSID issued by BS. - -- Return value - Command success returns 0, command failure returns -1. The success or failure of the update is determined based on the "+QLWURC:" update "event. - -- Example - -```python ->>> lw.update(1) -0 -``` - -## Register callback function - -> lw.register_call(usrfun) - -- Parameters - Usrfun: function - Prototype of usrfun: usrfun (list) - Usrfun parameter: type list - List description: - - | Parameter Description | Parameter Type | Remarks | - | --------------------- | -------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | - | List [0] | int | Event type (can be ignored without processing) | - | List [1] | int | Event encoding (can be ignored without processing) | - | List [2] | string | The URC string data captured (please refer to [Event Description](#Event description) for specific event descriptions), and use this parameter to determine the connection event of Lwm2m | - -- Return value - Success returns 0, failure returns -1 - Note that if you want to delete a registered callback function, pass the parameter None - -- Example - -```python ->>> import lwm2m ->>> lw=lwm2m() ->>> def lwm2m_call(args): -... print('args{}'.format(args)) -... -... -... ->>> ->>> lw.register_call(lwm2m_call) -0 ->>> ->>> lw.register_call(None) -0 ->>> ->>> -``` - -## Support platform - -| Support Platform | Remarks | -| ---------------- | ------- | -| EC600UEU_AC_WS | | -| BG95M8_SANX | | -| BG95M8 | | -| EC200AAU_HA_SANX | | -| EC200AAU_HA | | -| EG915NEA_AC_SANX | | -| EG912NEN_AA_SANX | | -| EG912NEN_AA | | - -## Event description - -| Event type | Description | Remarks | -| ------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- | -| QLWURC: "pdp active", result, APN | PDP activation result. Before sending a registration request to LwM2M, the PDP server should be activated | Result: string type
"successful"
"failed"
APN: string type
APN value | -| QLWURC: "initial", result, SSID | The initialization result of the connection between the client and LwM2M server | Result: string type
"successful"
"failed"
SSID: shape type
0- all servers
other values - other special servers | -| +QLWURC: "dtls", result, SSID | DTLS handshake result when using encryption method | Same as above | -| QLWURC: "Bootstrap" | When Bootstrap is working, this URC will be reported | | -| QLWURC: "Bootstrap", result, SSID | Bootstrap's working result | Same as above | -| QLWURC: "registering" | This URC will be reported when the client registers on the LwM2M server | Same as above | -| QLWURC: "ready", result, SSID | The registration result after sending a registration request to the LwM2M server | Same as above | -| +QLWURC: "update", result, SSID | The update result after sending an update request to the LwM2M server | Same as above | -| +QLWURC: "registry", SSID, code
+QLWURC: "registry", code | The logout result after sending a logout request to the LwM2M server | SSID: Shaping type
0- All servers
Other values - Other special servers
Code: Shaping
0- Success
1- Failure
3- Unknown error | -| +QLWURC: "fota/pkghurl", URL | The URL address issued by LWM2M. | | -| +QLWURC: "apn_changed", APN | APN value issued by LWM2M. | | -| +QLWURC: "user_name_changed", user | User issued by LWM2M. | | -| QLWURC: "secret_changed", password | Password issued by LWM2M | | -| +QLWURC: "authentication_type_changed", | Authentication issued by LWM2M. | | -| QLWURC: "lifetime_changed", lifetime | The lifetime issued by LWM2M | | -| +QLWURC: "Current_time_changed", data_time | The data_time issued by LWM2M is added with UTC_OFFSET. | | - -###### Example usage - -```python -import utime -import lwm2m -import modem -import net -import checkNet -from machine import Pin -import _thread - -class lwm2m_client(): - - def __init__(self): - - self.lwm2m = lwm2m() - self.network_wait_time = 60 - self.host = "220.180.239.212" - self.port = "5563" - self.connect_state = 0 # 0 -init, 1- registing, 2-register failed, 3-register success. - self.connect_server_type = 0 # 0 - server, 1 - bsserver - self.imei = modem.getDevImei() - self.security_mode = 3 # 3 - no Pre-share key mode, 0 Pre-share key mode , 2 - x509 - self.epname_mode = 3 # 3 - urn:imei:+imei . 1 - user define epname - self.support_security_mode=[0,2,3] - - self.psk="urn:imei:{}".format(self.imei) - self.key="30313233343536373839" - - if self.security_mode == 3: - self.url = "coap://"+self.host +":"+ self.port - else: - self.url = "coaps://"+self.host +":"+ self.port - - self.config_security =[1,1000,self.url,self.connect_server_type,3] - self.config_epname = ["testname"] # only self.epname_mode = 1 will use it - self.config_epnamemde = [self.epname_mode] - self.config_foat = [0,1] - self.config_server = [1, 60, 2, 60, 86400, 1, "U"] - stage, state = checkNet.waitNetworkReady(30) - if stage == 3 and state == 1: - self.log('Network connection successful.') - else: - self.log('Network connection failed, stage={}, state={}'.format(stage, state)) - - def log(self,args): - print("[Lwm2m_client Info] {}".format(args)) - - def lwm2m_set_psk(self,psk="testname"): - if self.security_mode == 0: - self.psk = psk - else: - self.log("security_mode:{},not support config psk!".format(self.security_mode)) - - def lwm2m_set_key(self,key="30313233343536373839"): - if self.security_mode == 0: - self.key = key - else: - self.log("security_mode:{},not support config key!".format(self.security_mode)) - - - def lwm2m_set_server_host(self,url="220.180.239.212"): - self.host = url - self.lwm2m_update_connect_url() - - def lwm2m_update_connect_url(self): - if self.security_mode == 3: - self.url = "coap://"+self.host +":"+ self.port - else: - self.url = "coaps://"+self.host +":"+ self.port - - def lwm2m_set_epname(self,epname): - if self.epname_mode == 1: - self.config_epname = [epname] - else: - self.log("epname_mode :{},the mode not support set epame!!".format(self.epname_mode)) - - def lwm2m_set_server_port(self,port="5563"): - self.port = port - self.lwm2m_update_connect_url() - - def lwm2m_set_security_mode(self,mode=3): - if mode in self.support_security_mode: - self.security_mode = mode - self.lwm2m_update_connect_url() - else: - self.log("the security_mode {} not support !!".format(mode)) - self.log("current support security_mode :{}".format(self.support_security_mode)) - - def lwm2m_mesage_callback(self,args): - self.log("Get Lwm2m Server Data :{}".format(args)) - result=args[2] - if '"ready","successfully"' in result: - self.log('Connect Success!') - elif '"ready","failed"' in result: - self.log('Connect Failed!') - else: - pass - - def lwm2m_display_current_info(self): - self.log("/---display config information---\\") - self.log("lw.Security :{}".format(self.config_security)) - self.log("lw.config_server :{}".format(self.config_server)) - self.log("lw.Epnamemode :{}".format(self.config_epnamemde)) - if self.epname_mode == 1: - self.log("lw.epname :{}".format(self.config_epname)) - self.log("lw.Fota :{}".format(self.config_foat)) - self.log("\\---display config information---/") - - - def lwm2m_config_prepare(self): - config=[] - self.lwm2m.config(self.lwm2m.Reset,config) - config=[1] - self.lwm2m.config(self.lwm2m.Security,config) - config=[0] - self.lwm2m.config(self.lwm2m.Security,config) - - def lwm2m_set_connect_type(self,connect_type): - if connect_type == 1 or connect_type == 0: - self.connect_server_type = connect_type - else: - self.log("connect_type :{},not support!".format(connect_type)) - - def register_all_callback(self): - self.lwm2m.register_call(self.lwm2m_mesage_callback) - - def lwm2m_set_epname_mode(self,epname_mode = 3): - if epname_mode == 1 or epname_mode == 3: - self.epname_mode = epname_mode - else: - self.log("epname_mode :{},not support!".format(epname_mode)) - - def lwm2m_update_all_config(self): - - if self.connect_server_type == 0 : - # connect server - self.config_security=[1,1000,self.url,self.connect_server_type,self.security_mode] - if self.connect_server_type == 1 : - # connect bsserver - self.config_security=[0,100,self.url,self.connect_server_type,self.security_mode] - - if self.security_mode == 0: - # need psk - self.config_security.append(self.psk) - self.config_security.append(self.key) - self.config_epnamemde=[self.epname_mode] - - def lwm2m_config(self): - self.lwm2m_display_current_info() - self.log("wait 1s ,will start config profile infomation!") - utime.sleep(1) - - self.lwm2m.config(self.lwm2m.Security,self.config_security) - self.lwm2m.config(self.lwm2m.Server,self.config_server) - self.lwm2m.config(self.lwm2m.Epnamemode,self.config_epnamemde) - if self.epname_mode == 1: - self.lwm2m.config(self.lwm2m.Epname,self.config_epname) - self.lwm2m.config(self.lwm2m.Fota,self.config_foat) - - - def lwm2m_befor_run(self): - - # must clear dirty config,always run this function - self.lwm2m_config_prepare() - - # config security_mode :3-no PSK ,0 -psk - self.lwm2m_set_security_mode(0) - - # config lwm2mserver ip address - self.lwm2m_set_server_host("lwm2m-test.avsystem.io") - self.lwm2m_set_server_port("5684") - # config epname format : 3 - urn:imei:imei - epname_mode = 3 - self.lwm2m_set_epname_mode(epname_mode) - self.lwm2m_set_psk("urn:imei:869339060001965") - self.lwm2m_set_key("30313233343536373839") - - # config connect server or bsserver 0 - server 1 -bsserver - self.lwm2m_set_connect_type(0) - - # update config set - self.lwm2m_update_all_config() - self.lwm2m_config() - self.register_all_callback() - - def lwm2m_run(self): - self.lwm2m_befor_run() - self.lwm2m.register() - -lw=lwm2m_client() - -def th_lwm2m(args): - print('thread th_func1 {} is running, heap_size {}'.format(args,_thread.get_heap_size())) - global lw - lw.lwm2m_run() - -if __name__ == '__main__': - - _thread.start_new_thread(th_lwm2m, (list("r"))) -``` -- Gitee From c141402842415aec94411c5c731a8e45f52513d7 Mon Sep 17 00:00:00 2001 From: "burols.wang" Date: Mon, 29 Jul 2024 16:52:04 +0800 Subject: [PATCH 04/14] =?UTF-8?q?=20(lwm2m):=20=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 固件版本: N 是否需要文案翻译: 否 --- docs/API_reference/en/cloudlib/Lwm2m.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/API_reference/en/cloudlib/Lwm2m.md b/docs/API_reference/en/cloudlib/Lwm2m.md index 371a765e..3cc6a88e 100644 --- a/docs/API_reference/en/cloudlib/Lwm2m.md +++ b/docs/API_reference/en/cloudlib/Lwm2m.md @@ -180,11 +180,11 @@ three Usrfun parameter: type list List description: - | Parameter Description | Parameter Type | Remarks | - | --------------------- | -------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | - | List [0] | int | Event type (can be ignored without processing) | - | List [1] | int | Event encoding (can be ignored without processing) | - | List [2] | string | The URC string data captured (please refer to [Event Description](#Event description) for specific event descriptions), and use this parameter to determine the connection event of Lwm2m | +| Parameter Description | Parameter Type | Remarks | +| --------------------- | -------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| List [0] | int | Event type (can be ignored without processing) | +| List [1] | int | Event encoding (can be ignored without processing) | +| List [2] | string | The URC string data captured (please refer to [Event Description](#Event description) for specific event descriptions), and use this parameter to determine the connection event of Lwm2m | - Return value Success returns 0, failure returns -1 -- Gitee From d90dae50f664b320bce4d4306af6f9852ec0de3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=9B=BD=E4=BC=9F?= Date: Mon, 29 Jul 2024 09:01:25 +0000 Subject: [PATCH 05/14] update docs/API_reference/en/cloudlib/Lwm2m.md. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 王国伟 --- docs/API_reference/en/cloudlib/Lwm2m.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/API_reference/en/cloudlib/Lwm2m.md b/docs/API_reference/en/cloudlib/Lwm2m.md index 371a765e..3cc6a88e 100644 --- a/docs/API_reference/en/cloudlib/Lwm2m.md +++ b/docs/API_reference/en/cloudlib/Lwm2m.md @@ -180,11 +180,11 @@ three Usrfun parameter: type list List description: - | Parameter Description | Parameter Type | Remarks | - | --------------------- | -------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | - | List [0] | int | Event type (can be ignored without processing) | - | List [1] | int | Event encoding (can be ignored without processing) | - | List [2] | string | The URC string data captured (please refer to [Event Description](#Event description) for specific event descriptions), and use this parameter to determine the connection event of Lwm2m | +| Parameter Description | Parameter Type | Remarks | +| --------------------- | -------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| List [0] | int | Event type (can be ignored without processing) | +| List [1] | int | Event encoding (can be ignored without processing) | +| List [2] | string | The URC string data captured (please refer to [Event Description](#Event description) for specific event descriptions), and use this parameter to determine the connection event of Lwm2m | - Return value Success returns 0, failure returns -1 -- Gitee From 935e6a4b40a6ce6e164ade4141537b67f85b1ee9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=9B=BD=E4=BC=9F?= Date: Mon, 29 Jul 2024 09:08:30 +0000 Subject: [PATCH 06/14] update docs/API_reference/en/cloudlib/Lwm2m.md. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 王国伟 --- docs/API_reference/en/cloudlib/Lwm2m.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/API_reference/en/cloudlib/Lwm2m.md b/docs/API_reference/en/cloudlib/Lwm2m.md index 3cc6a88e..14f3e0e9 100644 --- a/docs/API_reference/en/cloudlib/Lwm2m.md +++ b/docs/API_reference/en/cloudlib/Lwm2m.md @@ -264,8 +264,8 @@ class lwm2m_client(): self.connect_state = 0 # 0 -init, 1- registing, 2-register failed, 3-register success. self.connect_server_type = 0 # 0 - server, 1 - bsserver self.imei = modem.getDevImei() - self.security_mode = 3 # 3 - no Pre-share key mode, 0 Pre-share key mode , 2 - x509 - self.epname_mode = 3 # 3 - urn:imei:+imei . 1 - user define epname + self.security_mode = 3 # 3 - no Pre-share key mode, 0 Pre-share key mode + self.epname_mode = 3 # 3 - urn:imei:+imei self.support_security_mode=[0,2,3] self.psk="urn:imei:{}".format(self.imei) -- Gitee From 6b3b921ed94c4d000f928a68f903adebb44195a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=9B=BD=E4=BC=9F?= Date: Mon, 29 Jul 2024 09:09:26 +0000 Subject: [PATCH 07/14] update docs/API_reference/zh/cloudlib/Lwm2m.md. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 王国伟 --- docs/API_reference/zh/cloudlib/Lwm2m.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/API_reference/zh/cloudlib/Lwm2m.md b/docs/API_reference/zh/cloudlib/Lwm2m.md index 037e170e..41591544 100644 --- a/docs/API_reference/zh/cloudlib/Lwm2m.md +++ b/docs/API_reference/zh/cloudlib/Lwm2m.md @@ -272,8 +272,8 @@ class lwm2m_client(): self.connect_state = 0 # 0 -init, 1- registing, 2-register failed, 3-register success. self.connect_server_type = 0 # 0 - server, 1 - bsserver self.imei = modem.getDevImei() - self.security_mode = 3 # 3 - no Pre-share key mode, 0 Pre-share key mode , 2 - x509 - self.epname_mode = 3 # 3 - urn:imei:+imei . 1 - user define epname + self.security_mode = 3 # 3 - no Pre-share key mode, 0 Pre-share key mode + self.epname_mode = 3 # 3 - urn:imei:+imei . self.support_security_mode=[0,2,3] self.psk="urn:imei:{}".format(self.imei) -- Gitee From 6376c5aad6ccf5223bde2153e0abd60d4ec24016 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=9B=BD=E4=BC=9F?= Date: Tue, 3 Sep 2024 08:47:25 +0000 Subject: [PATCH 08/14] update docs/API_reference/zh/stdlib/utime.md. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 王国伟 --- docs/API_reference/zh/stdlib/utime.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/API_reference/zh/stdlib/utime.md b/docs/API_reference/zh/stdlib/utime.md index 48df3731..e629480d 100644 --- a/docs/API_reference/zh/stdlib/utime.md +++ b/docs/API_reference/zh/stdlib/utime.md @@ -88,7 +88,7 @@ utime.localtime_ex(secs) **参数描述:** - 无参数。返回当前本地时间(UTC+时区)。 -- 有参数,`secs`-int类型,单位秒。返回secs代表的UTC日期时间加设备设置的时区后的日期时间,例如,当前设备时区为3,secs转成UTC时间日期为2024-07-09 16:30:00,这此函数返回时间为,2024-07-09 19:30:00 。 +- 有参数,`secs`-int类型,单位秒。返回secs代表的UTC日期时间加设备设置的时区后的日期时间,例如,当前设备时区为3,secs转成UTC时间日期为2024-07-09 16:30:00,此函数返回时间为,2024-07-09 19:30:00 。 **返回值描述:** -- Gitee From f3cfb50170f38cd3f2b5e85a4b0d48875ec1f03f Mon Sep 17 00:00:00 2001 From: "burols.wang" Date: Wed, 18 Sep 2024 11:49:51 +0800 Subject: [PATCH 09/14] =?UTF-8?q?=20(sms):=20EC600M=E7=89=88?= =?UTF-8?q?=E6=9C=AC=E5=B1=9E=E4=BA=8EASR1606=EF=BC=8C=E6=B2=A1=E6=9C=89?= =?UTF-8?q?=E5=BC=80=E9=95=BF=E7=9F=AD=E4=BF=A1=E5=8A=9F=E8=83=BD=EF=BC=8C?= =?UTF-8?q?=E4=B9=9F=E6=9C=AA=E8=B0=83=E8=BF=87=EF=BC=8C=E6=8F=8F=E8=BF=B0?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit <修改点详述>(可选) 固件版本: N 是否需要文案翻译: 是 --- docs/API_reference/zh/iotlib/sms.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/API_reference/zh/iotlib/sms.md b/docs/API_reference/zh/iotlib/sms.md index af1ef4a6..387c34df 100644 --- a/docs/API_reference/zh/iotlib/sms.md +++ b/docs/API_reference/zh/iotlib/sms.md @@ -37,7 +37,7 @@ sms.sendTextMsg(phoneNumber, msg, codeMode) > 仅以下系列支持长短信: > -> EC600N/EG912N/EG915N/EC600M/EC200A系列短信内容UCS2编码最多支持420字节,GSM编码最多支持960个字节长度。 +> EC600N/EG912N/EG915N/EC200A系列短信内容UCS2编码最多支持420字节,GSM编码最多支持960个字节长度。 > > EC200U/EC600U/EG912U/EG915U系列短信内容UCS2编码最多支持280个字节,GSM编码最多支持640个字节的短信长度。 > @@ -83,7 +83,7 @@ sms.sendPduMsg(phoneNumber, msg, codeMode) > 仅以下系列支持长短信: > -> EC600N/EG912N/EG915N/EC600M/EC200A系列短信内容UCS2编码最多支持420字节,GSM编码最多支持960个字节长度。 +> EC600N/EG912N/EG915N/EC200A系列短信内容UCS2编码最多支持420字节,GSM编码最多支持960个字节长度。 > > EC200U/EC600U/EG912U/EG915U系列短信内容UCS2编码最多支持280个字节,GSM编码最多支持640个字节的短信长度。 > -- Gitee From e07c144479b9be392790f3aa759f2a0599f28855 Mon Sep 17 00:00:00 2001 From: "burols.wang" Date: Wed, 16 Oct 2024 11:12:05 +0800 Subject: [PATCH 10/14] =?UTF-8?q?=20(Lwm2m):=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E6=8F=8F=E8=BF=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 固件版本: N 是否需要文案翻译: 是 Signed-off-by: burols.wang --- docs/API_reference/zh/cloudlib/Lwm2m.md | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/docs/API_reference/zh/cloudlib/Lwm2m.md b/docs/API_reference/zh/cloudlib/Lwm2m.md index 41591544..ac8e8fa0 100644 --- a/docs/API_reference/zh/cloudlib/Lwm2m.md +++ b/docs/API_reference/zh/cloudlib/Lwm2m.md @@ -218,17 +218,19 @@ config_type参数配置类型介绍 ## 支持平台 -| 支持平台 | 备注 | -| ----------- | ---------------------------- | -| EC600UEU_AC | 公版不支持,定制型号支持 | -| BG95M8 | | -| BG95M3 | | -| EC200AAU_HA | | -| EG915NEA_AC | 公版不支持,定制型号支持 | -| EG912NEN_AA | | +| 支持平台 | 备注 | +| ----------- | ------------ | +| EC600UEU_AC | 公版不支持,定制型号支持 | +| BG95M8 | | +| BG95M3 | | +| EC200AAU_HA | | +| EG915NEA_AC | 公版不支持,定制型号支持 | +| EG912NEN_AA | | ## 事件说明 +事件类型不同的平台可能稍有不同,例如APN某些平台没有,不影响功能,不影响使用。 + | 事件类型 | 说明 | 备注 | | -------------------------------------------------------------- | --------------------------------------- | ------------------------------------------------------------------------------------------------ | | +QLWURC: "pdp active",result,APN | PDP的激活结果。在向 LwM2M 发送注册请求之前,应激活 PDP 服务器。 | result:string类型
"successfully"
"failed"
APN:string类型
APN值 | -- Gitee From 8ed19ba0097bf9cc7f3f15c695fa539b1ac5ca91 Mon Sep 17 00:00:00 2001 From: "burols.wang" Date: Wed, 16 Oct 2024 11:15:32 +0800 Subject: [PATCH 11/14] =?UTF-8?q?=20(Lwm2m):=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E6=8F=8F=E8=BF=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 固件版本: N 是否需要文案翻译: 否 Signed-off-by: burols.wang --- docs/API_reference/en/cloudlib/Lwm2m.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/API_reference/en/cloudlib/Lwm2m.md b/docs/API_reference/en/cloudlib/Lwm2m.md index 14f3e0e9..c6011a7e 100644 --- a/docs/API_reference/en/cloudlib/Lwm2m.md +++ b/docs/API_reference/en/cloudlib/Lwm2m.md @@ -222,7 +222,7 @@ three | EG912NEN_AA | | ## Event description - +The event types may vary slightly across different platforms; for example, some platforms may not have APN, but this does not affect functionality or usability. | Event type | Description | Remarks | | ------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- | | +QLWURC: "pdp active",result,APN | PDP activation result. Before sending a registration request to LwM2M, the PDP server should be activated | Result: string type
"successful"
"failed"
APN: string type
APN value | -- Gitee From 1ff64da5ab29aca80df4b48056b950e235289e1d Mon Sep 17 00:00:00 2001 From: "burols.wang" Date: Wed, 16 Oct 2024 11:20:13 +0800 Subject: [PATCH 12/14] =?UTF-8?q?=20(lwm2m):=20=E6=A0=BC=E5=BC=8F?= =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 固件版本: N 是否需要文案翻译: 否 Signed-off-by: burols.wang --- docs/API_reference/en/cloudlib/Lwm2m.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/API_reference/en/cloudlib/Lwm2m.md b/docs/API_reference/en/cloudlib/Lwm2m.md index c6011a7e..64635b60 100644 --- a/docs/API_reference/en/cloudlib/Lwm2m.md +++ b/docs/API_reference/en/cloudlib/Lwm2m.md @@ -222,7 +222,9 @@ three | EG912NEN_AA | | ## Event description + The event types may vary slightly across different platforms; for example, some platforms may not have APN, but this does not affect functionality or usability. + | Event type | Description | Remarks | | ------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- | | +QLWURC: "pdp active",result,APN | PDP activation result. Before sending a registration request to LwM2M, the PDP server should be activated | Result: string type
"successful"
"failed"
APN: string type
APN value | -- Gitee From c029aedd34dbab309e5e19c03a5f5751d2da4911 Mon Sep 17 00:00:00 2001 From: "burols.wang" Date: Wed, 20 Nov 2024 09:42:49 +0800 Subject: [PATCH 13/14] =?UTF-8?q?=20(lwm2m):=20=E6=A0=BC=E5=BC=8F?= =?UTF-8?q?=E5=86=85=E5=AE=B9=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 固件版本: N 是否需要文案翻译: 否 Signed-off-by: burols.wang --- docs/API_reference/en/cloudlib/Lwm2m.md | 360 +++++++++++------------- docs/API_reference/zh/cloudlib/Lwm2m.md | 226 +++++++-------- 2 files changed, 269 insertions(+), 317 deletions(-) diff --git a/docs/API_reference/en/cloudlib/Lwm2m.md b/docs/API_reference/en/cloudlib/Lwm2m.md index 64635b60..8ddc3f2a 100644 --- a/docs/API_reference/en/cloudlib/Lwm2m.md +++ b/docs/API_reference/en/cloudlib/Lwm2m.md @@ -1,250 +1,230 @@ -# LWM2M - Lightweight Internet of Things +# LWM2M - Lightweight M2M (Machine to Machine) -## Create object +## Create Object -> lw=lwm2m() +### `lwm2m` -- Parameters - No +```python +lw=lwm2m() +``` -- Return value - Lwm2m object +**Parameter Description:** -- Example - - ```python - >>> import lwm2m - >>> lw=lwm2m() - >>> - ``` +No parameters. -## Initialize object -> lw.init() -- Parameters - No +**Return Value Description:** -- Return value - Success: 0 - Failed: -1 +Returns the lwm2m object. -- Example +## Initialize Object + +### `init` ```python ->>> lw.init() -0 ->>> +lwm2m.init() ``` -## Configure objects - -> lw.config(config_type,config_list) - -- Parameters - config_type: Configuration type - config_list : List type, configuration parameter list. - -- Return value - Success: 0 - Failed: -1 - Not supported: -2 - -Introduction to fields in the config_list parameter list - -| Field Name | Field Type | Field Description | -| --------------- | ---------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| serverID | integer | 0 Bootstrap server
1 DM server
| -| SSID | integer | 100 Bootstrap server
1000 Diagnostics server
| -| server_addr | string | Server Address, in the format of "address: port", supports a maximum length of 256 | -| bootstrap | integer | 0. No need to use bootstrap (only if server ID is not 0)
1. Use bootstrap (only if server ID is 0) | -| security_mode | integer | encryption method:
0 Pre share key mode
3 No security mode | -| psk_id | string | useful when secure_mode is 0 | -| psk_key | string | useful when secure_mode is 0 | -| life_time | integer | lifetime, value range 1~86400, default value 86400, unit: seconds | -| pmin | integer | pmin default period, value range 1~86400, default value 86400, unit: seconds | -| pmax | integer | pmax default period, value range 1~86400, default value 86400, unit: seconds | -| disable_timeout | integer | The time interval from disconnecting from the LwM2M server to the next connection. The range is 1-86400, with a default value of 86400 and a unit of seconds. After testing the port, it can be immediately connected. Invalid (sent to the server, not restricted by the server) | -| storing | integer | Whether to save server information
0. Do not save
1. Save | -| binding_mode | string | Server Connection Method
"U" - UDP Method
"UQ" - UDP with Queue Mode
"S" - SMS Method
"SQ" - SMS with Queue Mode
"US" - UDP and SMS Methods
"UQS" - UDP and SMS with Queue Mode | -| mode | integer | terminal device name format
3 format: urn: imei: xxxxx
lwm2mserver configuration epname format | -| download | Integer | Download Mode
0 Manual Download
1 Automatic Download | -| update | integer | update mode
0 Manual update
1 Automatic update | -| URC_onoff | Integer | Enable URC reporting for LWm2m
0 Disable URC reporting
1 Enable URC reporting | - -Introduction to config_type parameter configuration type - -| Configuration type name | Corresponding config_list parameter | Remarks | -| ----------------------- | -------------------------------------------------------------------- | --------------------------------------------------------------- | -| Epnamemode | [mode] | | -| Reset | [] | Empty list | -| Security | [serverID, SSID,server_addr,bootstrap,security_mode,psk_id,psk_key] | | -| Server | [serverID, life_time,pmin,pmax,disable_timeout,storing,binding_mode] | | -| Urc | [URC_onoff] | If you want to capture URC, you must configure it to be enabled | -| Fota | [download, update] | If you want to crawl URLs, configure them to not be automatic | - -- Example +**Parameter Description:** + +No parameters. + + + +**Return Value Description:** + +Returns an integer value of 0 for success, and an integer value of -1 for failure. + +## Configure Object + +### `config` ```python ->>> config=[0,100," coaps://InteropBootstrap.dm.iot.att.com:5694 ",1,0,"urn:imei:864430010001095","313233343536"] ->>> lw.config(lw.Security,config) -0 ->>>   +lwm2m.config(config_type,config_list) ``` -## Register +**Parameter Description:** -> lw.register() +* `config_type` - Configuration type, an enumerated value under the lwm2m object, see Table 1 below. +* `config_list` - List of configuration parameters, list data type, list element values are explained in Table 2 below. + + -- Parameters - nothing +**Return Value Description:** + +Returns an integer value of 0 for success, an integer value of -1 for failure, and an integer value of -2 for unsupported operations. + +
Table 1
+ +| Configuration Type | Corresponding config_list Parameter | Remarks | +| ------------------ | ------------------------------------------------------------------- | ------------------------------ | +| Epnamemode | [mode] | | +| Reset | [] | Empty list | +| Security | [serverID,SSID,server_addr,bootstrap,security_mode,psk_id,psk_key] | | +| Server | [serverID,life_time,pmin,pmax,disable_timeout,storing,binding_mode] | | +| Urc | [URC_onoff] | Must be enabled to capture URC | +| Fota | [download,update] | Capture URC in manual mode. | + +
Table 2
+ +| Field Name | Data Type | Field Description | +| --------------- | --------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| serverID | Integer | 0 Bootstrap server
1 DM server
| +| SSID | Integer | 100 Bootstrap server
1000 Diagnostics server
| +| server_addr | String | Server address in the format "address", maximum length 256. | +| bootstrap | Integer | 0 Do not use bootstrap (only when serverID is not 0)
1 Use bootstrap (only when serverID is 0) | +| security_mode | Integer | Encryption method:
0 Pre-shared key mode
3 No security mode | +| psk_id | String | Used when security_mode is 0 | +| psk_key | String | Used when security_mode is 0 | +| life_time | Integer | Lifetime, range 1-86400, default is 86400, in seconds. | +| pmin | Integer | Default pmin period, range 1-86400, default is 86400, in seconds. | +| pmax | Integer | Default pmax period, range 1-86400, default is 86400, in seconds. | +| disable_timeout | Integer | Time interval before the next connection after disconnection from LwM2M server. Range 1-86400, default is 86400, in seconds. | +| storing | Integer | Whether to save server information:
0 Do not save
1 Save | +| binding_mode | String | Binding mode with the server:
"U" - UDP mode
"UQ" - UDP with queue mode
"S" - SMS mode
"SQ" - SMS with queue mode
"US" - UDP and SMS mode
"UQS" - UDP and SMS with queue mode | +| mode | Integer | Terminal device name format:
3 Format: urn:imei
lwm2mserver configured epname format | +| download | Integer | Download mode:
0 Manual download
1 Automatic download | +| update | Integer | Update mode:
0 Manual update
1 Automatic update | +| URC_onoff | Integer | Enable/Disable URC reporting for LwM2M:
0 Disable URC reporting
1 Enable URC reporting | -- Return value - Return 0 for successful execution and -1 for failed execution. The registration result needs to be queried by calling the query interface. +## Register -- Example +### `register` ```python ->>> lw.register() -0 +lwm2m.register() ``` -## Unregister +**Parameter Description:** + +No parameters. -> lw.unregister() -- Parameters - nothing -- Return value - Return 0 for successful execution and -1 for failed execution. The cancellation result needs to be queried by calling the query interface. +**Return Value Description:** -- Example +Returns 0 for success, -1 for failure. The registration result requires calling the query interface to check. + +## Unregister + +### `unregister` ```python ->>> lw.unregister() -0 +lwm2m.unregister() ``` -## Check registration status +**Parameter Description:** + +No parameters. + + -> lw.stat() +**Return Value Description:** -- Parameters - nothing +Returns 0 for success, -1 for failure. The unregister result requires calling the query interface to check. -- Return value - 0 Unregistered
1 Registering
2 Registered
3 Cancelling
- 4 login failures +## Query Registration Status -- Example +### `stat` ```python ->>> lw.stat() -0 ->>> lw.register() -0 ->>> lw.stat() -one ->>> lw.unregister() -0 ->>> lw.stat() -three ->>> +lwm2m.stat() ``` -## Send heartbeat +**Parameter Description:** -> lw.update(SSID) +No parameters. -- Parameters - SSID : The configured SSID, or the SSID issued by BS. -- Return value - Command success returns 0, command failure returns -1. The success or failure of the update is determined based on the "+QLWURC:" update "event. -- Example +**Return Value Description:** + +Returns an integer value of 0 for 'Not Registered' status, 1 for 'Registering' status, 2 for 'Registered' status, 3 for 'Deregistering' status, and 4 for 'Login Failed' status. + +## Send Heartbeat + +### `update` ```python ->>> lw.update(1) -0 +lwm2m.update(SSID) ``` -## Register callback function +**Parameter Description:** -> lw.register_call(usrfun) - -- Parameters - Usrfun: function - Prototype of usrfun: usrfun (list) - Usrfun parameter: type list - List description: +* `SSID` - Configured SSID or the SSID issued during BS login in the bootstrap stage, integer value. + -| Parameter Description | Parameter Type | Remarks | -| --------------------- | -------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| List [0] | int | Event type (can be ignored without processing) | -| List [1] | int | Event encoding (can be ignored without processing) | -| List [2] | string | The URC string data captured (please refer to [Event Description](#Event description) for specific event descriptions), and use this parameter to determine the connection event of Lwm2m | -- Return value - Success returns 0, failure returns -1 - Note that if you want to delete a registered callback function, pass the parameter None +**Return Value Description:** + +Returns 0 for success, -1 for failure. The result of the update is notified through the callback function. -- Example +## Register Callback Function + +### `register_call` ```python ->>> import lwm2m ->>> lw=lwm2m() ->>> def lwm2m_call(args): -... print('args{}'.format(args)) -... -... -... ->>> ->>> lw.register_call(lwm2m_call) -0 ->>> ->>> lw.register_call(None) -0 ->>> ->>> +lwm2m.register_call(usrfun) ``` -## Support platform - -| Support Platform | Remarks | -| --------------------------------------- | ---------------------------------------------------------------- | -| EC600UEU_AC | Public version is not supported, customized models are supported | -| BG95M8 | | -| BG95M3 | | -| EC200AAU_HA | | -| EG915NEA_AC | Public version is not supported, customized models are supported | -| EG912NEN_AA | | - -## Event description - -The event types may vary slightly across different platforms; for example, some platforms may not have APN, but this does not affect functionality or usability. - -| Event type | Description | Remarks | -| ------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- | -| +QLWURC: "pdp active",result,APN | PDP activation result. Before sending a registration request to LwM2M, the PDP server should be activated | Result: string type
"successful"
"failed"
APN: string type
APN value | -| +QLWURC: "initial",result,SSID | The initialization result of the connection between the client and LwM2M server | Result: string type
"successful"
"failed"
SSID: shape type
0- all servers
other values - other special servers | -| +QLWURC: "dtls",result,SSID | DTLS handshake result when using encryption method | Same as above | -| +QLWURC: "bootstraping" | When Bootstrap is working, this URC will be reported | | -| +QLWURC: "bootstrap",result,SSID | Bootstrap's working result | Same as above | -| +QLWURC: "registering" | This URC will be reported when the client registers on the LwM2M server | Same as above | -| +QLWURC: "ready",result,SSID | The registration result after sending a registration request to the LwM2M server | Same as above | -| +QLWURC: "update",result,SSID | The update result after sending an update request to the LwM2M server | Same as above | -| +QLWURC: "deregister",SSID,code
+QLWURC: "deregister",code | The logout result after sending a logout request to the LwM2M server | SSID: Shaping type
0- All servers
Other values - Other special servers
Code: Shaping
0- Success
1- Failure
3- Unknown error | -| +QLWURC: "fota/pkgurl",url | The URL address issued by LWM2M. | | -| +QLWURC: "apn_changed",APN | APN value issued by LWM2M. | | -| +QLWURC: "user_name_changed",user | User issued by LWM2M. | | -| +QLWURC: "secret_changed",password | Password issued by LWM2M | | -| +QLWURC: "authentication_type_changed", | Authentication issued by LWM2M. | | -| +QLWURC: "lifetime_changed",lifetime | The lifetime issued by LWM2M | | -| +QLWURC: "current_time_changed",data_time | The data_time issued by LWM2M is added with UTC_OFFSET. | | - -###### Example usage +**Parameter Description:** + +* `usrfun` - The callback function to be set, which is called when the server responds. + +**回调函数参数** + +* `list` - The callback function notification data, list type, described in detail below: + +| Element | Data Type | Description | +| ------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | +| list[0] | Integer | Event type (can be ignored) | +| list[1] | Integer | Event code (can be ignored) | +| list[2] | Integer | Captured URC string data (specific event description can be found in [Event-Description](#Event-Description), used to determine the connection event of Lwm2m. | + + + +**Return Value Description:** + +Returns 0 for success, -1 for failure. To remove an already registered callback function, pass in None. + +## Supported Platforms + +| Supported Platform | Remarks | +| ------------------ | ------------------------------------------------------------- | +| EC600UEU_AC | Standard version not supported, customized versions supported | +| BG95M8 | | +| BG95M3 | | +| EC200AAU_HA | | +| EG915NEA_AC | Standard version not supported, customized versions supported | +| EG912NEN_AA | | + +## Event-Description + +The event types may vary slightly across platforms, for example, some platforms do not have APN, which does not affect functionality or usage. + +| Event Type | Description | Remarks | +| -------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- | +| +QLWURC: "pdp active",result,APN | Result of PDP activation. Before sending the registration request to LwM2M, the PDP server should be activated. | result: string type
"successfully"
"failed"
APN: string type
APN value | +| +QLWURC: "initial",result,SSID | Initialization result when the client connects to the LwM2M server. | result: string type
"successfully"
"failed"
SSID: integer type
0 - All servers
Other values - Specific servers | +| +QLWURC: "dtls",result,SSID | DTLS handshake result when using encryption. | Same as above | +| +QLWURC: "bootstraping" | Reports this URC when the bootstrap process is active. | | +| +QLWURC: "bootstrap",result,SSID | Result of the Bootstrap process. | Same as above | +| +QLWURC: "registering" | Reports this URC when the client is registering with the LwM2M server. | Same as above | +| +QLWURC: "ready",result,SSID | Result of registration request sent to the LwM2M server. | Same as above | +| +QLWURC: "update",result,SSID | Result of update request sent to the LwM2M server. | Same as above | +| +QLWURC: "deregister",SSID,code
+QLWURC: "deregister",code | Result of the deregistration request sent to the LwM2M server. | SSID: integer type
0 - All servers
Other values - Specific servers
Code: integer
0 - Success
1 - Failure
3 - Unknown Error | +| +QLWURC: "fota/pkgurl",url | URL address issued by LWM2M. | | +| +QLWURC: "apn_changed",APN | APN value issued by LWM2M. | | +| +QLWURC: "user_name_changed",user | User name issued by LWM2M. | | +| +QLWURC: "secret_changed",password | Password issued by LWM2M. | | +| +QLWURC: "authentication_type_changed", | Authentication type issued by LWM2M. | | +| +QLWURC: "lifetime_changed",lifetime | Lifetime issued by LWM2M. | | +| +QLWURC: "current_time_changed",data_time | Data time issued by LWM2M with UTC_OFFSET. | | + + + +###### Example Usage. ```python import utime @@ -267,7 +247,7 @@ class lwm2m_client(): self.connect_server_type = 0 # 0 - server, 1 - bsserver self.imei = modem.getDevImei() self.security_mode = 3 # 3 - no Pre-share key mode, 0 Pre-share key mode - self.epname_mode = 3 # 3 - urn:imei:+imei + self.epname_mode = 3 # 3 - urn:imei:+imei . self.support_security_mode=[0,2,3] self.psk="urn:imei:{}".format(self.imei) diff --git a/docs/API_reference/zh/cloudlib/Lwm2m.md b/docs/API_reference/zh/cloudlib/Lwm2m.md index ac8e8fa0..899bcf9d 100644 --- a/docs/API_reference/zh/cloudlib/Lwm2m.md +++ b/docs/API_reference/zh/cloudlib/Lwm2m.md @@ -2,54 +2,71 @@ ## 创建对象 -> lw=lwm2m() +### `lwm2m` -* 参数 - 无 -- 返回值 - lwm2m对象 +```python +lw=lwm2m() +``` + +**参数描述:** + +无参数。 + + + +**返回值描述:** -- 示例 +返回lwm2m对象。 + +## 初始化对象 + +### `init` ```python ->>> import lwm2m ->>> lw=lwm2m() ->>> +lwm2m.init() ``` -## 初始化对象 +**参数描述:** + +无参数。 + -> lw.init() -- 参数 - 无 +**返回值描述:** -- 返回值 - 成功: 0 - 失败: -1 +成功返回整型数值0,失败返回整型数值-1。 -- 示例 +## 配置对象 + +### `config` ```python ->>> lw.init() -0 ->>> +lwm2m.config(config_type,config_list) ``` -## 配置对象 +**参数描述:** -> lw.config(config_type,config_list) +* `config_type` - 配置类型 ,枚举型,lwm2m对象下的枚举数值,详见表1。 +* `config_list` - 配置参数列表 ,列表数据类型,列表元素值详见表2。 + + -- 参数 - config_type:配置类型 - config_list : 列表类型,配置参数列表。 +**返回值描述:** -- 返回值 - 成功: 0 - 失败: -1 - 不支持:-2 +成功返回整型数值0,失败返回整型数值-1,不支持返回整型数值-2。 -用于config_list参数列表中的字段介绍 +
表1
+ +| 配置类型名 | 对应的config_list参数 | 备注 | +| ---------- | ------------------------------------------------------------------- | ----------------- | +| Epnamemode | [mode] | | +| Reset | [] | 空list | +| Security | [serverID,SSID,server_addr,bootstrap,security_mode,psk_id,psk_key] | | +| Server | [serverID,life_time,pmin,pmax,disable_timeout,storing,binding_mode] | | +| Urc | [URC_onoff] | 如果要抓取URC,必须配置开启 | +| Fota | [download,update] | 如果要抓取URC,配置成均不自动。 | + +
表2
| 字段名 | 字段类型 | 字段说明 | | --------------- | ---- | --------------------------------------------------------------------------------------------------------------------------------------------------- | @@ -71,150 +88,105 @@ | update | 整型 | 更新模式
0 手动更新
1 自动更新 | | URC_onoff | 整型 | 是否开启LWm2m的urc上报
0 禁用URC上报
1 启用URC上报 | -config_type参数配置类型介绍 - -| 配置类型名 | 对应的config_list参数 | 备注 | -| ---------- | ------------------------------------------------------------------- | ----------------- | -| Epnamemode | [mode] | | -| Reset | [] | 空list | -| Security | [serverID,SSID,server_addr,bootstrap,security_mode,psk_id,psk_key] | | -| Server | [serverID,life_time,pmin,pmax,disable_timeout,storing,binding_mode] | | -| Urc | [URC_onoff] | 如果要抓取URC,必须配置开启 | -| Fota | [download,update] | 如果要抓取URL,配置成均不自动。 | +## 注册 -- 示例 +### `register` ```python ->>> config=[0,100,"coaps://InteropBootstrap.dm.iot.att.com:5694",1,0,"urn:imei:864430010001095","313233343536"] ->>> lw.config(lw.Security,config) -0 ->>>   +lwm2m.register() ``` -## 注册 +**参数描述:** + +无参数 -> lw.register() -- 参数 - 无 -- 返回值 - 执行成功返回0,执行失败返回-1。注册结果需要调用查询接口进行查询。 +**返回值描述:** + +执行成功返回0,执行失败返回-1。注册结果需要调用查询接口进行查询。 + +## 注销 -- 示例 +### `unregister` ```python ->>> lw.register() -0 +lwm2m.unregister() ``` +**参数描述:** + +无参数。 -## 注销 -> lw.unregister() +**返回值描述:** -- 参数 - 无 +执行成功返回0,执行失败返回-1。注销结果需要调用查询接口进行查询。 -- 返回值 - 执行成功返回0,执行失败返回-1。注销结果需要调用查询接口进行查询。 +## 查询注册状态 -- 示例 +### `stat` ```python ->>> lw.unregister() -0 +lwm2m.stat() ``` +**参数描述:** + +无参数。 -## 查询注册状态 -> lw.stat() +**返回值描述:** -- 参数 - 无 +未注册状态返回整型值0,注册中状态返回整型值1,已注册状态返回整型值2,注销中状态返回整型值3,登录失败状态返回整型值4。 -- 返回值 - 0 未注册
1 注册中
2 已注册
3 注销中
- 4 登录失败 +## 发送心跳 -- 示例 +### `update` ```python ->>> lw.stat() -0 ->>> lw.register() -0 ->>> lw.stat() -1 ->>> lw.unregister() -0 ->>> lw.stat() -3 ->>> +lwm2m.update(SSID) ``` -## 发送心跳 +**参数描述:** + +* `SSID` - 配置的SSID或者是BS登录阶段BS下发的SSID,整型值。 + + -> lw.update(SSID) +**返回值描述:** -- 参数 - SSID : 配置的SSID,或者BS下发的SSID。 +成功返回整型值0,失败返回整型值-1。update结果通过回调函数通知。 -- 返回值 - 指令成功返回0,指令失败返回-1.更新成功或失败结果根据“+QLWURC: "update"事件进行判断。 +## 注册回调函数 -- 示例 +### `register_call` ```python ->>> lw.update(1) -0 +lwm2m.register_call(usrfun) ``` +**参数描述:** +* `usrfun` - 设置消息回调函数,function类型,当服务端响应时触发该方法。 -## 注册回调函数 +**回调函数参数** -> lw.register_call(usrfun) +* `list` - 回调函数通知消息数据,list类型,详细介绍如下: -- 参数 - usrfun:函数 - usrfun原型:usrfun(list) - usrfun参数:类型list - list说明: +| 元素 | 数据类型 | 备注 | +| ------- | ---- | ------------------------------------------------------- | +| list[0] | 整型 | 事件类型(可以不处理忽略) | +| list[1] | 整型 | 事件编码(可以不处理忽略) | +| list[2] | 整型 | 抓取到的URC字符串数据(具体事件说明请参考[事件说明](#事件说明),以此参数判断Lwm2m的连接事件为准 | -| 参数明 | 参数类型 | 备注说明 | -| ------- | ------ | ------------------------------------------------------- | -| list[0] | int | 事件类型(可以不处理忽略) | -| list[1] | int | 事件编码(可以不处理忽略) | -| list[2] | string | 抓取到的URC字符串数据(具体事件说明请参考[事件说明](#事件说明)),以此参数判断Lwm2m的连接事件为准 | -- 返回值 - 成功返回0,失败返回-1. - 注意如果要删除已经注册的回调函数,传入参数None. -- 示例 +**返回值描述:** -```python ->>> import lwm2m ->>> lw=lwm2m() ->>> def lwm2m_call(args): -... print('args{}'.format(args)) -... -... -... ->>> ->>> lw.register_call(lwm2m_call) -0 ->>> ->>> lw.register_call(None) -0 ->>> - ->>> -``` +成功返回0,失败返回-1。注意如果要删除已经注册的回调函数,传入参数None. ## 支持平台 @@ -234,14 +206,14 @@ config_type参数配置类型介绍 | 事件类型 | 说明 | 备注 | | -------------------------------------------------------------- | --------------------------------------- | ------------------------------------------------------------------------------------------------ | | +QLWURC: "pdp active",result,APN | PDP的激活结果。在向 LwM2M 发送注册请求之前,应激活 PDP 服务器。 | result:string类型
"successfully"
"failed"
APN:string类型
APN值 | -| +QLWURC: "initial",result,SSID | 客户端与LwM2M服务器连接的初始化结果。 | result:string类型
"successfully"
"failed"
SSID:整形类型
0-所有的服务器
其他值-其他的特殊服务器 | +| +QLWURC: "initial",result,SSID | 客户端与LwM2M服务器连接的初始化结果。 | result:string类型
"successfully"
"failed"
SSID:整型类型
0-所有的服务器
其他值-其他的特殊服务器 | | +QLWURC: "dtls",result,SSID | 使用加密方法时的 DTLS 握手结果。 | 同上 | | +QLWURC: "bootstraping" | 当 Bootstrap 工作时,将报告此 URC。 | | | +QLWURC: "bootstrap",result,SSID | Bootstrap 的工作结果。 | 同上 | | +QLWURC: "registering" | 当客户端在 LwM2M 服务器上注册时将报告此 URC。 | 同上 | | +QLWURC: "ready",result,SSID | 向LwM2M服务器发送注册请求后的注册结果。 | 同上 | | +QLWURC: "update",result,SSID | 向LwM2M服务器发送更新请求后的更新结果。 | 同上 | -| +QLWURC: "deregister",SSID,code
+QLWURC: "deregister",code | 向LwM2M服务器发送注销请求后的注销结果。 | SSID:整形类型
0-所有的服务器
其他值-其他的特殊服务器
Code:整形
0-成功
1-失败
3-未知错误 | +| +QLWURC: "deregister",SSID,code
+QLWURC: "deregister",code | 向LwM2M服务器发送注销请求后的注销结果。 | SSID:整型类型
0-所有的服务器
其他值-其他的特殊服务器
Code:整型
0-成功
1-失败
3-未知错误 | | +QLWURC: "fota/pkgurl",url | LWM2M下发的url地址。 | | | +QLWURC: "apn_changed",APN | LWM2M下发的APN值。 | | | +QLWURC: "user_name_changed",user | LWM2M下发的user。 | | -- Gitee From 19d899294aa3c6a33e0e4ba5fae380d44ac139ac Mon Sep 17 00:00:00 2001 From: "burols.wang" Date: Wed, 20 Nov 2024 09:52:29 +0800 Subject: [PATCH 14/14] =?UTF-8?q?=20(lwm2m):=20=E8=8B=B1=E6=96=87?= =?UTF-8?q?=E9=80=97=E5=8F=B7=E4=BF=AE=E6=94=B9=E6=88=90=E4=B8=AD=E6=96=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 固件版本: N 是否需要文案翻译: 是 Signed-off-by: burols.wang --- docs/API_reference/zh/cloudlib/Lwm2m.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/API_reference/zh/cloudlib/Lwm2m.md b/docs/API_reference/zh/cloudlib/Lwm2m.md index 899bcf9d..ac99afe6 100644 --- a/docs/API_reference/zh/cloudlib/Lwm2m.md +++ b/docs/API_reference/zh/cloudlib/Lwm2m.md @@ -64,7 +64,7 @@ lwm2m.config(config_type,config_list) | Security | [serverID,SSID,server_addr,bootstrap,security_mode,psk_id,psk_key] | | | Server | [serverID,life_time,pmin,pmax,disable_timeout,storing,binding_mode] | | | Urc | [URC_onoff] | 如果要抓取URC,必须配置开启 | -| Fota | [download,update] | 如果要抓取URC,配置成均不自动。 | +| Fota | [download,update] | 如果要抓取URC,配置成均不自动。 |
表2
@@ -72,7 +72,7 @@ lwm2m.config(config_type,config_list) | --------------- | ---- | --------------------------------------------------------------------------------------------------------------------------------------------------- | | serverID | 整型 | 0 Bootstrap server
1 DM server
| | SSID | 整型 | 100 Bootstrap server
1000 Diagnostics server
| -| server_addr | 字符串 | 服务器地址,格式为:"address:port",最长支持256。 | +| server_addr | 字符串 | 服务器地址,格式为:"address:port",最长支持256。 | | bootstrap | 整型 | 0 不用bootstrap(仅当serverID不为0)
1 使用bootstrap (仅当serverID为0) | | security_mode | 整型 | 加密方法:
0 Pre-share key mode
3 No security mode | | psk_id | 字符串 | security_mode为0时有用 | -- Gitee