├── roadmap.md ├── legacy ├── .DS_Store ├── address.py ├── print.sh ├── downloader.py ├── discover.py ├── subtest.py └── init.sh ├── fetch.py ├── .gitignore ├── setup.py ├── README.md └── print.py /roadmap.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /legacy/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jonathanlking/Instagram-Printer-RP/HEAD/legacy/.DS_Store -------------------------------------------------------------------------------- /legacy/address.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | import subprocess 4 | 5 | 6 | cmd = subprocess.Popen('hciconfig hci0', shell=True, stdout=subprocess.PIPE) 7 | for line in cmd.stdout: 8 | if "BD Address" in line: 9 | data = line.split() 10 | for field in data: 11 | if len(field) == len('XX:XX:XX:XX:XX:XX'): 12 | print field 13 | 14 | 15 | -------------------------------------------------------------------------------- /fetch.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import sys 4 | import os 5 | import urllib 6 | import subprocess 7 | import bluetooth 8 | 9 | # Download the image url to print 10 | 11 | response = urllib.urlopen('http://instagram.jonathanlking.com/service?requestPrintURL'); 12 | photoURL = response.read(); 13 | if not photoURL: sys.exit() 14 | print photoURL; 15 | subprocess.call(['python', '/home/pi/Raspberry-Pi-Instagram-Printer/print.py', photoURL]) -------------------------------------------------------------------------------- /legacy/print.sh: -------------------------------------------------------------------------------- 1 | # 2 | # Instaprint Shell Script v1.0 3 | # 4 | 5 | # Takes two arguments, the instagram link of the photo and the address of the printer 6 | 7 | # Download the image from the server 8 | wget http://instagram.jonathanlking.com/engine/link?link=$1 -O print.jpg 9 | 10 | # Bind to the Pogo Printer 11 | sudo rfcomm bind /dev/rfcomm0 $2 1 12 | 13 | # Push the file to the printer 14 | ussp-push /dev/rfcomm0 print.jpg file.jpg 15 | 16 | -------------------------------------------------------------------------------- /legacy/downloader.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import urllib 4 | 5 | photoLink = 'http://instagram.com/p/anrQQ9vA8p/' 6 | 7 | paramaters = urllib.urlencode({'link': photoLink}) 8 | photo = urllib.urlopen("http://instagram.jonathanlking.com/engine/link?%s" % paramaters) 9 | 10 | try: 11 | with open('temporaryImage.jpg','w') as file: 12 | file.write(photo.read()) 13 | except IOError: 14 | print "Unable to write file" 15 | else: 16 | print "Image saved" -------------------------------------------------------------------------------- /legacy/discover.py: -------------------------------------------------------------------------------- 1 | import bluetooth 2 | 3 | nearbyDevices = bluetooth.discover_devices() 4 | 5 | for bluetoothDeviceAddress in nearbyDevices: 6 | deviceName = bluetooth.lookup_name(bluetoothDeviceAddress) 7 | print "found target bluetooth device with address ", bluetoothDeviceAddress 8 | print "and device name", deviceName 9 | if "Polaroid" in deviceName: 10 | print "It is a polaroid Printer!" 11 | with open('bt','w') as file: 12 | file.write('6000\n') -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.py[cod] 2 | 3 | # C extensions 4 | *.so 5 | 6 | .DS_Store 7 | 8 | # Packages 9 | *.egg 10 | *.egg-info 11 | dist 12 | build 13 | eggs 14 | parts 15 | bin 16 | var 17 | sdist 18 | develop-eggs 19 | .installed.cfg 20 | lib 21 | lib64 22 | 23 | # Installer logs 24 | pip-log.txt 25 | 26 | # Unit test / coverage reports 27 | .coverage 28 | .tox 29 | nosetests.xml 30 | 31 | # Translations 32 | *.mo 33 | 34 | # Mr Developer 35 | .mr.developer.cfg 36 | .project 37 | .pydevproject 38 | -------------------------------------------------------------------------------- /legacy/subtest.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import os 3 | import bluetooth 4 | import subprocess 5 | 6 | cmd = subprocess.Popen('ussp-push /dev/rfcomm0 temporaryImage.jpg file.jpg', shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) 7 | output = cmd.stdout.read() 8 | errors = cmd.stderr.read() 9 | 10 | print '\033[92m', 'Output:', output, '\n' 11 | print '\033[91m', 'Errors:', errors, '\n' 12 | 13 | #'sudo rfcomm bind /dev/rfcomm0 00:04:48:1B:87:7F' 14 | #'ussp-push /dev/rfcomm0 temporaryImage.jpg file.jpg' -------------------------------------------------------------------------------- /legacy/init.sh: -------------------------------------------------------------------------------- 1 | echo "\nThis will guide you in setting up your Raspberry Pi Instaprint" 2 | echo "First off we need to install bluez, as this allows us to communicate over bluetooth to the Polaroid Pogo" 3 | read null 4 | echo "Attempting install now: \n" 5 | sudo apt-get install bluetooth bluez bluez-utils ussp-push python-bluetooth 6 | echo "\n" 7 | echo "Now a quick check to make sure bluetooth is running \n" 8 | /etc/init.d/bluetooth status 9 | echo "\n" 10 | echo "Make sure that the Polaroid Pogo is turned on, as we will now search for it over bluetooth \n" 11 | read null 12 | hcitool scan 13 | echo "\n\n" 14 | echo "You should see a device entry with 'YY:YY:YY:YY:YY:YY Polaroid ZZ ZZ ZZ'" 15 | echo "Please enter the YY:YY:YY:YY:YY:YY part with the : included \n" 16 | read PolaroidPogoAddress 17 | echo "As the Pogo has a bluetooth pin of '6000' we need to add it to a settings file" 18 | echo "First we need to find the address of the bluetooth adaptor in the Pi - 'BD Address' \n\n" 19 | read null 20 | hciconfig hci0 -a 21 | echo "\n" 22 | echo "Please enter the address with the : included \n" 23 | read AdaptorAddress 24 | echo "Now creating file..." 25 | cd /var/lib/bluetooth/$AdaptorAddress 26 | echo "PolaroidPogoAddress 6000" > pincodes 27 | echo "File created! \n" 28 | echo "Please make a note of you Polaroid Pogo Address: $PolaroidPogoAddress" 29 | echo "Setup Complete!" -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import sys 4 | import os 5 | import bluetooth 6 | import subprocess 7 | 8 | print "Searching for devices..." 9 | 10 | # Scan for nearby bluetooth devices 11 | nearbyDevices = bluetooth.discover_devices() 12 | 13 | if len(nearbyDevices) == 0: 14 | print "No bluetooth devices detected, please turn on and run this script again" 15 | sys.exit() 16 | 17 | printerAddress = '' 18 | printerName = '' 19 | 20 | for bluetoothDeviceAddress in nearbyDevices: 21 | deviceName = bluetooth.lookup_name(bluetoothDeviceAddress) 22 | print "Found bluetooth device with address", bluetoothDeviceAddress, "called", deviceName 23 | if "Polaroid" in deviceName: 24 | printerAddress = bluetoothDeviceAddress 25 | printerName = deviceName 26 | 27 | if not len(printerAddress) == 0: 28 | print "Polaroid Pogo printer detected..." 29 | else: 30 | print "No printer detected, please turn on and run this script again" 31 | sys.exit() 32 | 33 | # Save the address of the Polaroid Pogo so that it can be easily accessed later when trying to print 34 | with open('settings.txt','w') as file: 35 | file.write(printerAddress + '\n') 36 | file.write('# Address for device: ' + printerName + '\n') 37 | 38 | # Get the mac address of the bluetooth adaptor 39 | hostDeviceAddress = '' 40 | 41 | cmd = subprocess.Popen('hciconfig hci0', shell=True, stdout=subprocess.PIPE) 42 | for line in cmd.stdout: 43 | if "BD Address" in line: 44 | data = line.split() 45 | for field in data: 46 | if len(field) == len('XX:XX:XX:XX:XX:XX'): 47 | hostDeviceAddress = field 48 | 49 | if len(hostDeviceAddress) == 0: 50 | print "Something went wrong trying to determine the address of you bluetooth adaptor, are you sure it is plugged in and working?" 51 | sys.exit() 52 | 53 | pathToBluetoothPincodeSettings = '/var/lib/bluetooth/' + hostDeviceAddress 54 | 55 | if not os.path.exists(pathToBluetoothPincodeSettings): 56 | os.makedirs(pathToBluetoothPincodeSettings) 57 | 58 | # Create the pincodes file, all Polaroid Pogo's have a pin of 6000 59 | settingsFilePath = pathToBluetoothPincodeSettings + '/pincodes' 60 | 61 | try: 62 | with open(settingsFilePath,'w') as file: 63 | file.write(printerAddress) 64 | file.write(' 6000\n') 65 | except IOError: 66 | print "Unable to write file, maybe you did not run as sudo?" 67 | else: 68 | print "Setup complete." 69 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Instagram-Printer-RP 2 | ============================== 3 | 4 | Create your own Instagram printer with a Raspberry Pi, Polaroid Pogo and web server. 5 | 6 | Notes 7 | ----- 8 | 9 | This code is designed for use with a Raspberry Pi and Polaroid Pogo and may, or may not work with a Polaroid GL10 and other hardware 10 | 11 | Installation & Setup 12 | -------------------- 13 | 14 | Install Git + clone the repository; 15 | 16 | sudo apt-get install git-core 17 | git clone git://github.com/jonathanlking/Raspberry-Pi-Instagram-Printer.git 18 | 19 | Optional: You can then get the Pi to automatically update to the latest version on startup by adding this code to "/etc/rc.local" 20 | 21 | git pull home/username/...locationOfParentDirectory.../Raspberry-Pi-Instagram-Printer 22 | 23 | Install the following packages; 24 | 25 | sudo apt-get install bluetooth bluez bluez-utils ussp-push python-bluetooth 26 | 27 | Make sure you have a bluetooth adaptor connected and the Polaroid Pogo is on 28 | 29 | Now run the setup.py script - You must run as sudo as it needs to create files in the root directory 30 | 31 | cd Raspberry-Pi-Instagram-Printer 32 | sudo python setup.py 33 | 34 | Printing 35 | -------- 36 | 37 | To print once setup use the following code; 38 | 39 | python print.py instagramLink 40 | 41 | For example `python print.py http://instagram.com/p/Y-6a52hOmG/` 42 | 43 | License 44 | ------- 45 | 46 | Raspberry Pi Instagram Printer 47 | Copyright (C) 2013 Jonathan King 48 | 49 | This program is free software: you can redistribute it and/or modify 50 | it under the terms of the GNU General Public License as published by 51 | the Free Software Foundation, either version 3 of the License, or 52 | (at your option) any later version. 53 | 54 | This program is distributed in the hope that it will be useful, 55 | but WITHOUT ANY WARRANTY; without even the implied warranty of 56 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 57 | GNU General Public License for more details. 58 | 59 | You should have received a copy of the GNU General Public License 60 | along with this program. If not, see . 61 | 62 | Special thanks to: 63 | ------------------ 64 | 65 | Breakfast NY - http://instaprint.me/ - The original amazing idea, which I wish got fully backed on Kickstarter 66 | Jon - http://opalfruits.net/blog/ - For providing a much better solution to bluetooth pairing with a Raspberry Pi than I had before. 67 | -------------------------------------------------------------------------------- /print.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import sys 4 | import os 5 | import urllib 6 | import subprocess 7 | import bluetooth 8 | 9 | TEMP_FILE_NAME = 'temporaryImage.jpg' 10 | 11 | def downloadPhotoFromLink(link): 12 | 13 | paramaters = urllib.urlencode({'link': link}) 14 | photo = urllib.urlopen("http://instagram.jonathanlking.com/link?%s" % paramaters) 15 | return photo 16 | 17 | def savePhotoWithName(photo, name): 18 | 19 | try: 20 | with open(name,'w') as file: 21 | file.write(photo.read()) 22 | except IOError: 23 | print "Unable to write file" 24 | sys.exit() 25 | else: 26 | print "Image saved locally" 27 | 28 | def readPrinterAddress(): 29 | 30 | try: 31 | with open('settings.txt','r') as settings: 32 | printerAddress = file.readline(settings).rstrip() 33 | return printerAddress 34 | except IOError: 35 | print "Unable to read printer address, do you have a settings.txt file?" 36 | sys.exit() 37 | 38 | 39 | def printerAvailable(printerAddress): 40 | 41 | # Scan for nearby bluetooth devices 42 | nearbyDevices = bluetooth.discover_devices() 43 | 44 | if printerAddress in str(nearbyDevices): 45 | return True 46 | else: 47 | return False 48 | 49 | def sendPhotoToPrintWithFilename(filename): 50 | 51 | sendPhoto = subprocess.Popen('ussp-push /dev/rfcomm0 temporaryImage.jpg file.jpg', shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) 52 | output = sendPhoto.stdout.read() 53 | errors = sendPhoto.stderr.read() 54 | 55 | if 'connection established' in output.lower() and 'error' not in errors.lower(): 56 | return True 57 | else: 58 | print 'There was an error:', '\033[91m', errors 59 | return False 60 | 61 | # Get the printer address from 'settings.txt' 62 | 63 | printerAddress = readPrinterAddress() 64 | 65 | # Get the image link 66 | 67 | imageLink = '' 68 | 69 | if len(sys.argv) > 1: 70 | imageLink = sys.argv[1] 71 | else: 72 | print 'No link provided' 73 | sys.exit() 74 | 75 | # Download the image to print from the link 76 | 77 | photo = downloadPhotoFromLink(imageLink) 78 | 79 | # Save the image to file 80 | 81 | savePhotoWithName(photo, TEMP_FILE_NAME) 82 | 83 | # Bind the printer to rfcomm0 84 | 85 | subprocess.check_output(['sudo', 'rfcomm', 'bind', '/dev/rfcomm0', printerAddress], stderr=subprocess.STDOUT) 86 | 87 | # Check that the printer is available 88 | 89 | if not printerAvailable(printerAddress): 90 | print "No printer" 91 | sys.exit() 92 | 93 | # Check that the image is real 94 | # - Don't need to worry about this, the printer already handles this 95 | 96 | # Send to photo to be printed 97 | 98 | if sendPhotoToPrintWithFilename(TEMP_FILE_NAME): 99 | print "Sent to printer" 100 | --------------------------------------------------------------------------------