Adventures in pi
This post contains code and is a bit techy. You have been warned….
Last month I took the plunge, and decided to subscribe to Magpi. For a couple of reasons.
I missed out on the free Pi Zero last year (despite not having a use case for one, I want one)
I missed out on the Google AI kit that they gave way recently because I couldn’t find a copy of the magazine in any local shops.
There was a deal with a free Pi Zero W when you subscribed.
Related to this was the fact that the Raspberry Pi 2 in the office doing sterling duty as a small web server and basic home automation system (internal network access only to light control and doubling up as a bit of a small online radio player) and hadn’t been updated for a long time (I was happy with it just doing
Anyhoo, After a bit of googling and a chat with people on twitter who know more than me regarding these things, I decided it was time to update the OS (called Raspbian) from Wheezy to Jessie (if this is all gibberish then imagine an update from windows 7 to windows 8 as an analogy). This would (possibly) mean that the SD card powering the current Raspberry Pi 2 could be transferred to the new Pi Zero W and free up the Pi 2 for new and interesting projects (Again, unknown and no plans, but you never know).
Up until now I have used ssh to access the Pi 2 in the office (It’s a clever way of connecting from a different PC and being able to type commands onto the Pi), so I duly logged into the Pi 2 and did and update…
sudo apt-get update sudo apt-get upgrade
As I’ve done before and all went well. Now came the new step.
sudo apt-get dist-upgrade
To get the most up to date distribution (That’s what the ‘dist’ bit means).
Well, everything seemed to be going great guns, until the Pi 2 decided that it wold disconnect from the ssh on my laptop. Okay…so, it might need to reboot, or update that part of the operating system. I was fine with that and left the Pi alone for 12 hours.
The next evening, I logged back in to ssh and the Pi was happily sitting there as usual. A quick check of the version details with
and nothing had changed. Still running Wheezy. Google, yup, that’s the correct command, okay, let’s try that again.
sudo apt-get dist-upgrade
Funnily enough, this did *exactly* the same as before. The upgrade got so far and I was kicked off the Pi…
Off I go to work the next morning, safe in the knowledge that I’m doing the right thing.
Guess what? Yup. Same thing happened.
Insanity: doing the same thing over and over again and expecting different results.
– Albert Einstein
So… What’s next then?
Well, I decided to do some more thorough searching on Google and nothing obvious jumped out at me. After wasting an entire evening searching I decided to check tomorrow evening with the Pi connected to a screen of some sort. To see exactly where the process was hanging.
Now, I don’t have a free HDMI port on my TV at the moment so I used my projector and threw the Pi out put onto the wall in my living room.
Which was fine, apart from the fact that you had to pretty much try and guess what the code on screen was. However, it did let me know what the problem was.
I completely forgot that the update process would require some input from me, and, as the ssh kept kicking me out I didn’t see when the update got to this point. Each time I logged back onto the pi I started a new remote update process, which got to a specific point and then waited for input. A quick
showed that I had started about 6 update processes all of which got to the first user prompt and waited. Ooops.
This time, I answered each user prompt with a bash of the “y” key and everything progressed as it should have done.
Yay! I’ve done an update to Jessie. Well, actually, no. I hadn’t.
What I had done is update *most* of the system. It worked and
was reporting Jessie, which was good.
You can sense a “but” coming here can’t you? That’s right…
*But* not all of the installed software had updated. So a quick run of
sudo apt-get update sudo apt-get upgrade
and all was good? Nope. Afraid not. Some of the updates still looked for the old system version…
At this point I was rapidly losing the will to live. The system was live and was doing everything it should be doing, but I wasn’t happy.
I hope I don’t have to do a wipe and reinstall.
Another search online and I found the file I needed to edit and boom, everything was up to date. Brilliant. Off I went to bed safe in the knowledge that it was a job well done.
As it turns out, I was soon to realise that upgrading in this way is possibly the most time consuming way…
A couple of days later it grew dark outside and I wanted to turn the lights on. I dived for my trusty phone and visited the internal server and turned the lights on. Except I didn’t. Nothing happened. Hmmmm… that’s odd. A reboot of the Pi and we were in business again.
For about 24 hours.
A quick search online led to an issue with the wireless USB dongle I was using with the newly updated software. A few lines added to stop the power management kicking in and we were good to go.
Except we weren’t. Every few days the wifi would drop out and I would be unable to connect to the web server or the Pi through ssh. It worked about 90% of the time, and every now and then would require a reboot. No warning or anything – it would just stop working.
It’s a big job to wipe the SD card and start again. I’d have to reinstall all the scripts and re-code all the web server stuff, which I didn’t really want to do. I tried many things and nothing worked. Intermittently the Pi would lose internet connection.
A few weeks of this erratic behaviour later and I decided to bite the bullet and wiped the SD card. I installed the new version of Raspbian. A nice shiny clean desktop awaited and I set about getting the system back up to speed.
A few steps later and ssh was set up and working, the wifi was working (so far at least) and within a couple of hours I had the lights set up to work on a timer (hopefully) and next up is to recreate the basic webpage, some scripts to run from the website and to play with the internet radio setup.
I did have a script that used the current sunset time and changed the time the lights turned on each day, but I’m not sure I can remember how that script worked. The good news is that it looks like someone has already built something that can come to my rescue.
This (http://stenarson.com/projects/suncron/) appears to be a much more elegant solution than i created with my complicated and multiple batch files.
Plenty of interesting times ahead with changes I’m going to make on version 2.0 and even though I gave up and wimped out I learned an awful lot about how the system works behind the scenes and hopefully this will stand me in good stead for working on new projects.
Next time I’ll discuss my side project with my second Arduino Uno.
#Homeautomation #Magpi #Raspbian #linux #Coding #Tech #RaspberryPi