{"id":5834,"date":"2017-12-19T11:29:02","date_gmt":"2017-12-19T19:29:02","guid":{"rendered":"https:\/\/www.bigtreestech.com\/wp2013\/?p=5834"},"modified":"2017-12-20T08:49:41","modified_gmt":"2017-12-20T16:49:41","slug":"real-time-clock-and-more","status":"publish","type":"post","link":"https:\/\/www.bigtreestech.com\/wp2013\/real-time-clock-and-more\/","title":{"rendered":"Real Time Clock and More"},"content":{"rendered":"<p>This morning I added a DS3231 Real Time Clock to the measurement system Raspberry Pi.\u00a0 I used <a href=\"https:\/\/www.raspberrypi.org\/forums\/viewtopic.php?f=63&amp;t=161133\">THIS<\/a> article to guide the way.\u00a0 One mistake that I made at the end of the process cost me a lot of time.\u00a0 I used the command\u00a0 hwclock -r rather than sudo hwclock -r and kept getting an error message that no clock could be found.\u00a0 After reading the error message more carefully I discovered that it was due to an access permission issue which adding sudo resolved.<\/p>\n<p>Next up, I went about installing pysftp on the weather system Raspberry Pi 3.\u00a0 This turned out to be a very involved, time consuming process.\u00a0 I tried to use sudo apt-get install pysftp and got an error.\u00a0 I tried pip install pysftp and got another error.\u00a0 I tried pip3 install pysftp and it worked but only installed a version of pysftp for python3.\u00a0 I tried pip2 install pysftp and got another error.<\/p>\n<p>Finally after googling forever, I found <a href=\"https:\/\/stackoverflow.com\/questions\/45367380\/python-sftp-command-arm-linux-gnueabihf-gcc-failed-with-exit-status-1\">THIS<\/a> article which suggested that the problem was due to missing packages in the operating system required to build the pysftp for python2.\u00a0 Based on that article I executed the command:<\/p>\n<pre class=\"lang-py prettyprint prettyprinted\"><code><span class=\"pln\">sudo apt<\/span><span class=\"pun\">-<\/span><span class=\"pln\">get install gcc libffi<\/span><span class=\"pun\">-<\/span><span class=\"pln\">dev libssl<\/span><span class=\"pun\">-<\/span><span class=\"pln\">dev python<\/span><span class=\"pun\">-<\/span><span class=\"pln\">dev<\/span><\/code><\/pre>\n<p>and then pip2 install pysftp and it worked!<\/p>\n<p>On to testing pysftp&#8230;\u00a0 First problem, discovered after over an hour of attempts&#8230; I needed to turn on SSH on the target machine (measurement system).\u00a0 Silly me.<\/p>\n<p>Once I enabled SSH on the target machine then this worked using interactive Python:<\/p>\n<p>&gt;&gt;&gt; import pysftp<br \/>\n&gt;&gt;&gt; cnopts = pysftp.CnOpts()<br \/>\n&gt;&gt;&gt; cnopts.hostkeys = None<br \/>\n&gt;&gt;&gt; sftp = pysftp.Connection(&#8216;192.168.1.000&#8242;,username=&#8217;username&#8217;,password=&#8217;password&#8217;, cnopts=cnopts)<br \/>\n&gt;&gt;&gt; sftp.execute(&#8216;ls&#8217;)<br \/>\n[&#8216;Desktop\\n&#8217;, &#8216;Documents\\n&#8217;, &#8216;Downloads\\n&#8217;, &#8216;Music\\n&#8217;, &#8216;Pictures\\n&#8217;, &#8216;Public\\n&#8217;, &#8216;python_games\\n&#8217;, &#8216;Templates\\n&#8217;, &#8216;Videos\\n&#8217;]<br \/>\n&gt;&gt;&gt;<\/p>\n<p>That last line is a python list of strings showing the directories on the in the remote machine&#8217;s home directory.\u00a0 Success!<\/p>\n<p>By the way, those are not my real IP address, username or passwords.<\/p>\n<p>Now, I just need to put an appropriately formatted python script on the remote machine and see if I can get it to execute from the weather machine \ud83d\ude42<\/p>\n<p>UPDATE 12\/19\/17, 3:22PM<\/p>\n<p>Starting to build the test scripts.\u00a0 Discovered that there were two fundamental things I needed to do with the test script on the measurement machine in order to execute a python script as if it were a shell command.<\/p>\n<p>I needed to include the path to the script in the $PATH environmental variable via:<\/p>\n<p>export PATH=$PATH:\/path\/to\/my\/script\/directory<\/p>\n<p>I also needed to change the permissions on the script to make it executable.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This morning I added a DS3231 Real Time Clock to the measurement system Raspberry Pi.\u00a0 I used THIS article to guide the way.\u00a0 One mistake that I made at the end of the process cost me a lot of time.\u00a0 &hellip; <a class=\"more-link\" href=\"https:\/\/www.bigtreestech.com\/wp2013\/real-time-clock-and-more\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"footnotes":""},"categories":[259],"tags":[],"class_list":["post-5834","post","type-post","status-publish","format-standard","hentry","category-snow-depth-project"],"_links":{"self":[{"href":"https:\/\/www.bigtreestech.com\/wp2013\/wp-json\/wp\/v2\/posts\/5834","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.bigtreestech.com\/wp2013\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bigtreestech.com\/wp2013\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bigtreestech.com\/wp2013\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bigtreestech.com\/wp2013\/wp-json\/wp\/v2\/comments?post=5834"}],"version-history":[{"count":4,"href":"https:\/\/www.bigtreestech.com\/wp2013\/wp-json\/wp\/v2\/posts\/5834\/revisions"}],"predecessor-version":[{"id":5838,"href":"https:\/\/www.bigtreestech.com\/wp2013\/wp-json\/wp\/v2\/posts\/5834\/revisions\/5838"}],"wp:attachment":[{"href":"https:\/\/www.bigtreestech.com\/wp2013\/wp-json\/wp\/v2\/media?parent=5834"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bigtreestech.com\/wp2013\/wp-json\/wp\/v2\/categories?post=5834"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bigtreestech.com\/wp2013\/wp-json\/wp\/v2\/tags?post=5834"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}