DuetLapse3
-
Hello,
Trying out 3.2.0 and running into the following issue (below). The print starts fine and captures a handful of images till the connection reset issue. Both the duet and the pi are running on the same wifi subnet, and the duet is the latest firmware version.
running with the following options (have more logs if needed)
/usr/bin/python3 /home/pi/Desktop/images/DuetLapse3.py -port 8181 -verbose -duet 172.16.37.118 -detect layer -camera1 stream -weburl1 http://127.0.0.1:8080/?action=stream
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3.7/threading.py", line 917, in _bootstrap_inner
self.run()
File "/usr/lib/python3.7/threading.py", line 865, in run
self._target(*self._args, **self._kwargs)
File "/home/pi/Desktop/images/DuetLapse3.py", line 1068, in captureLoop
oneInterval('Camera1', camera1, weburl1, camparam1)
File "/home/pi/Desktop/images/DuetLapse3.py", line 612, in oneInterval
zn = getDuetLayer(apiModel)
File "/home/pi/Desktop/images/DuetLapse3.py", line 733, in getDuetLayer
r = requests.get(URL, timeout=5)
File "/usr/lib/python3/dist-packages/requests/api.py", line 75, in get
return request('get', url, params=params, **kwargs)
File "/usr/lib/python3/dist-packages/requests/api.py", line 60, in request
return session.request(method=method, url=url, **kwargs)
File "/usr/lib/python3/dist-packages/requests/sessions.py", line 533, in request
resp = self.send(prep, **send_kwargs)
File "/usr/lib/python3/dist-packages/requests/sessions.py", line 646, in send
r = adapter.send(request, **kwargs)
File "/usr/lib/python3/dist-packages/requests/adapters.py", line 498, in send
raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection abort -
@stuartofmt sorry but i have also a error for you
Exception in thread Thread-2: Traceback (most recent call last): File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 600, in urlopen chunked=chunked) File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 384, in _make_request six.raise_from(e, None) File "<string>", line 3, in raise_from File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 380, in _make_request httplib_response = conn.getresponse() File "/usr/lib/python3.7/http/client.py", line 1336, in getresponse response.begin() File "/usr/lib/python3.7/http/client.py", line 306, in begin version, status, reason = self._read_status() File "/usr/lib/python3.7/http/client.py", line 267, in _read_status line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1") File "/usr/lib/python3.7/socket.py", line 589, in readinto return self._sock.recv_into(b) ConnectionResetError: [Errno 104] Connection reset by peer During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/lib/python3/dist-packages/requests/adapters.py", line 449, in send timeout=timeout File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 638, in urlopen _stacktrace=sys.exc_info()[2]) File "/usr/lib/python3/dist-packages/urllib3/util/retry.py", line 367, in increment raise six.reraise(type(error), error, _stacktrace) File "/usr/lib/python3/dist-packages/six.py", line 692, in reraise raise value.with_traceback(tb) File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 600, in urlopen chunked=chunked) File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 384, in _make_request six.raise_from(e, None) File "<string>", line 3, in raise_from File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 380, in _make_request httplib_response = conn.getresponse() File "/usr/lib/python3.7/http/client.py", line 1336, in getresponse response.begin() File "/usr/lib/python3.7/http/client.py", line 306, in begin version, status, reason = self._read_status() File "/usr/lib/python3.7/http/client.py", line 267, in _read_status line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1") File "/usr/lib/python3.7/socket.py", line 589, in readinto return self._sock.recv_into(b) urllib3.exceptions.ProtocolError: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer ')) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/lib/python3.7/threading.py", line 917, in _bootstrap_inner self.run() File "/usr/lib/python3.7/threading.py", line 865, in run self._target(*self._args, **self._kwargs) File "/home/pi/DuetLapse/DuetLapse3.py", line 1041, in captureLoop duetStatus=getDuetStatus(apiModel) File "/home/pi/DuetLapse/DuetLapse3.py", line 707, in getDuetStatus r = requests.get(URL, timeout=120) #Long timeout to handle restart of Duet File "/usr/lib/python3/dist-packages/requests/api.py", line 75, in get return request('get', url, params=params, **kwargs) File "/usr/lib/python3/dist-packages/requests/api.py", line 60, in request return session.request(method=method, url=url, **kwargs) File "/usr/lib/python3/dist-packages/requests/sessions.py", line 533, in request resp = self.send(prep, **send_kwargs) File "/usr/lib/python3/dist-packages/requests/sessions.py", line 646, in send r = adapter.send(request, **kwargs) File "/usr/lib/python3/dist-packages/requests/adapters.py", line 498, in send raise ConnectionError(err, request=request) requests.exceptions.ConnectionError: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by p eer'))
-
@jnofsinger said in DuetLapse3:
File "/home/pi/Desktop/images/DuetLapse3.py", line 733, in getDuetLayer
r = requests.get(URL, timeout=5)Your command is almost identical to one I used successfully yesterday - the only meaningful difference being -verbose.
The problem does not look like there was a timeout issue - if there was there should be a message in the logs like:
getDuetLayer failed to get data. Code: <some number> Reason: <some text>
SO that points to a communication issue between the pi and the Duet i.e. it looks like it could not even connect. The fact that it worked sometimes makes it hard to track down and suggests that the basic code is ok.
Let me thing about how to trap the connection issue and report it - although to be frank, I don't want to disappear down the rabbit hole of debugging Duet connections
In any case, in parallel, can you trawl through the WDC forum and see what discussions are taking place on connection issues. My sense is that you will need to address some aspect anyway , independently of anything I can do in the code.
I hope to have a patched version for you to try later today / tomorrow but as I said , I doubt it will fix anything - maybe just allow Duet to report the error or try a little harder.
-
@SIam :
It looks like you are both experiencing the same issue. Are you both using SBC ?
Please try this version. I restructured the API calls and put in some exception handling for network connection issues and for timeouts. The messages will appear in the output. The code will try to re-establish a connection and continue on if it is successful.
It will eventually give up after a few minutes.
In any case it will give some clues as to what is happening.
I tested this in three ways (1) turning off the network on the machine running DuetLapse3 and (2) turning off my printer (3) repeatedly hitting emergency stop in DWCThis will show as version 3.2.1. Please report back.
-
I have a Duet Wifi 1.01 board. it has been with me for a very long time and is impossible to kill ;).
I can just have the program open and it will throw those errors even when not printing. If I switch it to take picture every x seconds it will work fine. Your idea of some type of communication issue between the pi and duet is correct. I also have the webcam from the duet pointing to the same URL for a quick print and it stays connected.
I will try it again with the .1 version and see if it improves. Also I will remove the webcam url from the duet itself to see if something differs.
Thanks
Jim -
@jnofsinger said in DuetLapse3:
If I switch it to take picture every x seconds it will work fine.
Hmm - I'd love it if that was a clue but from a codepoint of view it asks Duet to report the current layer even if its just capturing images every 'nnn' seconds. So in theory* - that should not make any difference. But we shall see .....
- --> As I often say: "There is no difference between theory and practice -- except in practise"
-
So far so good! I have a 72 frame capture and will print another test. The logs are clean and did not show any disconnects. Will continue to test it tonight and let you know.
Great program for the duet. I do have a question, do you plan on offering a flag to flip images with the ffmpeg processing? My camera is flipped as it comes from the top of my Ender3.
Thanks,
Jim -
@jnofsinger said in DuetLapse3:
@stuartofmt
do you plan on offering a flag to flip images with the ffmpeg processing? My camera is flipped as it comes from the top of my Ender3.Thanks,
JimJim - I do not plan to do this. I have spent some time trying and failed. The reason is that there are just too many versions of ffmpeg out there and finding a command sequence that actually works across many of them is a (time-consuming) art-form. For example: using "rotate" may or may not work on playback, using "transpose" does not work on the version of ffmpeg that I have .
In any case - I believe a better solution is to rotate at the source. That way you can also monitor the print the right way up
The program you are using to stream the video should (hopefully) have the ability to set the port and also to rotate the images before streaming. If not - you may be able to find another streaming program for your setup.If you are using a Pi and a Pi camera -- here is what I use.
http://picamera.readthedocs.io/en/latest/recipes2.html#web-streamingSo far so good! I have a 72 frame capture and will print another test. The logs are clean and did not show any disconnects. Will continue to test it tonight and let you know.
Just to be clear - I did not do anything to fix the connection problem. I just try to ignore it and hope it will go away. If there are connection problems - these will be reported in the console / log. If you are not seeing these messages "There was a network failure:..." followed by several lines of explanation -- then the previous issue has mysteriously gone away (at least for now)
Good Luck.
-
A small update to reflect the recent test code on handling Duet connectivity issues plus a couple of cosmetic tweaks.
###Version 3.2.2###
[1] Added resilience to lost connectivity with Duet. If disconnected the issue will be reported and attempts to reconnect will be made
[2] Made some cosmetic changes to the http responses. Most now include the local time as part of the response.
[3] The status page will automatically refresh every 60 seconds. Other pages will show the last time they were invoked.
[4]Similar changes to [2] and [3] made to startDuetLapse -
Another small update. For those using windows (c'mon I know you are out there !). There were some inconsistencies in the way python3 provided some operating system information.
###Version 3.2.3###
[1] Fixed some inconsistencies when running on Windows due to slightly different behavior of python3.
-
This post is deleted! -
This post is deleted! -
You posted a problem you encountered about using -camparam1 from startDuetLapse3.py and have since deleted it. I am making this post for the benefit of others.
Basically - you noted that starting an instance of DuetLapse3 from startDuetLapse3 failed when the command was of the form
http://{ip:port}/?command=start&args={some DuetLapse3 options} -camparam1="'{some camera parameters}' +fn+debug"
I tested your command options on my pi (with pi camera) in "standalone mode and it worked fine.
I then tested it by starting with startDuetLapse3 (running in foreground so I could see more of what was happening) and it failed just as you had reported.
The problem is because "+" symbols are not allowed in urls. To overcome this when using startDuetLapse3 or otherwise sending a URL - substitute "%2B" for the plus symbols (no quotes). E.g.
http://{ip:port}/?command=start&args={some DuetLapse3 options} -camparam1="'{some camera parameters} ' %2Bfn%2Bdebug"
Also - make sure there is a space between the last camera parameter and the fn argument since some commands will be expecting one. E.g.
<snip> --output ' %2Bfn%2Bdebug ^ space here between the t and the '
I will update the documentation to alert others to this "trap for young players" - like me
Note: there may be an additional issue which I am looking into. -
@stuartofmt Just to clarify, the issue in my specific case was a missing space after --output and the closing single quote in -camparam1, which was causing the filename to be appended to the end of the argument with no space in between. Turning on -verbose showed me my error, which was a stupid one, and therefore I chose to hide my shame by deleting the original post
-
@GoremanX said in DuetLapse3:
@stuartofmt Just to clarify, the issue in my specific case was a missing space after --output and the closing single quote in -camparam1, which was causing the filename to be appended to the end of the argument with no space in between. Turning on -verbose showed me my error, which was a stupid one, and therefore I chose to hide my shame by deleting the original post
Hmm - maybe I got it wrong too (about the escape characters) . Can you post your working command please - so I can take a closer look?
-
@stuartofmt You were right, the + symbol in the url was also an issue. The reason I got it working by just adding the missing space is because I was testing directly with the DuetLapse3.py file. My new, working http request is:
http://localhost:8083/?command=start&args=-dontwait -verbose -duet 192.168.220.2 -basedir /mnt/remote -seconds 15 -detect none -instances single -camera1 other -camparam1="'raspistill --nopreview --timeout 1 --saturation 15 --sharpness 50 --contrast 25 --ev 1 --quality 95 --awb off --awbgains 3.0,1.9 --shutter 50000 --ISO 100 --output ' %2Bfn%2Bdebug"
It did not work with + symbols in the url
-
Following from an off-line discussion with @GoremanX here is my proposal. You will get the gist of his suggestions. Appreciate your comment and ideas on what you would find useful or any alternative approaches that may apply.
I think the best compromise approach is as follows. Trying for a simple and consistent way that does not force folks into linux / windows.
Create logfiles with a timestamp (e.g. YY-MM-DD-HH:MM:SS.log)
Log files are created one per instance of DuetLapse and placed in the "ip" directory as they are now.
New option -keeplogs (default False if omitted). The default maintains the current behavior with a slight twist - deletes ALL logfiles in the "ip" directory on startup. If set to True log files will accumulate but can be cleared out by setting --keeplogs False. Users that want to can always go into the command line and self-manage log files by always having -keeplogs True.New option -createvideo (default True if omitted). The default maintains the current behavior. If False then no video is created on "restart" or "terminate" BUT will be created on "restart"
New option -keeppics (default True if omitted). The default maintains the current behavior i.e. pictures are kept until the next instance runs. If False the pictures are deleted immediately after the video is created (on "terminate"). If -createvideo is false then the pictures are not deleted.
Note that this needs a little more thought since I had a "todo" to address the possible situation (unhandled at the moment) of more than one instance of DuetLapse3 running against the same duet "ip". -
I think this part needs clarification because it's contradictory the way it's currently written:
@stuartofmt said in DuetLapse3:
New option -createvideo (default True if omitted). The default maintains the current behavior. If False then no video is created on "restart" or "terminate" BUT will be created on "restart"
Beyond that, I like the proposed changes. It's more elegant than what I came up with. However, reading this just made me realize something:
@stuartofmt said in DuetLapse3:Note that this needs a little more thought since I had a "todo" to address the possible situation (unhandled at the moment) of more than one instance of DuetLapse3 running against the same duet "ip".
All my duet 3D printers have the same IP address They all sit behind their own respective pi 4 computers, they all run in standalone mode with the exact same ip address, and they all write their external files to the same shared directory over NFS. So that means they would all save their photos in the same 192-168-220-2 directory I do this so that I can use the exact same Raspbian SD card image on every pi without modification. The duet boards themselves don't talk to the network, the pi computers do all the talking for them using a DHCP-assigned address.
However each printer does declare a unique hostname in config.g, even if the network isn't aware of it. Is there a way for the script to try to get the board's hostname if it hasn't been declared in the -host parameter for file/directory name purposes?
-
For fun, my first timelapse using this script:
https://youtu.be/XjBwTqbEZD8 -
@GoremanX That was a pretty weird timelapse.