Open Vishal-Birajdar opened 1 day ago
Do you ever read your own posts after you've sent them?
You are not the first or the last person to format code incorrectly. The code must be enclosed with code tags. https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax#quoting-code
You can also edit your original post.
Do you ever read your own posts after you've sent them?
You are not the first or the last person to format code incorrectly. The code must be enclosed with code tags. https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax#quoting-code
You can also edit your original post.
I posted issue first time on gitbub . sorry for mistakes
Just put your code in Code Tags, that other users could help.
@Vishal-Birajdar Thanks for the clear description of the problem. I've changed the """
in your post to ```py
so the code highlights correctly.
It's not possible to investigate a bug report without the code to reproduce it, and the code posted above is not complete or runnable - the ota
, shared
, and x
modules are missing, for example.
My best guess is there are two likely possibilities for what is happening here:
x.message_callback
) is calling back around into some other function which eventually recurses.If that's not enough to solve the problem, suggest you remove or disable code in your program and re-run until you find a version which doesn't crash. If you do this carefully, you may find the root cause of the problem yourself. If you don't succeed to find the root cause, you may end up with a minimal working example that we can use to diagnose the bug.
Oh, I looked again and there is actually recursion here:
def mqtt_connect():
try:
print("Attempting to connect to MQTT broker...")
# (removed some lines)
except Exception as e:
mqtt_connect()
# (removed more lines)
The exception handler for mqtt_connect()
calls mqtt_connect()
, so each time the connection fails you are pushing a frame on the stack. If the network goes down then it could easily call into itself many times. Try restructuring the code with a while loop around the outside of the try/except instead of using recursion.
That suggested structure would look something like
def mqtt_connect():
while True:
try:
print("Attempting to connect to MQTT broker...")
# (removed some lines)
break # Exit the loop if the connection is successful
except Exception as e:
print(f"Connection failed with error: {e}. Retrying...")
# wait some time
# (removed more lines)
this is my another file where i declare callback function.
class call_loop:
def __init__(self):
pass
def callback(self,topic_cmd,msg):
decoded_topic = topic_cmd.decode('utf-8').strip()
decoded_msg = msg.decode('utf-8').strip()
#print("decoded_topic:"+decoded_topic)
#print("decoded_msg:"+decoded_msg)
if decoded_topic.endswith("FD"):
print("decoded_topic:"+decoded_topic)
if decoded_msg == "1105":
shared.buffer["FD"] = "1105"
shared.FG_Arm = True
print("shared.FG_Arm ",shared.FG_Arm)
shared.string_json = json.dumps(shared.buffer)
elif decoded_msg == "0105":
shared.buffer["FD"] == "0105"
shared.FG_Arm = False
print("shared.FG_Arm ",shared.FG_Arm)
shared.string_json = json.dumps(shared.buffer)
else:
print("Invalid Input !")
shared.string_json = json.dumps(shared.buffer)
shared.client.publish(shared.topic_json,shared.string_json)
I am remove the try and exception but same issue again Is this error hardware related?, because I have soldered the controller on my I/O board.
Port, board and/or hardware
Pi Pico w
MicroPython version
MicroPython v1.22.2 on 2024-02-22; Raspberry Pi Pico W with RP2040
Expected behaviour
No response
maximum recursion depth exceeded occurdue to mqtt connection problem and reconnection problem. after hours code stuck automatically and mqtt not reconnected
I am not using any recursion or thread in my code but running a code after some time occuremaximum recursion depth error .
Additional Information
I am working on Iot project there is three .py file one is for main logic and other is varibale declared which used in all three file. and third file is main.py here i impleted wifi,mqtt and in loop I check the 4 gpio input (for any detection) and then call the main logic function which is define in another file,and checking the wifi connection status continously.
after running a code 10-15 min working ok then i got two error 1) maximum recursion depth 2) mqtt connection lost automatically
Code of Conduct
Yes, I agree