edit: pared the code down to a simple "write results of wlan.scan() to file" as a starting point to debug the issue. Still eventually run into the same problem; the script hangs after a while.
Running latest firmware on an ESP8266 and I'm having an issue that doesn't seem to be giving me an exception when network.scan() fails.
Currently continuously calling a simple loop that writes any newly found access points to a txt file using the scan() function. Earlier versions of my function would eventually return an "OSerror wlan.scan() failed", but I don't seem to get that specific error anymore. Instead now the function will run quite happily until an indeterminate time in the future where it quietly stops working.
(Tried a couple ways to format this so it's readable. Haven't figured out the right tags yet...)
def wifirecorder():
global bssid, total
added = 0
res_file = open('results.txt', 'a')
results = sta_if.scan()
if not results:
pass
for ap in results:
if not ap[1] in bssid:
total += 1
added += 1
bssid.append(ap[1])
res_file.write(
str(ap[0].decode()) + ',' + str(ubinascii.hexlify(ap[1]).decode()) + ',' + str(
ap[2]) + ',' + str(ap[3]) + ',' + str(ap[4]) + ',' + str(
ap[5]) + '\n')
print('added ' + str(added) + ' access points')
res_file.close()
gc.collect()
[/code]
If I let the board scan from a stationary location, like just sitting here on my desk, it will run seemingly forever. Once I walk it around in the apartment complex in order to test its actual use-case, it breaks. I can seem to extend the life of the cycle by walking slowly enough to introduce 10~ new APs per scan but if the ESP suddenly starts finding a lot more brand-new APs, it seems to kinda crap out. My best guess is somewhere within that loop the board is running out of memory. That, or I'm needlessly over-working the board with something in my janky code....or the issue is originating from the scan() method.
Anyone have an idea? Or if not, what I could append to my function to try and catch where/how it's failing?
wlan.scan() failed, or silently "hangs" after a while
Re: wlan.scan() failed, or silently "hangs" after a while
The post is back, and hopefully the user too, maybe thanks to viewtopic.php?f=2&t=4413
DMWidgets and I shared a bunch by email while things were offline. In particular I drew their attention to the string concatenation and likelihood of fragmentation leading to out of memory errors from e.g.
See "String Concatenation" in http://docs.micropython.org/en/v1.9.3/e ... ained.html
Having done what they can with fixed buffers instead of string concatenation, they are now exploring the memory overhead of a menu module they were importing to try and improve things.
DMWidgets and I shared a bunch by email while things were offline. In particular I drew their attention to the string concatenation and likelihood of fragmentation leading to out of memory errors from e.g.
Code: Select all
str(ap[0].decode()) + ',' + str(ubinascii.hexlify(ap[1]).decode()) + ',' + str(
ap[2]) + ',' + str(ap[3]) + ',' + str(ap[4]) + ',' + str(
ap[5]) + '\n')
Having done what they can with fixed buffers instead of string concatenation, they are now exploring the memory overhead of a menu module they were importing to try and improve things.
Re: wlan.scan() failed, or silently "hangs" after a while
Props to Cefn for his help while I was "indisposed" during that confusing turn of events.
I changed the way the string gets concatenated/lowered the gc threshold and monitored the memory usage while trying to replicate the error. After running the specific function alone on a spare board I've determined, between its highs and lows, it just eats up too much ram when scan() returns 50~ APs on occasion. the overhead of my menu module and related functions chews up about 22k ram, if I'm looking at things correctly, so I'll have to figure out how to pare that down. It has it's own issue of eventually reaching recursion depth which I don't know how I'll fix.
While the function now runs fine 95% of the time, I'm still getting an "OSerror: scan() failed" issue which I don't know how to pick apart to troubleshoot so in the mean-time I've just been calling the function again on failure. I've spent too many hours on this whole issue anyhow!
I changed the way the string gets concatenated/lowered the gc threshold and monitored the memory usage while trying to replicate the error. After running the specific function alone on a spare board I've determined, between its highs and lows, it just eats up too much ram when scan() returns 50~ APs on occasion. the overhead of my menu module and related functions chews up about 22k ram, if I'm looking at things correctly, so I'll have to figure out how to pare that down. It has it's own issue of eventually reaching recursion depth which I don't know how I'll fix.
While the function now runs fine 95% of the time, I'm still getting an "OSerror: scan() failed" issue which I don't know how to pick apart to troubleshoot so in the mean-time I've just been calling the function again on failure. I've spent too many hours on this whole issue anyhow!