Skip to content

Commit 93eba3d

Browse files
committed
PSM
1 parent c19d0ec commit 93eba3d

File tree

1 file changed

+72
-0
lines changed
  • content/firmwareapi/pycom/network

1 file changed

+72
-0
lines changed

content/firmwareapi/pycom/network/lte.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,73 @@ lte = LTE()
5858

5959
This method is used to set up the LTE subsystem. After a `deinit()` this method can take several seconds to return waiting for the LTE modem to start-up. Optionally specify a carrier name. The available options are: `verizon, at&t, standard`. `standard` is generic for any carrier, and it's also the option used when no arguments are given.
6060

61+
**Power Saving Mode**
62+
63+
The _Power Saving Mode_ allows a user to configure how often a device will connect and how long it will stay connected. Upon `attach()` this configuration is then requested from the network. Ultimately it is up to the network to decide the PSM configuration. After a successful PSM configuration,
64+
65+
- the LTE modem will go into a low power state during deep sleep, but
66+
- it will stay attached to the network, thus no time is spent for `attach()` after waking up.
67+
68+
The configuration is done with these four parameters:
69+
70+
- `psm_period_value` : Configure at which period the device will connect to the network. Values from 0 to 31 are allowed.
71+
- `psm_period_unit` : Specify the _unit_ to be used for `psm_period_value`.
72+
- `psm_active_value` : Configure how long the device will be connected. Values from 0 to 31 are allowed.
73+
- `psm_active_unit` : Specify the _unit_ for `psm_active_value`.
74+
75+
The LTE specification prescribes certain _units_ for configuring PSM. See the constants below.
76+
77+
For the following example, assume you want to wake up once per hour, connect and do some processing, then go to deepsleep for 55 minutes:
78+
79+
```python
80+
81+
from network import LTE
82+
import time
83+
import socket
84+
import machine
85+
import pycom
86+
87+
def attach():
88+
start = time.time()
89+
if lte.isattached():
90+
print("already attached")
91+
else:
92+
print("attach")
93+
lte.attach(band=20, apn="spe.inetd.vodafone.nbiot")
94+
while not lte.isattached():
95+
time.sleep(1)
96+
print("attached after", time.time() - start, "seconds")
97+
print(lte.psm())
98+
99+
def connect():
100+
print("connect")
101+
start = time.time()
102+
lte.connect()
103+
while not lte.isconnected():
104+
time.sleep(0.5)
105+
print("connected after", time.time() - start, "seconds")
106+
107+
def http_get(url = 'http://detectportal.firefox.com/'):
108+
_, _, host, path = url.split('/', 3)
109+
addr = socket.getaddrinfo(host, 80)[0][-1]
110+
s = socket.socket()
111+
s.connect(addr)
112+
s.send(bytes('GET /%s HTTP/1.0\r\nHost: %s\r\n\r\n' % (path, host), 'utf8'))
113+
s.close()
114+
115+
# period 1h, active 10s
116+
lte = LTE(psm_period_value=1, psm_period_unit=LTE.PSM_PERIOD_1H,
117+
psm_active_value=5, psm_active_unit=LTE.PSM_ACTIVE_2S )
118+
print(lte.psm())
119+
attach()
120+
connect()
121+
http_get()
122+
print("deinit")
123+
lte.deinit(detach=False, reset=False)
124+
print("deepsleep")
125+
machine.deepsleep(55 * 60 * 1000) # 55m
126+
```
127+
61128
#### lte.deinit(detach=True, reset = False)
62129

63130
Disables LTE modem completely. This reduces the power consumption to the minimum. Call this before entering deepsleep.
@@ -209,3 +276,8 @@ Check Network Coverage for UE device (i.e LTE modem).
209276
- `LTE.IP` : Internet Protocol IP
210277

211278
- `LTE.IPV4V6` : Internet protocol ver. 4/6
279+
280+
- `PSM_PERIOD_2S`, `PSM_PERIOD_30S`, `PSM_PERIOD_1M`, `PSM_PERIOD_10M`, `PSM_PERIOD_1H`, `PSM_PERIOD_10H`, `PSM_PERIOD_320H`: Specify the unit for the PSM period to be 2 seconds, 30 seconds, 1 minute, 10 minutes, 1 hour, 10 hours, or 320 hours, respectively.
281+
- `PSM_PERIOD_DISABLED`: Specifying the unit for PSM period of `PSM_PERIOD_DISABLED` means turning PSM off. This is the default.
282+
- `PSM_ACTIVE_2S`, `PSM_ACTIVE_1M`, `PSM_ACTIVE_6M`: Specify the unit for the PSM active duration to be 2 seconds, 1 minute, or 6 minutes, respectively.
283+
- `PSM_ACTIVE_DISABLED`: Specifying the active duration unit of `PSM_ACTIVE_DISABLED` means turning PSM off. This is the default.

0 commit comments

Comments
 (0)