{"id":1958,"date":"2018-06-17T23:23:32","date_gmt":"2018-06-17T23:23:32","guid":{"rendered":"http:\/\/www.talkcrypto.org\/blog\/?p=1958"},"modified":"2018-06-17T23:35:40","modified_gmt":"2018-06-17T23:35:40","slug":"hello-world-hashgraph-raspberry-pi","status":"publish","type":"post","link":"https:\/\/www.talkcrypto.org\/blog\/2018\/06\/17\/hello-world-hashgraph-raspberry-pi\/","title":{"rendered":"Hello World Hashgraph Raspberry Pi"},"content":{"rendered":"<p>If you have a Raspberry Pi lying around and fancy seeing if you can get the Hashgraph sdk running on it, here is how.<\/p>\n<h3>Step 1: Check if Java is present and if it is 1.8+<\/h3>\n<p>If you are running Raspbian Stretch, it will have Java 8 already on it. Otherwise you&#8217;ll have to download it at\u00a0\u00a0<a href=\"http:\/\/www.oracle.com\/technetwork\/java\/javase\/downloads\/jdk8-downloads-2133151.html\" target=\"_blank\" rel=\"noopener\">Oracle<\/a><\/p>\n<p><img fetchpriority=\"high\" decoding=\"async\" class=\"alignnone wp-image-1963 size-full\" src=\"https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/06\/Screen-Shot-2018-06-18-at-10.54.55-AM.png\" alt=\"\" width=\"827\" height=\"456\" srcset=\"https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/06\/Screen-Shot-2018-06-18-at-10.54.55-AM.png 827w, https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/06\/Screen-Shot-2018-06-18-at-10.54.55-AM-300x165.png 300w, https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/06\/Screen-Shot-2018-06-18-at-10.54.55-AM-768x423.png 768w\" sizes=\"(max-width: 827px) 100vw, 827px\" \/><\/p>\n<p>The location of Java on the Pi is:\u00a0<span class=\"s1\">\/usr\/lib\/jvm\/jdk-8-oracle-arm32-vfp-hflt<\/span><\/p>\n<h3>Step 2: Get the sdk<\/h3>\n<p>Run:<br \/>\n<code>&gt; wget\u00a0https:\/\/www.swirlds.com\/downloads\/Swirlds%20SDK%20-%20version%2018.05.23.zip<\/code><br \/>\nIf you try running the sdk:<\/p>\n<p><code>&gt; jav -jar swirlds.jar<\/code><\/p>\n<p>and get this error:<\/p>\n<pre class=\"p1\"><span class=\"s1\">The JAVA_HOME environment variable is not defined correctly<\/span>\r\n<span class=\"s1\">This environment variable is needed to run this program<\/span>\r\n<span class=\"s1\">NB: JAVA_HOME should point to a JDK not a JRE\r\n<\/span><\/pre>\n<p>Make sure you have set JAVA_HOME correctly. To set it run:<\/p>\n<p><code>&gt; nano ~\/.profile<\/code><br \/>\nand add this line at the bottom of the file:<br \/>\n<code>export JAVA_HOME=\/usr\/lib\/jvm\/jdk-8-oracle-arm32-vfp-hflt<\/code><br \/>\nTake care of <em>arm32<\/em>\u00a0if you copied the command from another website.<\/p>\n<p>Test by running:<br \/>\n<code>&gt; echo $JAVA_HOME<br \/>\n&gt;\u00a0\/usr\/lib\/jvm\/jdk-8-oracle-arm32-vfp-hflt<\/code><\/p>\n<h3>Step 3: Download JCE<\/h3>\n<p>If you try and run it now, you&#8217;ll probably get this error:<\/p>\n<pre class=\"p1\"><span class=\"s1\">***************************************************************************<\/span>\r\n<span class=\"s1\">* ERROR: Please install the Oracle JCE Unlimited Jurisdiction Policy files.<\/span>\r\n<span class=\"s1\">* They can be downloaded as a single .zip file from:<\/span>\r\n<span class=\"s1\">* <span class=\"Apple-converted-space\">\u00a0 \u00a0 <\/span>http:\/\/www.oracle.com\/technetwork\/java\/javase\/downloads\/jce8-download-2133166.html<\/span>\r\n<span class=\"s1\">* If that address doesn't work, then click on the DOWNLOAD button <\/span>\r\n<span class=\"s1\">* next to the JCE Unlimited Strength link in the Additional Resources <\/span>\r\n<span class=\"s1\">* section of this page:<\/span>\r\n<span class=\"s1\">* <span class=\"Apple-converted-space\">\u00a0 \u00a0 <\/span>http:\/\/www.oracle.com\/technetwork\/java\/javase\/downloads<\/span>\r\n<span class=\"s1\">* Then unzip the downloaded .zip file, and move the two .jar files into:<\/span>\r\n<span class=\"s1\">*<span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 <\/span>\/home\/pi\/Downloads\/sdk\/usr\/lib\/jvm\/jdk-8-oracle-arm32-vfp-hflt\/jre\/lib\/security<\/span>\r\n<span class=\"s1\">* Please make sure they are legal in your country before installing.<\/span>\r\n<span class=\"s1\">***************************************************************************<\/span><\/pre>\n<p>Download\u00a0Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files 8 from <a href=\"http:\/\/www.oracle.com\/technetwork\/java\/javase\/downloads\/jce8-download-2133166.html\" target=\"_blank\" rel=\"noopener\">here<\/a>\u00a0and paste it to \/<span class=\"s1\">usr\/lib\/jvm\/jdk-8-oracle-arm32-vfp-hflt\/jre\/lib\/security<\/span>.<\/p>\n<p>Now it should work but you&#8217;ll get null pointer exception errors.<\/p>\n<p><img decoding=\"async\" class=\"alignnone wp-image-1964 size-large\" src=\"https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/06\/Screen-Shot-2018-06-18-at-12.46.08-AM-1024x292.png\" alt=\"\" width=\"940\" height=\"268\" srcset=\"https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/06\/Screen-Shot-2018-06-18-at-12.46.08-AM-1024x292.png 1024w, https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/06\/Screen-Shot-2018-06-18-at-12.46.08-AM-300x85.png 300w, https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/06\/Screen-Shot-2018-06-18-at-12.46.08-AM-768x219.png 768w, https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/06\/Screen-Shot-2018-06-18-at-12.46.08-AM.png 1172w\" sizes=\"(max-width: 940px) 100vw, 940px\" \/><\/p>\n<p>This is because the code is trying to execute\u00a0<em><span class=\"s1\">console<\/span><span class=\"s2\">.<\/span><span class=\"s1\">out<\/span><span class=\"s2\">.println(<\/span>&#8220;Hello Swirld from &#8220;<span class=\"s2\"> + <\/span><span class=\"s3\">myName<\/span><span class=\"s2\">);\u00a0<\/span><\/em><span class=\"s2\">at line 68 and it can&#8217;t because there is no console. Go into the source file and comment this out with \/\/. Do this for line 91 as well.\u00a0<\/span><\/p>\n<p>Now it should work but\u00a0you won&#8217;t see anything happening. If you run top, you should see Java consume 200% cpu but that is about it.\u00a0The problem is that you&#8217;ve ssh&#8217;d into your Pi and there is no output console. To see some output, try step 4.<\/p>\n<h3 class=\"p1\">Step 4: Getting funky<\/h3>\n<p>Go to sdk\/source\/HelloSwirldDemo\/src and modify\u00a0HelloSwirldDemoMain.java and add a system.out.println as shown below.<\/p>\n<p><code>#console.out.println(\"Hello Swirld from \" + myName);<br \/>\nSystem.out.println(\"Hello Swirld from \" + myName);<\/code><\/p>\n<h3 class=\"p1\">Step 5: Installing Maven<\/h3>\n<p>Check if you have maven with:<\/p>\n<p><code>pi@raspberrypi:~ $ mvn -v<br \/>\nApache Maven 3.5.3 (3383c37e1f9e9b3bc3df5050c29c8aff9f295297; 2018-02-24T19:49:05Z)<br \/>\nMaven home: \/opt\/apache-maven-3.5.3<br \/>\nJava version: 1.8.0_65, vendor: Oracle Corporation<br \/>\nJava home: \/usr\/lib\/jvm\/jdk-8-oracle-arm32-vfp-hflt\/jre<br \/>\nDefault locale: en_GB, platform encoding: UTF-8<br \/>\nOS name: \"linux\", version: \"4.9.59-v7+\", arch: \"arm\", family: \"unix\"<\/code><\/p>\n<p>If you don&#8217;t get the above then download Maven first:<br \/>\n<code>&gt; wget http:\/\/www-us.apache.org\/dist\/maven\/maven-3\/3.5.3\/binaries\/apache-maven-3.5.3-bin.tar.gz<\/code><br \/>\nExtract to \/opt:<\/p>\n<p><code>&gt; cd \/opt<br \/>\n&gt; sudo tar -xzvf \/path\/to\/apache-maven-3.5.3-bin.tar.gz<\/code><\/p>\n<p>Then you need to tell shell where to find maven. We\u2019ll do this in the system profile settings so it is available to all users.<\/p>\n<p><code>&gt; sudoedit \/etc\/profile.d\/maven.sh<\/code><\/p>\n<p>and enter<\/p>\n<p><code>export M2_HOME=\/opt\/apache-maven-3.2.5<br \/>\nexport PATH=$PATH:$M2_HOME\/bin<\/code><\/p>\n<p>Source:\u00a0https:\/\/xianic.net\/2015\/02\/21\/installing-maven-on-the-raspberry-pi\/<\/p>\n<h3>Step 6: Compiling with Maven<\/h3>\n<p>Go back to the HelloSwirldDemo folder where there is a pom.xml file. Run:<\/p>\n<p><code>mvn install<\/code><\/p>\n<p>It can take anywhere between 20 seconds to 7 minutes&#8230;.<\/p>\n<p><img decoding=\"async\" class=\"alignnone wp-image-1959 size-full\" src=\"https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/06\/Screen-Shot-2018-06-15-at-12.19.32-PM.png\" alt=\"\" width=\"617\" height=\"140\" srcset=\"https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/06\/Screen-Shot-2018-06-15-at-12.19.32-PM.png 617w, https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/06\/Screen-Shot-2018-06-15-at-12.19.32-PM-300x68.png 300w\" sizes=\"(max-width: 617px) 100vw, 617px\" \/><\/p>\n<p>Output<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1960 size-full\" src=\"https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/06\/Screen-Shot-2018-06-15-at-12.21.01-PM.png\" alt=\"\" width=\"652\" height=\"108\" srcset=\"https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/06\/Screen-Shot-2018-06-15-at-12.21.01-PM.png 652w, https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/06\/Screen-Shot-2018-06-15-at-12.21.01-PM-300x50.png 300w\" sizes=\"(max-width: 652px) 100vw, 652px\" \/><\/p>\n<p>Here is a quick video sped up 20x:<\/p>\n<p><iframe title=\"Hello World with Hashgraph on Raspberry Pi\" width=\"640\" height=\"360\" src=\"https:\/\/www.youtube.com\/embed\/ly-wm3-GJFI?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe><\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you have a Raspberry Pi lying around and fancy<\/p>\n","protected":false},"author":1,"featured_media":1967,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[33],"tags":[],"class_list":["post-1958","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dlt"],"featured_image_urls":{"full":["https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/06\/hashgraphpi.jpg",300,375,false],"thumbnail":["https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/06\/hashgraphpi-150x150.jpg",150,150,true],"medium":["https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/06\/hashgraphpi-240x300.jpg",240,300,true],"medium_large":["https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/06\/hashgraphpi.jpg",300,375,false],"large":["https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/06\/hashgraphpi.jpg",300,375,false],"1536x1536":["https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/06\/hashgraphpi.jpg",300,375,false],"2048x2048":["https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/06\/hashgraphpi.jpg",300,375,false],"chromenews-featured":["https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/06\/hashgraphpi.jpg",300,375,false],"chromenews-large":["https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/06\/hashgraphpi.jpg",300,375,false],"chromenews-medium":["https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/06\/hashgraphpi.jpg",300,375,false]},"author_info":{"info":["seandotau"]},"category_info":"<a href=\"https:\/\/www.talkcrypto.org\/blog\/category\/dlt\/\" rel=\"category tag\">DLT<\/a>","tag_info":"DLT","comment_count":"0","_links":{"self":[{"href":"https:\/\/www.talkcrypto.org\/blog\/wp-json\/wp\/v2\/posts\/1958","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.talkcrypto.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.talkcrypto.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.talkcrypto.org\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.talkcrypto.org\/blog\/wp-json\/wp\/v2\/comments?post=1958"}],"version-history":[{"count":9,"href":"https:\/\/www.talkcrypto.org\/blog\/wp-json\/wp\/v2\/posts\/1958\/revisions"}],"predecessor-version":[{"id":1975,"href":"https:\/\/www.talkcrypto.org\/blog\/wp-json\/wp\/v2\/posts\/1958\/revisions\/1975"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.talkcrypto.org\/blog\/wp-json\/wp\/v2\/media\/1967"}],"wp:attachment":[{"href":"https:\/\/www.talkcrypto.org\/blog\/wp-json\/wp\/v2\/media?parent=1958"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.talkcrypto.org\/blog\/wp-json\/wp\/v2\/categories?post=1958"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.talkcrypto.org\/blog\/wp-json\/wp\/v2\/tags?post=1958"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}