Not sure I have explained that well.
Using Pi4 + Raspberry Pi OS + Thonny +esp8266-20200911-v1.13.bin
Complete code is on page:131 on …Programming_with_ESP32_and_ESP8266...
This line works as expected:
elif motion and (time() – last_motion_time)>delay_interval:
and this one does not:
elif motion and (time() – last_motion_time)>delay_interval:
The error message is as per the title
Other than a difference in indentation (edit- which does not show in this post) I cannot see a difference between the two.
I typed the code myself and then when it would not run;
after checking and checking again I still got the above error:
I copied and pasted the one line from the Github repository.
Hi Steve.
Indentation can be two spaces or four spaces, it doesn’t matter as long as you use the same number of spaces throughout the code.
I’ve tested the code with four spaces and I didn’t get any errors. We usually provide our MicroPython scripts with two spaces because that occupies less space in the ESP32.
Usually, when the next line needs indentation the IDE does that for you when you press Enter. I think the default indentation in Thonny is 4 spaces. If your TAB gives four spaces, you can use TAB.
Take a look at your code line 13. There’s something missing.
It should be:
last_motion_time = time()
And not:
last_motion_time = ()
So, the IDE must be “thinking” that last_motion_time is a tupple (a Python variable type: https://www.w3schools.com/python/python_tuples.asp) which is not compatible with the type of operation you’re trying to do at line 26.
I hope this helps.
Regards,
Sara
About the one and only thing I know about Python is that indentation is paramount. Your post really doesn’t show the indentation at all. I’m relatively sure that the semi-colon makes no difference in Python – Other languages use it to terminate a statement. I would say that the “elif” (I’m guessing “else if”) must have exactly the same indentation as the “if” it’s paired with.
@Steve Mercer
I suspect you are correct. Possibly the issue is not in the code but the way Thonny “presents the code. What I mean by that is:
I have just retyped the code from line 20 onwards and the indentation given by Thonny is different to that which appears when I get the code from Github.
I am new to this.
I have not worked out if there is a way of controlling the level of indentation. I would assume that Thonny (version 3.3.3) being designed for beginners, would format a while true: statement correctly.
I have got the PIR Motion Sensor with Interrupts and Timers ‘thing’ to run by copying the code BUT I want to learn why it stalls at line 20 when I have typed it in myself
Hi Steve.
To understand your issue, I need to see the differences in indentation.
Can you show me your code? When you type it yourself (with indentation)? You can share your code using patebin, a link to github, google drive or any other method that is useful for you.
Regards,
Sara
Hello Sara
Thank you for responding.
I have not got my head around pastebin yet; from what I can make out I can only copy and paste and as I am not sure this will retain the indentation I have put both versions in Dropbox on the link below.
The error message is there too:
https://www.dropbox.com/sh/ibw2a6kjeejxyxb/AAATjEDG_Tyn2SuBzsNWZKo4a?dl=0
Now that I have spent quite a long time fiddling with this I have also come to the conclusion it’s the indentation that causes the problem. Just that I am not sure how to rectify incorrect indentation; backspace delete or the Tab key does not always give the result I am trying to achieve ie one that will match the layout in your github samples.
Are there hidden layout commands in the editor?
and
Is hitting the space bar x number of times the same as using the TAB key once?
(obviously I can delete the offending statement and retype)
Two additional points/thoughts
What is the statement
“TypeError: unsupported types for __sub__: ‘int’, ‘tuple'” telling me?
Googling did not yield anything helpful – at least not to a beginner!
Is there a glossary of error messages anywhere?
Note: I am making myself type code text as I find it helps get used to the syntax and come to that, the indentation(s)
Regards
Steve