- It is possible to mull over these things for a few weeks when you are too busy to do anything serious, and then put in a few hours' work late on a Friday afternoon and come up with something working.
- iPads are fun, and there are some great apps to do serious engineering, but you can't hack those apps, and you can't do much to hack the iPad. You get to do what Apple, and Apple-approved developers, allow you to do. Which is a great deal, but it's not the sort of activity that engineers find really satisfying (and despite the fact that I'm an ex-geochemist with a master's degree in philosophy, I still consider myself a kind of engineer).
- On Friday afternoon, I needed the python-twitter library to check the twitter feed from Python. Downloading and installing it via apt-get from the Ubuntu repository took a few seconds. When I realised I needed a newer version to cope with changes in Twitter's API, it took a couple of minutes to find the newer version, download it and install it. If I had been using the locked-down campus version of Windows, it would not have been that trivial. Perhaps not even possible. Linux makes it much, much easier to do this sort of thing.
- I enjoyed myself more late on Friday afternoon than I had done for weeks doing more "important" things. It really fired my enthusiasm for using these things in next year's programmable electronics module (I have sixty kits sitting in a cupboard), and encouraging students to play around with them and see what they can do.
- I thought I had fried the GPIO port on my Raspberry Pi. A morning sitting in a room with disappointingly few visitors meant I had time to do some troubleshooting with a multimeter, and it turned out to be a broken connection on the ground rail of one of my breadboards, which was a relief. I love my multimeter.
- To some visitors, sending a tweet to turn on an LED was like magic. To some, it was deeply unimpressive. Only colleagues were able to grasp how much was really going on between pressing the send button on the iPad, and the red and green lights coming on.
Monday, July 1, 2013
Open Day, Part II
The main things I learned from the open day:
Labels:
arduino,
linux,
programming,
python,
twitter
Open Day, Part I
I was asked to demonstrate the use of an iPhone in Engineering at Saturday's alumni open day. I demonstrated AutoDesk ForceEffect Motion (which is pretty good fun) on the iPad rather than iPhone, but also demonstrated using the iPad to send tweets to the department's Twitter account (@le_engineering), which was more fun for me to do. I had a Python program running on my Linux netbook, which checked Twitter for mentions of @le_engineering, and then searched the rest of the text for the characters R, G, r, g, b and 1 or 0. These characters were sent via USB to an Arduino, which interpreted them as commands to light (uppercase) or turn off (lowercase) a red and green LED, sound a buzzer, or move a servo to 90 or 0 degrees.
Wednesday, June 12, 2013
Raspberry Pi
I haven't done much with the Raspberry Pi since I bought it, but having semi-volunteered to give some talks at a forthcoming open day, I thought I would use it as a web server to interface with an Arduino and some hardware. So I set it up again.
umount /dev/sdb1
dd if=2013-05-25-wheezy-raspbian.img of=/dev/sdb bs=4M
update-alternatives --config x-session-manager
A menu appears, and I was able to choose /usr/bin/startxfce4 as my session manager.
SD Card
I bought a new 16 gigabyte SD card for a tenner from the students' union shop. I think I paid about £130 for a 2 gigabyte hard disk back in the mid-nineties (I have a pile of them propping up a bookshelf in my office). Downloaded the raspbian image on to my Linux netbook, popped the SD card into the slot, and created the image (the card was automounted as /dev/sdb1, hence the first command):umount /dev/sdb1
dd if=2013-05-25-wheezy-raspbian.img of=/dev/sdb bs=4M
Network
The RPi was already registered for the campus network, so I haven't bothered with any of the static network address recipes - it picks up its address through DHCP.Additional software
I installed (using apt-get) the following packages:- apache2
- php5
- libapache2-mod-php5
- xfce4
- tightvnc
- arduino
VNC
I want to run the RPi headless most of the time, and don't want to have to muck about with monitor cables and spare keyboards when I do need to use the GUI. Initially, I took the RPi up to one of the labs where I could pinch a monitor with DVI input, and work in peace. These instructions worked to get VNC up and running. I used vinagre and remmina to test the setup - VNC is now starting reliably at boot time.Web server
I want the web server to use one of my subdirectories as root (documents in /home/pi/www/htdocs, CGI scripts in /home/pi/www/cgi-bin), so I edited /etc/apache2/sites-enabled/000-default to change the values of DocumentRoot, ScriptAlias, and the permissions on /home/pi/www/htdocs/.Desktop
I use xfce as my standard desktop (I like Gnome 4 on netbooks, have never got on with Unity). Selecting that as the default is simple (like most of the commands above, this has to be done using sudo to give yourself root privileges):update-alternatives --config x-session-manager
A menu appears, and I was able to choose /usr/bin/startxfce4 as my session manager.
Wednesday, April 17, 2013
Gmail
I've been using Python to email .MOBI files to the Kindle "Personal Documents" service, which adds them to your documents list on Amazon and allows them to be downloaded, synchronised between reading devices, etc. I've been sending via Gmail's SMTP server rather than the University server (because my Gmail account is authorised to send to Kindle, and my University account is not). That stopped working today, with the mail server reporting an incorrect password.
The answer: https://accounts.google.com/DisplayUnlockCaptcha
This doesn't actually display a Captcha, but it opens a ten minute window during which, if you use the application which is getting password rejections, the password will be accepted and the application added to a "whitelist".
The answer: https://accounts.google.com/DisplayUnlockCaptcha
This doesn't actually display a Captcha, but it opens a ten minute window during which, if you use the application which is getting password rejections, the password will be accepted and the application added to a "whitelist".
Thursday, September 27, 2012
CTRL-ALT-DEL
A couple of things arose today in connection with the university's new Windows 7 service. Our lab machines, for reasons I won't go into because I can only vaguely remember them, are set up as staff PCs rather than student PCs. This means you can do CTRL-ALT-DEL and lock the screen, which isn't what you want in a student lab (I remember this being a major cause of disputes in Charles Wilson labs during the Windows 3.1 days, when there was fierce competition for machines and students would lock the screen and then go off for an hour to a lecture). There's a simple fix: run gpedit.msc as an administrator, and enable User Configuration / Administrative Templates / System / Ctrl+Alt+Del Options / Remove Lock Computer. This also has the effect of disabling the "Lock" option in the Windows start button (it is still there, it just doesn't do anything).
I was accidentally switched to the new service a couple of days ago, and found that access to the Z drive from both my Linux PC, and the Windows 7 virtual machine I run on it, no longer work (the X drive still works, but that seems to still be on older file servers). Pending the resolution of that problem, a new PC fell off the back of a lorry and I am back to having two computers on my desk, one running Linux and one Windows 7 (which I think we are officially supposed to call "UOL" because there are no other things associated with the University of Leicester which might use the initials "UOL" and it will not be at all confusing). Linking them using synergy:
In the instructions below, EG-PC845 is the Linux box which will be running the server, and EG-PC1184 is the Windows machine.
As root, create /etc/synergy, and put this lot into /etc/synergy/synergy.conf:
Then put this lot into /etc/synergy/startsynergys, followed by chmod +x /etc/synergy/startsynergys to make the file executable:
And finally, append this to /etc/lightdm/lightdm.conf:
The synergy server will now start when the machine boots.
I was accidentally switched to the new service a couple of days ago, and found that access to the Z drive from both my Linux PC, and the Windows 7 virtual machine I run on it, no longer work (the X drive still works, but that seems to still be on older file servers). Pending the resolution of that problem, a new PC fell off the back of a lorry and I am back to having two computers on my desk, one running Linux and one Windows 7 (which I think we are officially supposed to call "UOL" because there are no other things associated with the University of Leicester which might use the initials "UOL" and it will not be at all confusing). Linking them using synergy:
Linux
From this page. I had to install a newer version of synergy (1.4, the current Ubuntu version is 1.3).In the instructions below, EG-PC845 is the Linux box which will be running the server, and EG-PC1184 is the Windows machine.
As root, create /etc/synergy, and put this lot into /etc/synergy/synergy.conf:
section: screens
EG-PC845:
EG-PC1184:
end
section: links
EG-PC845:
left = EG-PC1184
EG-PC1184:
right = EG-PC845
end
Then put this lot into /etc/synergy/startsynergys, followed by chmod +x /etc/synergy/startsynergys to make the file executable:
#!/bin/bash /usr/bin/synergys -c /etc/synergy/synergy.conf -n EG-PC845
And finally, append this to /etc/lightdm/lightdm.conf:
greeter-setup-script=/etc/synergy/startsynergys
The synergy server will now start when the machine boots.
Windows
Install synergy as normal, setting it up to start as a client when the machine does, and connect to the IP address of EG-PC845. The only remaining problem is to do CTRL-ALT-DEL to log on to Windows 7, because you are no longer using the keyboard attached to the PC. The solution is to use gpedit.msc again, as described here: enable Local Computer Policy / Computer Configuration / Administrative Templates / Windows Components / Windows Logon Options, with the option "Services and Ease of Access applications". CTRL-ALT-PAUSE then works in place of CTRL-ALT-DEL.Thursday, July 26, 2012
Looking ahead
As the previous post suggests, I've been thinking about Twitter bots today, and in particular how to post lengthy text in 140-character chunks. A diversion was to think about how to "read ahead" - I wanted to be able to say "if the next chunk of text will take me over the 140-character limit, don't read it in". But I can't do that without reading it in (I could of course read the whole file into an array, then use pop() and append() to treat it as a stack, but I want to avoid having to read in the whole file if possible). A solution is below:
#!/usr/bin/python
from tempfile import mkstemp
import shutil
import os
ifpath = "a.txt"
fh, ofpath = mkstemp()
ofile = open(ofpath, "w")
ifile = open(ifpath)
lines = []
length = 0
while True:
previous = ifile.tell()
line = ifile.readline()
if length + len(line) < 140:
lines.append(line)
length += len(line)
else:
ifile.seek(previous)
print lines
break
for line in ifile:
ofile.write(line)
ifile.close()
ofile.close()
os.remove(ifpath)
shutil.move(ofpath, ifpath)
This opens a.txt for reading (as ifile), and creates a temporary file (ofile). There's then an infinite loop - each time round, I store the current file location as previous, read in a new line, and check to see if that would take it over the limit. If not, I add the new line to the stored array. If it will go over the limit, I use ifile.seek() to go back to the file location before I read in the new line, and then print out the lines stored so far. All that remains is to write the unread lines (including the one I read in and decided not to use) to a temporary file, remove the original a.txt, and replace it with the temporary one.
Wednesday, July 25, 2012
Twitter Updating
Revised version of the code I originally wrote about here. The main difference is that I've included a counter so it doesn't post more than two tweets every time it is run (and since it only runs once an hour, this shouldn't make it too antisocial even when it hasn't run for a while and there are a lot of items in the RSS feed).
#!/usr/bin/python
import tweepy
import feedparser
import urllib
import urllib2
url = "http://www2.le.ac.uk/departments/engineering/news-and-events/blog/RSS"
oauth_file = open("access_token.txt", "r")
oauth_token = oauth_file.readline().rstrip()
oauth_token_secret = oauth_file.readline().rstrip()
consumer_file = open("consumer_keys.txt", "r")
consumer_key = consumer_file.readline().rstrip()
consumer_secret = consumer_file.readline().rstrip()
bitly_file = open("bitly.txt", "r")
bitly_username = bitly_file.readline().rstrip()
bitly_apikey = bitly_file.readline().rstrip()
bitly_base = "http://api.bit.ly/v3/shorten?"
bitly_data = {
"login" : bitly_username,
"apiKey" : bitly_apikey,
"format" : "txt",
"longUrl" : ""
}
already_done = []
done_file = open("done.txt", "r")
for line in done_file:
already_done.append(line.rstrip())
done_file.close()
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(oauth_token, oauth_token_secret)
api = tweepy.API(auth)
feed = feedparser.parse(url)
count = 0
for item in feed["items"]:
url = item["link"]
title = item["title"]
if url not in already_done and count < 2:
bitly_data["longUrl"] = url
to_shorten = bitly_base + urllib.urlencode(bitly_data)
result = urllib2.urlopen(to_shorten).read()
api.update_status(title + " : " + result)
already_done.append(url)
count = count + 1
done_file = open("done.txt", "w")
for url in already_done:
done_file.write(url + "\n")
done_file.close()
Subscribe to:
Posts (Atom)