> I am trying your firmware but it give this error after my UDP loop run for about 10 minutes.
Well, that's frustrating! The backtrace provides exactly zero information that I can use . Any way I can repro?
ESP32 reliability
Re: ESP32 reliability
My code.
>>>>>>>>>>>>
Code: Select all
import machine
import network
import time
import gc
from machine import Pin
import usocket as socket
from time import sleep
import _thread
import ubinascii
import esp
esp.osdebug(0)
#Global Variable
p22 = Pin(22, Pin.OUT, Pin.PULL_UP)
#All the inputs
ipins = [machine.Pin(i, machine.Pin.IN) for i in (36, 39, 34, 35, 32, 33, 25, 26)]
opins = [machine.Pin(i, machine.Pin.OUT) for i in (27, 14, 12, 13, 15, 23, 4, 21)]
#opins = [machine.Pin(i, machine.Pin.OUT) for i in (15, 2, 4, 21, 13, 12, 14, 27)]
gConfigList = []
gMyconfig = ""
gMode = ''
gSTA_IP = ''
gAP_IP = ''
gSSID = ''
gPW = ''
gSTA_SSID=''
gSTA_PW=''
port=10086
rec_port=10087
gHBCount = -1
gi = 1
data1 = ''
ip = ''
MAC = ''
inp1 = 0
inp2 = 0
inp3 = 0
inp4 = 0
inp5 = 0
inp6 = 0
inp7 = 0
inp8 = 0
total = 0
totalstr = ''
gTotalCount = 0
gTCStr = ''
gClient = 0 # 0 no client, 1 got client
gOutputByte=''
giOutput = 0
giTempValue = 0
gConnected = 0 #Client connected
gMemFree = 0 #Memory Free
gLowCount = 0
def thread_master_scan_io():
global p22
while True:
#get the resource value
p22.value(1)
time.sleep(0.5)
p22.value(0)
time.sleep(0.5)
def load_config_file(filename):
global gConfigList
global gMyconfig
global gMode
global gAP_IP
global gSTA_IP
global gSSID
global gPW
global gSTA_SSID
global gSTA_PW
f=open(filename,"r")
sleep(1)
ConfigList = list(f)
sleep(1)
f.close
sleep(1)
LineCount = 0
print(ConfigList)
for item in ConfigList:
print( LineCount)
LineCount = LineCount+1
print (item.rstrip('\n'))
print (item.rstrip('\r'))
gMyconfig = str(item.rstrip('\r\n'))
print(gMyconfig)
pos = gMyconfig.find("MODE")
if pos >= 0:
gMode = (gMyconfig.split("=")[1])
print(gMode)
pos = gMyconfig.find("STA_IP")
if pos >= 0:
gSTA_IP = (gMyconfig.split("=")[1])
print(gSTA_IP)
pos = gMyconfig.find("AP_IP")
if pos >= 0:
gAP_IP = (gMyconfig.split("=")[1])
print(gAP_IP)
pos = gMyconfig.find("AP_SSID")
if pos >= 0:
gSSID = (gMyconfig.split("=")[1])
print(gSSID)
pos = gMyconfig.find("AP_PW")
if pos >= 0:
gPW = (gMyconfig.split("=")[1])
print(gPW)
pos = gMyconfig.find("STA_PW")
if pos >= 0:
gSTA_PW = (gMyconfig.split("=")[1])
print(gSTA_PW)
pos = gMyconfig.find("STA_SSID")
if pos >= 0:
gSTA_SSID = (gMyconfig.split("=")[1])
print(gSTA_SSID)
load_config_file('config.txt')
count = -1
pos1 = gMode.find("AP")
if pos1>= 0:
print("AP Mode")
ap = network.WLAN(network.AP_IF) # create access-point interface
#ap.config(essid='TCOS-IO',authmode=network.AUTH_WPA_WPA2_PSK,password='abc123456') # set the ESSID of the access point
ap.config(essid = gSSID,authmode=network.AUTH_WPA_WPA2_PSK,password = gPW) # set the ESSID of the access point
#ap.config(max_clients=1) # set how many clients can connect to the network
#ap.ifconfig(('192.168.5.4', '255.255.255.0', '192.168.5.1', '8.8.8.8'))
ap.ifconfig((gIPAddress, '255.255.255.0', gIPAddress, '8.8.8.8'))
ap.active(True) # activate the interface
ip = gAP_IPA
else:
print("STA Mode")
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(gSTA_SSID, gSTA_PW)
while(wlan.isconnected() == False):
time.sleep(1)
ip = wlan.ifconfig()[0]
print(ip)
MAC = ubinascii.hexlify(wlan.config('mac'),':').decode()
print(MAC)
gSTA_IP = ip
# sendtcp is not use
def sendtcp(host, port):
global count
count = count + 1
data = b'@hello tcp,' + str(count ) + b'*'
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
#socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
print("data is type {}".format(type(data)))
sock.connect((host, port))
while True:
data = sock.recv(500)
print (str(data),'utf8',end='')
#Look for header
pos1 = data.find(b'@')
if pos1 >= 0:
sock.send(data)
print('sent')
sock.close()
s=socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)
s.bind((ip,port))
_thread.start_new_thread(thread_master_scan_io, ())
while gClient == 0:
data,addr=s.recvfrom(1024) # wait for PC/Client to connect, this is nlocking mode
pos = data.find(b'IsTCOSWifiThere')
if pos >=0:
print('Client Query, reply with IP and MAC')
print(addr)
print(data)
s.sendto('@Yes'+','+ip+','+MAC+',*',addr)
#gClient = 1
else:
#Look for Connect String
pos = data.find(b'Connect')
if pos >=0:
print('Client Connected')
print('Go into scanning loop')
s.sendto('@Connected*',addr)
gConnected = 1
#addr = socket.getaddrinfo('192.168.0.136', 10086)[0][-1]
s.setblocking(0) #non block mode
while gConnected == 1:
try:
inp1 = ipins[0].value()
inp2 = ipins[1].value()
inp3 = ipins[2].value()
inp4 = ipins[3].value()
inp5 = ipins[4].value()
inp6 = ipins[5].value()
inp7 = ipins[6].value()
inp8 = ipins[7].value()
total = (inp8 << 7) + (inp7 << 6) + (inp6 << 5) + (inp5 << 4)+ (inp4 << 3) + (inp3 << 2) + (inp2 << 1) + inp1
totalstr = '{0:02X}'.format(total)
gTotalCount = gTotalCount+1
gTCStr = '{0:08X}'.format(gTotalCount)
#Sent input status to client
s.sendto('@I,'+totalstr+gTCStr+'*',addr)
gMemFree = gc.mem_free()
if gMemFree <= 50000:
print('Low Memory')
gLowCount = gLowCount + 1
print(gLowCount)
gc.collect()
data,addr=s.recvfrom(1024) #Check if we received anything from UDP, non blocking
print('data read is: ',data)
#Process the msg from Client
pos = data.find(b'@O,') #set output command
if pos >=0:
#@OFFxx*
#@O,FF*
gOutputByte = data[3:5]
#set the output base on the result
print('output byte is: ',gOutputByte)
#Process the output bit sent from the client and set output
giOutput = int(gOutputByte,16)
giTempValue = giOutput & 0x01
opins[0].value(giTempValue)
giTempValue = (giOutput & 0x02)>>1
opins[1].value(giTempValue)
giTempValue = (giOutput & 0x04)>>2
opins[2].value(giTempValue)
giTempValue = (giOutput & 0x08)>>3
opins[3].value(giTempValue)
giTempValue = (giOutput & 0x10)>>4
opins[4].value(giTempValue)
giTempValue = (giOutput & 0x20)>>5
opins[5].value(giTempValue)
giTempValue = (giOutput & 0x40)>>6
opins[6].value(giTempValue)
giTempValue = (giOutput & 0x80)>>7
opins[7].value(giTempValue)
gHBCount = gHBCount + 1
if gHBCount % 10000 == 0:
print('data read is: ',data)
gc.collect()
print('where:', str(gc.mem_free()))
sleep(0.0005)
else:
pos = data.find(b'@Disconnect') #set output command
if pos >=0:
s.sendto('@Disconnected*',addr)
gConnected = 0
print('Disconect from Client')
s.setblocking(1) #block
except OSError as e:
if e.args[0] == 104:
print('where:', str(gc.mem_free()))
break
continue #if other error or nothing received from the UDP just continue,
sleep(0.001) #Sleep 1ms
else:
print('No Client attached')
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: ESP32 reliability
@tve Running your build with the pending PR's the ESP32 still reboots occasionally.
As I said before my WiFi suffers from brief outages (roughly one per hour). I've never found the reason, which has persisted through three instances of AP. I still see these outages on a project I completed nearly 15 years ago so it's certainly nothing to do with MicroPython Yet on PC's and tablets the WiFi is fine.
I suspect the reboots may be associated with outages, although the vast majority pass without a reboot. This would perhaps explain why you aren't seeing reboots.
As I said before my WiFi suffers from brief outages (roughly one per hour). I've never found the reason, which has persisted through three instances of AP. I still see these outages on a project I completed nearly 15 years ago so it's certainly nothing to do with MicroPython Yet on PC's and tablets the WiFi is fine.
I suspect the reboots may be associated with outages, although the vast majority pass without a reboot. This would perhaps explain why you aren't seeing reboots.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.