Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import httplib
- import base64
- import StringIO
- class Trendnet():
- def __init__(self, ip='1.1.1.1', username='admin', password='admin'):
- self.IP = ip
- self.Username = username
- self.Password = password
- self.Connected = False
- def Connect(self):
- print 'Attempting to connect to camera...'
- try:
- h = httplib.HTTP(self.IP)
- h.putrequest('GET','/cgi/mjpg/mjpeg.cgi')
- h.putheader('Authorization', 'Basic %s' % base64.encodestring('%s:%s' % (username, password))[:-1])
- h.endheaders()
- errcode, errmsg, headers = h.getreply()
- self.file = h.getfile()
- self.Connected = True
- print 'Connected!'
- return True
- except:
- print 'Unable to Connect'
- self.Connected = False
- return False
- def Update(self):
- if self.Connected:
- s = self.File.readline() # '--myboundry'
- s = self.File.readline() # 'Content-Length: #####'
- framesize = int(s[16:])
- s = self.File.read(framesize) # jpeg data
- while s[0] != chr(0xff): # strip off some junk in front of the jpeg
- s = s[1:]
- return StringIO.StringIO(s)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement