Power management.

To extend the life of the internal batteries we can suspend the computer. Waking the machine is the trick though. BIOS doesn’t support power resume (but we could try the capacitor trick) but it does support Wake On LAN. Possibly configure the Arduino with an ethernet shield to do this at intervals.

http://www.debian-administration.org/articles/122

http://yutakalifenet.up.seesaa.net/html/wolRepeater.html

rossetti@waikato:~$ sudo aptitude install ethtool
rossetti@waikato:~$ sudo ethtool eth0
Settings for eth0:
Supports Wake-on: pg
Wake-on: d
Current message level: 0x00000000 (0)
Link detected: no
rossetti@waikato:~$ sudo ethtool -s eth0 wol g
rossetti@waikato:~$ sudo ethtool eth0
Settings for eth0:
Supports Wake-on: pg
Wake-on: g
rossetti@waikato:~$ /sbin/ifconfig eth0
eth0 Link encap:Ethernet HWaddr 00:24:8c:29:67:44

There are several pieces of software for sending the wakeonlan packets inside the Debian archive:

  • etherwake
    • Requires root privileges and available in all Debian distributions.
  • wakeonlan
    • Can be used by all users, but only in the Sarge (testing) and unstable (Sid) repositories

I’m going to use wakeonlan, since it’s already installed and can be used by non-root users:

skx@mystery:~$ wakeonlan  08:00:20:C2:1E:F6 
Sending magic packet to 255.255.255.255:9 with 08:00:20:C2:1E:F6

Updating a Twitter profile image using Python and cURL

I’ve been trying for ages to update the Twitter profile image from Python and getting lost in multipart boundary rubbish. It seems as though its a fairly ad-hoc part of the Twitter API that hasn’t ever been updated. PyTwitter doesn’t handle it currently which is being used for all the other Twitter updates being done.

Finally here is a working method using PycURL. Thanks to pieceofpy for solving the actual syntax for form file uploads.

def SetProfileImage(self, filename):
import pycurl
url = 'https://twitter.com/account/update_profile_image.xml'
head = ['Expect: ']
data = [('image', (pycurl.FORM_FILE, filename))]
c = pycurl.Curl()
c.setopt(pycurl.URL, url)
c.setopt(pycurl.USERPWD, "%s:%s" % (self.user, self.passwd))
c.setopt(pycurl.HTTPHEADER, head)
c.setopt(pycurl.HTTPPOST, data)
c.perform()
c.close()

This is the equivalent of the curl command

curl -u anxiousdoor:xxxxxxxx --header "Expect: " -F image="@/home/rossetti/door/icon-unlocked.png" https://twitter.com/account/update_profile_image.xml

Arduino + motor controller.

A better way to do this is using an h-bridge IC. But can I buy one in Sydney? Only Altronics and Farnell stock them.

http://itp.nyu.edu/physcomp/Labs/DCMotorControl

http://lab.guilhermemartins.net/?p=66

http://www.toddholoubek.com/classes/pcomp/?page_id=394

There is an official Arduino motor controller shield. 

And the all done solution from Lady Ada – an Arduino shield kitset (with eagle files if you want to DIY) that controls dc motors, steppers and servos for good measure.

Lady Ada – 19.50USD + 9.65/33.50PP
http://www.ladyada.net/

Fun Gizmos (v3) – shield & components 25USD + 13.85/28.85/72.52PP
http://store.fungizmos.com/

Little Bird (v3) – shield only 18AUD +7.80PP (+GST I don’t like it when they neglect to mention that until checkout)
http://www.littlebirdelectronics.com/

NKC (v1) – shield only/shield & components 4.99/10.99USD (incl. shipping comes to 17-25USD)
http://www.nkcelectronics.com/

Schematics for Motor Shield v3
http://forums.fungizmos.com/

Local store w/ Arduino & motor controllers
http://www.oceancontrols.com.au/

Parts from Farnell ~36AUD

Parts list from Fun Gizmo (v3)

  • 1 Official Arduino bare motor shield PCB V3.0
  • 2 100uF electrolytic capacitor 25Vdc
  • 4 100nF capacitor polyester
  • 1 74HC32N DIL14 Quad 2-input OR gate
  • 1 SN754410 (L293D) DIL16 (motor controller)
  • 1 74HC00N DIL14 Quad 2-input NAND gate
  • 2 3mm RED LED
  • 1 3mm GREEN LED
  • 6 100K 1/4W resistor
  • 2 2.2K Resistor 1/4W
  • 2 470 Ohm Resistor 1/4W
  • 1 1×40 .1″ mail header
  • 2 Pushbutton 6×6 
  • Eco-anxiety

    10 articles from the last month containing the phrase `climate change’ with the highest `fear’ rating.

    rossetti@Wakatipu:~/door$ sqlite3 door_wordlist.db "SELECT ratings_1.q3, articles.title FROM articles LEFT JOIN ratings_1 ON articles.id = ratings_1.id where articles.date_utc > date(2008-5-7) AND articles.content LIKE '%climate change%' ORDER BY ratings_1.q3 DESC LIMIT 10;"

    0.685783020643|Blogwatch: the La Nina situation
    0.488184223473|White House thaws over polar bear
    0.47334045077|Your Views:  What MPs drive
    0.467275269602|More than a billion trees planted this year: UN
    0.459957990744|Water plan speech not criticism, says Treasury boss
    0.455275970518|Millions of 'climate change migrants' will overwhelm Europe, says report
    0.453333437261|Norway to show US global warming affect on Arctic islands
    0.45237335196|'Out of ideas' - PM fails to catch Labor
    0.445142297835|NZ forests falling
    0.443097177169|River report points to dam trouble

    And results for the word `weather’

    0.546797083867|Climate change set to erode house values
    0.483457646351|Photos:  First snow brings chaos to London, across Europe
    0.476200389826|Wild weather chaos in New South Wales
    0.469760177924|Flood emergency eases in Hunter Valley
    0.433045967141|Premier confident of power availability
    0.424738123771|Black ice in south, gale warning for north
    0.423129126153|Two dead in European mudslides, floods: reports
    0.4219486054|Pasha report blames poor seamanship
    0.414978076786|Bad weather: more ships issue distress calls
    0.413745027142|Rare Snowstorm

    SELECT anxiety;

    rossetti@Wakatipu:~/door$ sqlite3 -column door_wordlist.db 'SELECT ratings_1.q3, articles.date, articles.title FROM articles LEFT JOIN ratings_1 ON articles.id = ratings_1.id ORDER BY ratings_1.q3 DESC LIMIT 10;'

    0.800 2007-04-24 Henry Porter: Islam must condemn the chlorine bombers
    0.798 2007-07-09 Australian police could get more time to hold terror s
    0.780 2007-07-24 NZ climber dies in French Alps
    0.779 2007-05-10 Russian writer finds being rebellious can be dangerous
    0.735 2007-11-14 MacCormack: Nats stick to the script, shameless pork h
    0.725 2007-05-28 Dead teenagers named
    0.691 2007-08-14 Bomb Derails Train in Russia
    0.688 2007-11-08 Finland mourns teen’s ‘revolution’ massacre
    0.682 2007-02-03 Hundreds protest against new desalination plants in Sy
    0.673 2007-10-10 Wines vie for awards

    Anxious sentiment in the last 24hrs.

    foo=`sqlite3 door_wordlist.db "SELECT ratings_1.q3 FROM articles LEFT JOIN ratings_1 ON articles.id = ratings_1.id where articles.date_utc > date('2007-11-11 03:30:00') ORDER BY articles.date;"`; python _test-sparkline.py $foo > r7.gifanxious in the last 24hr

    and 10 days of aggregated sentiment
    foo=`sqlite3 door_wordlist.db 'select r1q3 from scores order by date desc limit 240;'`; python _test-sparkline.py $foo > agg13.gifsparkline

    Spark line test.

    Fearful spark from the last week. Simple sparklines.

    sqlite> SELECT ratings_1.q3 FROM articles LEFT JOIN ratings_1 ON articles.id = ratings_1.id WHERE date(articles.date) > "2007-10-21" ORDER BY articles.date;

    [spark] [type line] [size 30,330] [series 0.144403792499,0.0738422091162,0.204887587994,0.0,0.0,0.257322806016,0.170458339935,0.186673693907,0.103929163868,0.113549465655,0.222691506218,0.190330239872,0.0,0.169294870468,0.0881183138969,0.170869077271,0.219570823594,0.0629105073619,0.0,0.187879411561,0.154360207598,0.0955314706589,0.118257977181,0.0269139996558,0.22956545669,0.242917155542,0.184570256009,0.0,0.166541138141,0.204739216492,0.395745509549,0.272438688431,0.300362929308,0.171071168897,0.168410757751,0.197797123779,0.206781926938,0.0,0.204114691277,0.458221956257,0.306912528889,0.156173343527,0.179199213931,0.128763036576,0.188048344797,0.263415832583,0.0667314353696,0.0928106708179,0.0489320370692,0.28285154363,0.102676967004,0.205410857796,0.180058510657,0.0,0.302150946612,0.200117673982,0.205120331381,0.0903359797936,0.0,0.0,0.0407977380077,0.343606310847,0.245301066909,0.0685350862472,0.197186872409,0.0,0.108442533404,0.222020599414,0.163188714723,0.211963827224,0.0,0.203691354004,0.20492592301,0.0,0.0,0.0751663103793,0.201152891167,0.0,0.115092050817,0.132877350819,0.20462455334,0.0,0.249949356504,0.191826745571,0.371606310847,0.200400427149,0.0435705335247,0.154841241486,0.231762577446,0.181983698832,0.11557728227,0.182564572313,0.106533709448,0.21189290552,0.34263669809,0.216213577576,0.352227549616,0.288323719879,0.284514807808,0.194713933813,0.0405019674178,0.325460826646,0.221896493737,0.191199857295,0.218096885842,0.185490853464,0.263556089428,0.0,0.267499360342,0.20033162965,0.221394595371,0.120537915134,0.187392106198,0.232570076397,0.299523228975,0.0628330680692,0.0867815157469,0.0,0.353321728998,0.250918751953,0.231747498782,0.338297663081,0.118941138141,0.157017883254,0.18608078757,0.20205730704,0.111995034835,0.230058028785,0.0,0.208501063974,0.251435203527,0.281913617197,0.341707888559,0.337264184755,0.0,0.0862635081424,0.158564599959,0.218699545774,0.277658374705,0.21823719041,0.0738239713951,0.174927722476,0.12694195838,0.0,0.0,0.222375084737,0.194365479852,0.225386522303,0.217465810455,0.205099545774,0.302687613369,0.0424289528377,0.331825025118,0.116068810202,0.211098203545,0.0,0.210390084556,0.472840252389,0.181962918787,0.24107188739,0.250008279537,0.535895343884,0.0,0.0,0.0636864753507,0.208855016275,0.192705183095,0.357856294526,0.308615997979,0.0,0.336940107289,0.406977270392,0.271181135937,0.0,0.237618105788,0.181561563461,0.49806841757,0.424735770734,0.285979740021,0.0417627417663,0.0,0.32777858925,0.200781481218,0.0,0.211982118829,0.0,0.0632048333594,0.177920720934,0.443702185723,0.0,0.117188357238,0.160588111842,0.0462361902277,0.207105926186,0.249367818181,0.201683007792,0.200811066894,0.0414516009273,0.307566796638,0.0,0.183638815662,0.424071870935,0.216353995754,0.051064495111,0.1724479168,0.206680761243,0.247149406973,0.191324576819,0.114541138141,0.23423497128,0.251761771001,0.222247048798,0.221091506218,0.299991807628,0.176782986976,0.196657047389,0.376979940325,0.217360341508,0.279394381713,0.202435772029,0.474450413016,0.0,0.204511512726,0.193654468484,0.215752959267,0.194278377085,0.0888815771572,0.1559476333,0.20183315059,0.392370416352,0.0608409842369,0.182307704863,0.0329599027012,0.0,0.214114130146,0.215096080957,0.168403829196,0.283489770201,0.207045788109,0.301012015935,0.32795851523,0.237511589244,0.205240454253,0.193643199734,0.156967047706,0.185087096817,0.216484921118,0.312799810605,0.168591122788,0.198567164056,0.215549033362,0.150963355476,0.185751339661,0.0,0.195498410118,0.0312706857907,0.187555820087,0.185474894518,0.0,0.0,0.3740636416,0.194347431728,0.193435033196,0.0645271103961,0.20063315059,0.289826245232,0.207268444311,0.078007186525,0.295005050968,0.0,0.107187809607,0.0331265075438,0.195473369476,0.172245422966,0.245070243113,0.0,0.203156855076,0.201949913623,0.217881466369,0.338552043072,0.407901863475,0.210908152562,0.110941138141,0.0772859202065,0.1975476333,0.188466661189,0.282346917148,0.0416259425731,0.210762929308,0.336431847616,0.291833525923,0.117375189626,0.0,0.0,0.0,0.296813098853,0.246786153582,0.0,0.0588706857907,0.211198367215,0.30424185602,0.0,0.145807180706,0.336697663081,0.229914741242,0.176913786532,0.0461943389957,0.0,0.0,0.355080026745,0.182101700019,0.0,0.331484385893,0.0980488087154,0.293961805403,0.19527677214,0.160459011477,0.218960214723,0.163399479521,0.0,0.252685045914,0.214732803369,0.319345722737,0.16399565138,0.0,0.20089827829,0.083727209182,0.188773634208,0.155460945343,0.176683891179][dot 7,50,5,green][/spark]

    SELECT fearful;

    sqlite> SELECT ratings_1.q3,articles.title FROM articles LEFT JOIN ratings_1 ON articles.id = ratings_1.id ORDER BY ratings_1.q3 DESC LIMIT 10;

    0.622115874383|Spanish PM talks tough on terrorism after latest ETA blast
    0.532897708158|Britain backs US sanctions against Iran
    0.45492276759|World's most influential wine critic accused of becoming too 'cosy' with the growers
    0.394539399442|Cuba and Castro pay tribute to 'El Che, the flower cut early from its stem'
    0.371606310847|Citizen Crikey: Missives from the marginals
    0.360371702545|New EU treaty 'same as Constitution' say MPs
    0.359015961078|1915 Armenian massacre WAS a genocide, insists US foreign affairs committee
    0.358686637582|PETER HITCHENS: North Korea, the last great Marxist bastion, is a real-life Truman show
    0.353321728998|World Briefing | Asia: The Philippines: Arroyo Pardons Predecessor and Draws Fire
    0.349470571259|Terror as 14-year-old shoots five at his school in Cleveland