sodnpoo.com

n95 remote cam

I wanted to do some time lapse photography of the peppers and tomatoes I have on my windowsill so I could see how they're growing. I'd done this before using a webcam and a shell script. Although you could see the plants growing, due to the low resolution of the webcam you couldn't really see much more.

I started thinking about hacking an old digital camera with an arduino but while digging around for the best one found my old n95. The n95 has a 5 mega pixel camera on it which is better than the 3 mega pixel camera I've got. I also realised as I'd written code for it before (here (c++) and here (pys60)) that I could probably use the camera on it without having to make any modifications to the hardware.

The pys60 camera api makes taking the picture easy with the only sticking point being the need to first wake the screen up and then change the orientation to landscape otherwise we won't get the full 5 mega pixel image. All that was left was to code some method of retrieving the picture - I decided to use a TCP server over wifi, simply pushing the JPEG back to the client. I can then use netcat to pull the picture from anywhere I can connect to it from.

import appuifw, e32, SocketServer, camera, time

class MyTCPHandler(SocketServer.BaseRequestHandler):
    def handle(self):    
        e32.reset_inactivity() # wake screen up
        time.sleep(1)
        appuifw.app.orientation = 'landscape' #Switch to landscape mode
        time.sleep(1)
        img = camera.take_photo("JPEG_Exif",(2592, 1944),0)
        self.request.send(img)

if __name__ == "__main__":
    HOST, PORT = "0.0.0.0", 9999
    server = SocketServer.TCPServer((HOST, PORT), MyTCPHandler)
    server.serve_forever()