All the momentum of the start of the project seems to have come to a halt. My internet got disconnected accidentally during some upgrades down the street and it took my ISP two full weeks to get the connection back up. During this time I considered my mounting options and while I'm not happy with what I came up with I think it will suffice - I guess time will tell.
I mounted the pi on the dryer using doublesided tape. This is definitely the mount that I'm most worried about and expect to have to find another solution for quickly, but I expect it to suffice for a few weeks. I made some extender cables for the accelerometers and mounted them with zip ties to the points on the machines which seemed to be the most mechanically secure places on the backside.
The mounting point of the washing machine - at the metal part of the drain pipe.
Pi mounted on top of dryer and accelerometer mounted at a loop found at the top of the dryer.
With that done I connected to the pi and started my script (which had earlier been tested for 24 consecutive hours without issues), and was happy to see both sensors report data - for a while. After ~3 hours the data stream stopped and when I found out the next day the wifi had also dropped. Another attempt made a similar result, and I am theorizing something goes wrong (bug in code, blip in wifi, etc) the program crashes and then after a while the pi sends the inactive wifi to sleep. Normally I'd print to the terminal to help debug the issues but since I'm running the application seperate from the terminal session this was not possible. After thinking about writing to a local file I found it was possible to redirect the messages normally shown in the terminal to a file. To run a python script in a ssh session one would normally use the command 'python scriptname.py' but currently I run my script using this command
sudo setsid python gyrospreadx2.py >> Full_log.txt 2>&1 &
For others trying to break into python development on pi, let me break the way I run my script down. I'm still very green when it comes to linux so I probably use sudo a lot more than I should - I don't remember specifically anymore why I'm using it in this case actually, something in the script or writing output to a file probably.
setsid was added due to my findings from this stackexchange. It 'ensures the forked process will be re-parented by init' as goldilocks puts it in her answer. Again, I'm green in linux and not ensurely certain what init is, but I assume it is some sort of user which is active from the initiation of the os. The effect is that the script continues running when I shut down the SSH session. However it also has the effect that the normal messages printed to the terminal are not shown since the script is now running on another user - bummer.
The & in the endforks the process out so the pi can also do other stuff than running the script (as mentioned here)
>> Full_log.txt 2>&1 - This cryptic addition (also found on stackexchange) redirects the output from the terminal where it normally would be shown (given it was the user active in the terminal running the script) to a file, in this case Full_log.txt. It logs both normal messages and error messages which will turn out to be helpful in debugging the problems mentioned earlier. I had some issues getting this to work, as I had to create a file (using either nano or touch) and chmod the file to allow writing to it. This seemed cumbersome, so I am sure there is an easier way.
I might have gotten a few details wrong here and there (please sound off in the comments if you have suggestions, corrections etc!) but all in all this allows me to run the script after shutting down the ssh session and read the output history (after the script crashes). Two sessions had the exact same output:
Traceback (most recent call last):
File "gyrospreadx2.py", line 134, in <module>
accel_yout2 = read_word_2c(address2, 0x3d)
File "gyrospreadx2.py", line 37, in read_word_2c
val = read_word(address, adr)
File "gyrospreadx2.py", line 31, in read_word
high = bus.read_byte_data(address, adr)
IOError: [Errno 5] Input/output error
So it seems I am having (apparently random) issues reading my accelerometers. After the first attempt I inserted small delays between reading the inputs, but it did not fix the issue. Next attempt will be to try to encapsulate the communication with the i2c devices in some exception handling such as suggested here. The current setup also differs from the previous 'long term test' by the wifi not being powered by a powered usb hub - the additional power draw from the Pi's power draw might be what causes issues? In that case the exception handling, and additional tries would probably (hopefully) solve it.
So the project state, at the time of writing, is that I haven't found a permanent solution for mounting, the script has a serious bug when running for longer time and it seems the Pi drops the wifi connection is inactive for a while. While the last point isn't mission critical, it would be nice to not have to go down and reboot the Pi whenever the script has been inactive for a certain amount of time (the goal was to do less trips to the basement, not more!). I'll be trying out different solutions (, , ) but I do find it odd that the Raspbian image would ship with such a 'feature'.
The good news is that the script, when running, does work so I have gotten some new dual accelerometer data to analyze, which I'll cover in a later blog post.
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.
Instead of writing the log to a file, having to fork the process and the like, i suggest that you take a look at screen (http://raspi.tv/2012/using-screen-with-raspberry-pi-to-avoid-leaving-ssh-sessions-open).
This is a terminal that you can detach from and reattach from another terminal (ssh, direct, ssh via GPIO serial). It's pretty neat for running programs for longer periods of time!
Are you sure? yes | no