Skip to content

Commit 16e66f7

Browse files
committed
fast_io: StreamReader.readinto method added.
1 parent 7b802c9 commit 16e66f7

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

fast_io/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,13 @@ def read(self, n=-1):
164164
# PollEventLoop._unregister
165165
return res # Next iteration raises StopIteration and returns result
166166

167+
def readinto(self, buf, n=-1): # Experimental and not yet tested TODO
168+
yield IORead(self.polls)
169+
res = self.ios.readinto(buf, n)
170+
assert res, 'zero bytes returned' # Temporary
171+
yield IOReadDone(self.polls)
172+
return res
173+
167174
def readexactly(self, n):
168175
buf = b""
169176
while n:

lowpower/mqtt_log.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@
66
# On my SF_2W board consumption while paused was 170μA.
77

88
# Test reception e.g. with:
9-
# mosquitto_sub -h 192.168.0.33 -t result
10-
11-
SERVER = '192.168.0.33' # *** Adapt for local conditions ***
12-
SSID = 'misspiggy'
13-
PW = '6163VMiqSTyx'
9+
# mosquitto_sub -h 192.168.0.10 -t result
1410

1511
import rtc_time_cfg
1612
rtc_time_cfg.enabled = True
@@ -19,6 +15,7 @@
1915
from umqtt.simple import MQTTClient
2016
import network
2117
import ujson
18+
from local import SERVER, SSID, PW # Local configuration: change this file
2219

2320
import uasyncio as asyncio
2421
try:
@@ -42,7 +39,7 @@ async def main(loop):
4239
sta_if = network.WLAN()
4340
sta_if.active(True)
4441
sta_if.connect(SSID, PW)
45-
while sta_if.status() == 1:
42+
while sta_if.status() in (1, 2): # https://github.com/micropython/micropython/issues/4682
4643
await asyncio.sleep(1)
4744
grn.toggle()
4845
if sta_if.isconnected():

0 commit comments

Comments
 (0)