LmacRxBlk:1 continues unabated - every time I don't close the sockets

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
alanm101
Posts: 5
Joined: Sun Apr 09, 2017 4:08 pm

LmacRxBlk:1 continues unabated - every time I don't close the sockets

Post by alanm101 » Sun Apr 09, 2017 4:31 pm

Hi All,

I've followed all advice found on the net, but the problem continues unabated. After roughly 5 post requests with urequests, the LmacRxBlk:1 occurs and does not cease until I hard reset. A soft reboot has no effect.

The latest code is below, as is the debug info. I have used two different versions of urequests. They get the same problem. The latest version I've tried is the one by J.G.Davies.

Any advice on whether my code sucks and how to fix it will be treated like gold.

My code:

import sys
import time
import machine
import dht
import urequests

bool_interrupt = False
last_interrupt = time.time()

NOTIFICATION = "https://api.prowlapp.com/publicapi/add? ... ORTHISPOST"

def blink_led(count, delay):
for x in range(0, count - 1):
if pin_led.value():
pin_led.low()
else:
pin_led.high()
time.sleep(delay)
pin_led.value(0)

def callback(p):
global bool_interrupt
bool_interrupt = True
print(bool_interrupt)

pin_led = machine.Pin(13, machine.Pin.OUT)
pin_vibration = machine.Pin(14, machine.Pin.IN)
temp = dht.DHT11(machine.Pin(0))

#d.measure()
#print(d.temperature())

# Tell everyone we are awake

blink_led(8, 0.5)

# now set interrupt for movement
pin_vibration.irq(trigger=machine.Pin.IRQ_FALLING, handler=callback)

url = NOTIFICATION

wlan = network.WLAN(network.STA_IF)

while True:
if wlan.isconnected() == False:
print('WiFi disconnected')
break
if bool_interrupt:
this_interrupt = time.time()
if this_interrupt - last_interrupt < 5:
print('avoid interrupt')
else:
print('interrupt')
resp = urequests.urlopen(url, 'method=POST')
print(resp)
last_interrupt = this_interrupt
blink_led(6, 0.3)
bool_interrupt = False
# time.sleep(1)


The console log:

#6 ets_task(40100164, 3, 3fff828c, 4)
network config: ('192.168.1.44', '255.255.255.0', '192.168.1.1', '192.168.1.1')
True
True
interrupt
True
True
<_SSLSocket 3fff2b10>
True
True
interrupt
<_SSLSocket 3fff4420>
True
True
interrupt
True
True
True
True
True
True
True
True
True
True
<_SSLSocket 3fff2b10>
True
interrupt
True
True
<_SSLSocket 3fff65f0>
True
True
interrupt
True
True
True
True
True
True
True
True
True
True
<_SSLSocket 3fff2ed0>
LmacRxBlk:1
LmacRxBlk:1
LmacRxBlk:1
LmacRxBlk:1
LmacRxBlk:1
LmacRxBlk:1
LmacRxBlk:1
LmacRxBlk:1
LmacRxBlk:1
LmacRxBlk:1
LmacRxBlk:1
LmacRxBlk:1
LmacRxBlk:1
LmacRxBlk:1
LmacRxBlk:1
LmacRxBlk:1
LmacRxBlk:1
LmacRxBlk:1
LmacRxBlk:1
LmacRxBlk:1
LmacRxBlk:1
LmacRxBlk:1
LmacRxBlk:1
LmacRxBlk:1

pfalcon
Posts: 1155
Joined: Fri Feb 28, 2014 2:05 pm

Re: LmacRxBlk:1 continues unabated

Post by pfalcon » Sun Apr 09, 2017 8:46 pm

Did you read the official documentation: http://docs.micropython.org/en/latest/e ... -resources ?
Awesome MicroPython list
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/

alanm101
Posts: 5
Joined: Sun Apr 09, 2017 4:08 pm

Re: LmacRxBlk:1 continues unabated

Post by alanm101 » Wed Apr 12, 2017 4:29 pm

Thanks for the response. Yes I did read the guide. I guess, from your cryptic response, that you are implying one should not use the available code for urequest, but rather create your own socket code where you have better control over the release of sockets.
I'm probably going to move away from that technique and rather use MQTT or some such.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: LmacRxBlk:1 continues unabated

Post by pythoncoder » Thu Apr 13, 2017 6:11 am

I'm no networking guru, but looking at the official urequests module the request() function returns a Response instance. This supports a close() method; this closes the socket which was created by request(). I think Paul is suggesting you use this to ensure sockets are closed after use.
Peter Hinch
Index to my micropython libraries.

alanm101
Posts: 5
Joined: Sun Apr 09, 2017 4:08 pm

Re: LmacRxBlk:1 continues unabated

Post by alanm101 » Fri Apr 14, 2017 8:41 am

Thanks pythoncoder. I changed to the urlopen module and added a socket.close(). Works fine now. However, it does seem that MQTT will be more suitable for my purposes. Another learning curve coming up...

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: LmacRxBlk:1 continues unabated

Post by pythoncoder » Fri Apr 14, 2017 9:09 am

Peter Hinch
Index to my micropython libraries.

pfalcon
Posts: 1155
Joined: Fri Feb 28, 2014 2:05 pm

Re: LmacRxBlk:1 continues unabated

Post by pfalcon » Sat Apr 15, 2017 6:15 pm

alanm101 wrote:I guess, from your cryptic response
There's nothing cryptic. The quoted documentation section states clearly:
please be sure to close open files, sockets, etc. as soon as possible after use.
Neither there's a need to modify anything - you just need to close (as in: call ".close()" method on them) any resources you finished dealing with, e.g a stream object you got from urlopen() call.
Awesome MicroPython list
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/

JNA

Re: LmacRxBlk:1 continues

Post by JNA » Fri May 05, 2017 12:05 am

@Alarm101

How have you progressed using MQTT in your setup? Success? Not? If you have been successful, it would be great to see your code as I too am having this issue.

TIA, JNA.

Post Reply