Skip to content

Commit

Permalink
Send correct headers
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewn committed Jun 8, 2012
1 parent 2819452 commit 54cd2ff
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions printer.py
@@ -1,6 +1,6 @@
import serial
import time
import urllib
import urllib2

from optparse import OptionParser

Expand All @@ -11,6 +11,8 @@
RASPI_SERIAL = '/dev/ttyAMA0'
DEBUG_SERIAL = '/dev/master'

printerType = 'A2-raw'

printerDevice = DEBUG_SERIAL if options.debug else RASPI_SERIAL
printerId = None
printer = None
Expand Down Expand Up @@ -40,8 +42,12 @@ def getPrinterUrl():

def checkForDownload():
url = getPrinterUrl()
print "Check for download: " + url
response = urllib.urlopen(url)

req = urllib2.Request(url)
req.add_header('Accept', 'application/vnd.freerange.printer.' + printerType)

print "Checking for download: " + url
response = urllib2.urlopen(req)
status = str( response.getcode() )

print "Status: " + status
Expand All @@ -54,6 +60,7 @@ def checkForDownload():
time.sleep(5)

def sendToPrinter(f):
print "Printing."
bytes = f.read()
for b in bytes:
printer.write(b)
Expand Down

0 comments on commit 54cd2ff

Please sign in to comment.