I'm using AT commands to send data over http, but the problem is that sometimes the program has an error and wont run again until I reboot and the GSM. Im using a crontab and also running the file as local file on boot. How could I fix the program to just begin the script again? How do I fix segmentation fault error.
-
This is not a valid program, so it's not clear what's happening. Segmentation fault means you're writing to an illegal memory address somewhere (or a library that you're calling is), but there's no way to tell where that's happening with this fragment of code.– BrickJun 7, 2019 at 15:34
-
Hello. Could you move the error message from your comment to the question, reading it all bunched up with no formatting is a little difficult.– Roger JonesJun 7, 2019 at 18:23
-
Getting better. Now we have the program but we don't know where the error occurs.– BrickJun 7, 2019 at 18:46
-
1This is not a Pi question, but a general programming question. You are asking us to debug a poorly structured python program. You should split the code into modules and debug each module– MilliwaysJun 7, 2019 at 23:52
-
@Milliways I meant to tag python actually, and I don't believe I asked you to debug anything. I was just asking those that might know something about the error to take a look. I didn't say it was perfect; however does have days were errors don't occur. I appreciate you're feedback.– 00BEARJun 8, 2019 at 3:21
1 Answer
Obviously, the interpreter is attempting to iterate result
, which (in the case your program crashes) isn't iterable because it's of typeNoneType
. It seems like execute()
returns None
in result = execute(cmd)
. Looking at that function, there are two possibilities:
port.read(100).decode()
returnsNone
. That's unlikely the case because the function is supposed to return an iterable type. ReturningNone
in any case is prone to crashes and bad practice.There is an exception in
execute()
. In this case (except
) the function will not return anything (None
) which I'm pretty sure is what crashes your program.
-
-
I think, it answers this question at least. Whether the question is on raspberry pi or not is another story.– Sim SonJun 10, 2019 at 16:00
-