Reset after a few minutes

after a few minutes show this error:

ets Jan 8 2013,rst cause:2, boot mode:(3,6)

load 0x40100000, len 32528, room 16

tail 0

chksum 0x5c

load 0x3ffe8000, len 2280, room 8

tail 0

chksum 0x4d

load 0x3ffe88f0, len 7696, room 8

tail 8

chksum 0x90

csum 0x90

This reset is propably due to exception error from the code, Please double check the code again for some exception errors :smile:
If you want, Have a look at this reply for the reset codes.

my code works for a few minutes and then reset.I realized that the reset is not because of the port and it’s because of my code.In the while loop, if I increase the amount of sleep, it won’t reset, but I don’t want to increase the runtime.what can i do?

I used thread in my code and when i dont use thread nodemcu dont reset!!!

Could you post the whole code please? :smile:
I’ll have a look at it and help if I can.

import streams
import gpio
import threading
import json

s=streams.serial()
data = s.read(638)
s1= data.split(’-’)
s.close()

gpio.mode(D0, OUTPUT)
gpio.mode(D4, OUTPUT)
gpio.mode(D1, INPUT)
gpio.mode(D2, INPUT)
gpio.mode(D3, INPUT)
gpio.mode(D5, INPUT)
gpio.mode(D6, INPUT)
gpio.mode(D7, INPUT)
gpio.mode(D8, INPUT)

gpio.low(D0) 
gpio.low(D4) 





par1=s1[0]
par1=par1.replace("\'", "\"")
par1=json.loads(par1)
par2=s1[1]
par2=par2.replace("\'", "\"")
par2=json.loads(par2)

item1=s1[2]
item1=item1.replace("\'", "\"")
item1=json.loads(item1)
item2=s1[3]
item2=item2.replace("\'", "\"")
item2=json.loads(item2)

branch1=s1[4]
branch1=branch1.replace("\'", "\"")
branch1=json.loads(branch1)
branch2=s1[5]
branch2=branch2.replace("\'", "\"")
branch2=json.loads(branch2)



node_li1=s1[6]
node_li1=node_li1.replace("\'", "\"")
node_lis1=json.loads(node_li1)
node_li2=s1[7]
node_li2=node_li2.replace("\'", "\"")
node_lis2=json.loads(node_li2)

node_list1=[]
node_list2=[]

for i in node_lis1.items():
    node_list1.append(i[1])
for i in node_lis2.items():
    node_list2.append(i[1])

def analyze(tree_num):
sum_ = 1
t = True
q = True
d = None
dd = None
ddd = None
for x in node_list[tree_num]:
if x == ‘t’:
sleep(timer1)

        elif x in visited[tree_num]:
            pass
        else:
            if q:
                if t:
                    if len(branch[tree_num][x]) == 1:
                        if x in item[tree_num]:
                            sum_ = sum_ and int(items[item[tree_num][x]])
                            visited[tree_num].append(x)
                    elif len(branch[tree_num][x]) == 2:
                        sum_ = sum_ and int(items[item[tree_num][x]])
                        visited[tree_num].append(x)
                        temp1 = 1
                        temp2 = 1
                        t = False
                    elif len(branch[tree_num][x]) == 3:
                        sum_ = sum_ and int(items[item[tree_num][x]])
                        visited[tree_num].append(x)
                        tmp1 = 1
                        tmp2 = 1
                        tmp3 = 1
                        q = False
                else:
                    if x in item[tree_num]:
                        if d == x:
                            t = True
                            sum_ = sum_ and (temp1 or temp2)
                            sum_ = sum_ and int(items[item[tree_num][x]])
                            visited[tree_num].append(x)
                        elif len(par[tree_num][x]) == 1:
                            temp1 = temp1 and int(items[item[tree_num][x]])
                            visited[tree_num].append(x)
                        elif len(par[tree_num][x]) == 2:
                            temp2 = temp1
                            temp1 = 1
                            d = x
            else:
                if x in item[tree_num]:
                    if ddd == x:
                        q = True
                        sum_ = sum_ and (tmp1 or tmp2 or tmp3)
                        sum_ = sum_ and int(items[item[tree_num][x]])
                        visited[tree_num].append(x)
                    elif len(par[tree_num][x]) == 1:
                        tmp1 = tmp1 and int(items[item[tree_num][x]])
                        visited[tree_num].append(x)
                    elif len(par[tree_num][x]) == 3:
                        if dd == x:
                            ddd = x
                            tmp3 = tmp1
                            tmp1 = 1
                        else:
                            tmp2 = tmp1
                            tmp1 = 1
                            dd = x
    print(sum_)
    result[tree_num].append(sum_)
    if tree_num == 0:
        if sum_ == 1:
            #digitalWrite(D5, HIGH)        
            gpio.high(D0) 
        else:
            #digitalWrite(D5, LOW)
            gpio.low(D0)      
   
    elif tree_num ==1:
        if sum_ == 1:
            #digitalWrite(D5, HIGH)         
            gpio.high(D4) 
        else:
            #digitalWrite(D5, LOW)
            gpio.low(D4)

    def p(t_n):

    while (1):
        if t_n == 0 :
            v1 = digitalRead(D5)
            v2 = digitalRead(D7)
        
            if v1 == 0:
                item1["v1"]="NO"
            else:
                item1["v1"]="NC"
        
        
            if v2 == 0:
                item1["v2"]="NO"
            else:
                item1["v2"]="NC"
        
        elif t_n == 1 :
        
            v4 = digitalRead(D2)
            v3 = digitalRead(D1)
    
            v5 = digitalRead(D3)

            v6 = digitalRead(D6)

        analyze(t_n)
        

        sleep(500)



thread(p,0)
thread(p,1)

I am sending a few Array through the serial port to nodemcu and analyze them using this method but reset after a few minutes.If this problem is not resolved. can i save the data and
dont wipe with a power outage?

do you have any ideas?

I think this could be solved by writing to the flash, please have a look atflash module and theflash examples. :smile:

Which address is good to use in nodemcu?

For the NodeMCU ESP-32S, according tothe Flash Layout, the free space for the user is at 0x00310000.

i have esp8266 what about this?