{"id":3477,"date":"2015-09-30T20:28:59","date_gmt":"2015-09-30T20:28:59","guid":{"rendered":"http:\/\/johnjohnston.info\/blog\/?p=3477"},"modified":"2020-07-03T13:21:25","modified_gmt":"2020-07-03T12:21:25","slug":"sky-pi-posting-to-tumblr-from-a-raspberry-pi","status":"publish","type":"post","link":"https:\/\/johnjohnston.info\/blog\/sky-pi-posting-to-tumblr-from-a-raspberry-pi\/","title":{"rendered":"Sky Pi: posting to tumblr from a Raspberry Pi"},"content":{"rendered":"<p><strong>Update\u00a029-09-2016:<\/strong> the pi is no longer posting gifs and images. I&#8217;ve recycled it\u00a0it. Also hat-tip to\u00a0<a href=\"https:\/\/twitter.com\/oliverquinlan\">Oliver\u00a0Quinlan<\/a>\u00a0for catching a mistake in the instructions, I&#8217;ve fixed it below (sudo pip <em>install<\/em> pytumblr). The <a href=\"http:\/\/raspskypi.tumblr.com\">archive of over 50,000 gifs<\/a> is still there.<\/p>\n<p>A couple of weeks ago I <a title=\"Gif Cam on Raspberry pi | John's World Wide Wall Display\" href=\"http:\/\/johnjohnston.info\/blog\/gif-cam-on-raspberry-pi\/\">blogged<\/a> about getting my Raspberry Pi to create gifs and server them to the web:<a href=\"http:\/\/pi.johnj.info\/gifcam.html\">Gif Cam<\/a>.<\/p>\n<p>This only keeps the most recent gif. A couple of days ago I tried to set it up to catch the blood moon, and store a series of gifs but my scripts failed to work. It did lead me to changing the position of the camera from the local cross roads to the sky.<\/p>\n<p>I then noticed a couple of interesting images, so though about how I could do that. There is not enough room on the pi&#8217;s SD card to hold images for very long. I started by uploading the gifs to a website via ftp. But this was still not a long term solution. I then though about Tumblr and after a bit of googling I&#8217;ve got a working solution that posts a gif of the Glasgow Skies to <a href=\"http:\/\/raspskypi.tumblr.com\/\">Sky Pi<\/a>.<\/p>\n<p>Here are some notes to show how I did some of it. You need to be able to use the termianl and a command line file editor such as nano. I am very much a newbie with this stuff.<\/p>\n<p>My pi is on my home network connected to the router via Ethernet and a powerline. It is set up as a webserver with a domain, <a title=\"john's pi server\" href=\"http:\/\/pi.johnj.info\">http:\/\/pi.johnj.info<\/a>. I have ssh access to the pi and do any editing from my mac via ssh. None of these things apart from the connection to the Internet.<\/p>\n<p>The pi is running from an SD card with <a href=\"https:\/\/www.raspberrypi.org\/downloads\/noobs\/\">NOOBS<\/a> installed.<\/p>\n<p>I&#8217;ve run: <code>sudo apt-get update<\/code><br \/>\nand<br \/>\n<code>sudo apt-get upgrade<\/code><br \/>\nbefore starting to get the pi up to date.<\/p>\n<p>Code like the above is run form the terminal, either on the pi with a monitor and keyboard or by logging on via ssh. I create scripts on the pi in the terminal with nano, which is an uncomplicated text editor that is used in the terminal.<\/p>\n<h3>Taking Pictures, making Gifs<\/h3>\n<p>The whole thing runs from a shell script, which started like this:<\/p>\n<pre><code>\n    #!\/usr\/bin\/env bash\n    for (( i = 0; i &lt; 10; i++ )); do\n        raspistill -h 486 -w 648 -a 1036 -vf -hf --encoding gif  -o \/var\/www\/tempgifs\/cam${i}.gif\n    done\n    gifsicle --delay=10 --colors 256  --loop \/var\/www\/tempgifs\/cam*  &gt; \/var\/www\/tempgifs\/camd.gif\n    mv \/var\/www\/tempgifs\/camd.gif \/var\/www\/camd.gif\n    raspistill -h 486 -w 648 -a 1036 -ae +25+25 -vf -hf -o \/var\/www\/camd.jpg\n<\/code><\/pre>\n<p>When the script runs, it takes 10 still pictures with the <em>raspistill<\/em> program. I am not too sure if these are the best settings, but<\/p>\n<ul>\n<li><em>-h 486<\/em> and <em>-w 648<\/em> set the dimensions.<\/li>\n<li><em>-a 1036<\/em> stamps the date and time.<\/li>\n<li><em>-vf -hf<\/em> flips the image and turns it upside down (to put it the right way up)<\/li>\n<li><em>&#8211;encoding gif<\/em> outputs as a gif<\/li>\n<li><em>-o \/var\/www\/tempgifs\/cam${i}.gif<\/em> set the file path for the export.<\/li>\n<\/ul>\n<p>I saved this file to regulargif.sh and then made it run-able with <code>chmod +x regulargif.sh<\/code>.<\/p>\n<p>I&#8217;ve installed gifsicle with <code>sudo apt-get install gifsicle<\/code> and use that to create the gif file. The last line creates a jpg too. You can see the current gif and jpg on <a href=\"http:\/\/pi.johnj.info\/gifcam.html\">Gif Cam<\/a>.<\/p>\n<p>I need the script to run regularly so I set up a cron job. To do this in the terminal type <code>crontab -w<\/code> and add<\/p>\n<p><code>*\/9 * * * * \/path\/to\/regulargif.sh<\/code><\/p>\n<p>to the bottom of the file. This will run the script every 9 minutes.<\/p>\n<h3>Tumbling Gifs<\/h3>\n<p>The next problem is to upload to tumblr. Tumblr has a well developed <a href=\"https:\/\/www.tumblr.com\/docs\/en\/api\/v2\">API<\/a> and libraries for several languages. After a fair bit of googling for a simple solution I decided to just use one of Tumblr&#8217;s own. I though it sensible to use Python as that language seems to have a lot of support on the pi. I don&#8217;t know any python.<\/p>\n<p>First you need to install the pytumblr python module. So in the terminal:<\/p>\n<p><code>sudo pip install pytumblr<\/code><\/p>\n<p>You also need to have various keys for the API: consumer_key, consumer_secret, oauth_token and oauth_secret. To get these you need to create an App on tumblr. Here is what I did. (Well this was a second run through to document, the first time got a bit messy;-))<\/p>\n<p><a href=\"https:\/\/www.tumblr.com\/oauth\/apps\">register an application<\/a> Click the button and fill in the fields.<br \/>\nThis will give you the consumer_key and consumer_secret.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"3483\" data-permalink=\"https:\/\/johnjohnston.info\/blog\/sky-pi-posting-to-tumblr-from-a-raspberry-pi\/key-and-secret\/\" data-orig-file=\"https:\/\/johnjohnston.info\/blog\/wp-content\/uploads\/2015\/09\/key-and-secret.png\" data-orig-size=\"609,99\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"key-and-secret\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/johnjohnston.info\/blog\/wp-content\/uploads\/2015\/09\/key-and-secret.png\" class=\"aligncenter size-full wp-image-3483\" src=\"https:\/\/johnjohnston.info\/blog\/wp-content\/uploads\/2015\/09\/key-and-secret.png\" alt=\"key-and-secret\" width=\"609\" height=\"99\" \/><\/p>\n<p>If you click the Explore API you will get a dialog to allow your new app to post for you (This did not work for me in Safari, I had to switch to Chrome and go through a couple of times).<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"3482\" data-permalink=\"https:\/\/johnjohnston.info\/blog\/sky-pi-posting-to-tumblr-from-a-raspberry-pi\/permit-app\/\" data-orig-file=\"https:\/\/johnjohnston.info\/blog\/wp-content\/uploads\/2015\/09\/permit-app.png\" data-orig-size=\"474,246\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"permit-app\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/johnjohnston.info\/blog\/wp-content\/uploads\/2015\/09\/permit-app.png\" class=\"aligncenter size-full wp-image-3482\" src=\"https:\/\/johnjohnston.info\/blog\/wp-content\/uploads\/2015\/09\/permit-app.png\" alt=\"permit-app\" width=\"474\" height=\"246\" \/><\/p>\n<p>This will lead to a place to fill in your key and secret. Then the console.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"3481\" data-permalink=\"https:\/\/johnjohnston.info\/blog\/sky-pi-posting-to-tumblr-from-a-raspberry-pi\/add-keys\/\" data-orig-file=\"https:\/\/johnjohnston.info\/blog\/wp-content\/uploads\/2015\/09\/add-keys.png\" data-orig-size=\"724,271\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"add-keys\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/johnjohnston.info\/blog\/wp-content\/uploads\/2015\/09\/add-keys.png\" class=\"aligncenter size-full wp-image-3481\" src=\"https:\/\/johnjohnston.info\/blog\/wp-content\/uploads\/2015\/09\/add-keys.png\" alt=\"add-keys\" width=\"724\" height=\"271\" srcset=\"https:\/\/johnjohnston.info\/blog\/wp-content\/uploads\/2015\/09\/add-keys.png 724w, https:\/\/johnjohnston.info\/blog\/wp-content\/uploads\/2015\/09\/add-keys-620x232.png 620w, https:\/\/johnjohnston.info\/blog\/wp-content\/uploads\/2015\/09\/add-keys-668x250.png 668w\" sizes=\"auto, (max-width: 724px) 100vw, 724px\" \/><\/p>\n<p>The Console will let you test various bits of code but more important will let you copy a block of code with the consumer_key, consumer_secret, oauth_token and oauth_secret.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"3480\" data-permalink=\"https:\/\/johnjohnston.info\/blog\/sky-pi-posting-to-tumblr-from-a-raspberry-pi\/all-info\/\" data-orig-file=\"https:\/\/johnjohnston.info\/blog\/wp-content\/uploads\/2015\/09\/all-info.png\" data-orig-size=\"485,236\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"all-info\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/johnjohnston.info\/blog\/wp-content\/uploads\/2015\/09\/all-info.png\" class=\"aligncenter size-full wp-image-3480\" src=\"https:\/\/johnjohnston.info\/blog\/wp-content\/uploads\/2015\/09\/all-info.png\" alt=\"all-info\" width=\"485\" height=\"236\" \/><\/p>\n<p>It is worth clicking on <strong>Example output<\/strong> on the console to make sure everything is working.<\/p>\n<p>Moving back onto the pi and the terminal I edited a new file with:<\/p>\n<p><code>nano pytumble.py<\/code><\/p>\n<p>And edit the file:<\/p>\n<pre><code>\nimport pytumblr\n\nclient = pytumblr.TumblrRestClient(\n 'consumer_key',\n  'consumer_secret',\n  'oauth_token',\n  'oauth_secret'\n)\n\n# Make the request\no=client.create_photo('raspskypi', state=\"published\", data=[\"\/var\/www\/camd.gif\"] )\n\nprint o\n<\/code><\/pre>\n<p>With the keys, tokens and secrets filled in. <strong>raspskypi<\/strong> is the name of the tumblr blog.<\/p>\n<p>Save the file and make it executable. (chmod +x ) pytumble.py.<\/p>\n<p>then type:<\/p>\n<p>python .\/pytumble.py<\/p>\n<p>After a minute, if all is set up right you should see an id for the post returned and checking the blog should show a post with the image from \/var\/www\/camd.gif<\/p>\n<p>If all is well you can add:<\/p>\n<p><code>python \/home\/pi\/pytumble.py<\/code><\/p>\n<p>To the bottom of the script that makes the gif.<\/p>\n<p>Now every time the script creates a new gif, it should post the image to your tumblr blog.<\/p>\n<p>Currently my pi has uploaded over 200 gifs: <a href=\"http:\/\/raspskypi.tumblr.com\/archive\">Sky Pi: Archive<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Update\u00a029-09-2016: the pi is no longer posting gifs and images. I&#8217;ve recycled it\u00a0it. Also hat-tip to\u00a0Oliver\u00a0Quinlan\u00a0for catching a mistake in the instructions, I&#8217;ve fixed it below (sudo pip install pytumblr). The archive of over 50,000 gifs is still there. A couple of weeks ago I blogged about getting my Raspberry Pi to create gifs and [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":3479,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"mf2_syndication":[],"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":true,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"webmentions_disabled_pings":false,"webmentions_disabled":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[6],"tags":[727,505],"post_format":[],"class_list":{"0":"post-3477","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-wwwd","8":"tag-raspberry-pi","9":"tag-raspberrypi","10":"kind-article","12":"h-entry","13":"hentry"},"better_featured_image":{"id":3479,"alt_text":"","caption":"","description":"","media_type":"image","media_details":{"width":648,"height":486,"file":"2015\/09\/camd.gif","sizes":{"thumbnail":{"file":"camd-150x150.gif","width":150,"height":150,"mime-type":"image\/gif","source_url":"https:\/\/johnjohnston.info\/blog\/wp-content\/uploads\/2015\/09\/camd-150x150.gif"},"medium":{"file":"camd-620x465.gif","width":620,"height":465,"mime-type":"image\/gif","source_url":"https:\/\/johnjohnston.info\/blog\/wp-content\/uploads\/2015\/09\/camd-620x465.gif"},"rpwe-thumbnail":{"file":"camd-45x45.gif","width":45,"height":45,"mime-type":"image\/gif","source_url":"https:\/\/johnjohnston.info\/blog\/wp-content\/uploads\/2015\/09\/camd-45x45.gif"},"jetpack-portfolio-admin-thumb":{"file":"camd-50x50.gif","width":50,"height":50,"mime-type":"image\/gif","source_url":"https:\/\/johnjohnston.info\/blog\/wp-content\/uploads\/2015\/09\/camd-50x50.gif"}},"image_meta":{"aperture":0,"credit":"","camera":"","caption":"","created_timestamp":0,"copyright":"","focal_length":0,"iso":0,"shutter_speed":0,"title":"","orientation":0}},"post":3477,"source_url":"https:\/\/johnjohnston.info\/blog\/wp-content\/uploads\/2015\/09\/camd.gif"},"jetpack_featured_media_url":"https:\/\/johnjohnston.info\/blog\/wp-content\/uploads\/2015\/09\/camd.gif","jetpack_shortlink":"https:\/\/wp.me\/p57zFQ-U5","jetpack_likes_enabled":false,"jetpack_sharing_enabled":true,"kind":false,"_links":{"self":[{"href":"https:\/\/johnjohnston.info\/blog\/wp-json\/wp\/v2\/posts\/3477","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/johnjohnston.info\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/johnjohnston.info\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/johnjohnston.info\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/johnjohnston.info\/blog\/wp-json\/wp\/v2\/comments?post=3477"}],"version-history":[{"count":6,"href":"https:\/\/johnjohnston.info\/blog\/wp-json\/wp\/v2\/posts\/3477\/revisions"}],"predecessor-version":[{"id":4283,"href":"https:\/\/johnjohnston.info\/blog\/wp-json\/wp\/v2\/posts\/3477\/revisions\/4283"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/johnjohnston.info\/blog\/wp-json\/wp\/v2\/media\/3479"}],"wp:attachment":[{"href":"https:\/\/johnjohnston.info\/blog\/wp-json\/wp\/v2\/media?parent=3477"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/johnjohnston.info\/blog\/wp-json\/wp\/v2\/categories?post=3477"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/johnjohnston.info\/blog\/wp-json\/wp\/v2\/tags?post=3477"},{"taxonomy":"post_format","embeddable":true,"href":"https:\/\/johnjohnston.info\/blog\/wp-json\/wp\/v2\/post_format?post=3477"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}