spark local-cloud-on-raspberry-pi
TRANSCRIPT
1. Introduction2. PreparingSDcard
i. Downloadbaseimageii. BurntoSDcardiii. Updatekernel.img&start.elf
3. PoweringupRpii. CheckIPAddressofRpiii. LoginviaSSHiii. Changepassword&assignStaticIP
4. UpdatePackages5. InstallNode.js6. InstallGit7. InstallLocalCloudRepo8. FireupLocalCloud!9. Setupinit.dscript10. MiscInstructions
TableofContents
Outline
ThisTutorialdocumentstheprocessfromthebeginningofhowtosetupaRaspberryPiwithRasbianimageandeventuallyrunaLocalSparkCloud.
TheAPIserver+COAPprotocoliswrittenonnode.jsandthereposareavailableat:
1. https://github.com/spark/spark-server2. https://github.com/spark/spark-protocol
Futurechapterstobeadded
1. InstallLocalCloudinDocker2. DynamicDNSsystem3. Bootonstartup
Youcanviewthetutorialonlineat:http://kennethlimcp.gitbooks.io/spark-local-cloud-on-raspberry-pi
Writtenby:kennethlimcp
Licensedunder:Attribution-ShareAlike4.0International(CCBY-SA4.0)
Goto:http://www.raspberrypi.org/downloads/
DownloadtheRASPBIANimage
Licensedunder:Attribution-ShareAlike4.0International(CCBY-SA4.0)
Downloadbaseimage
TheRaspberryPiwebsitehasgreatdocumentationtosetuptheSDcardproperly.
1. Linux2. MacOSx3. Windows
Tipsformac:
Tospeedupthecopying,weshouldusetherawdiskdriveinstead.Somehavegotten10ximprovedperformancebydoingthefollowing:
*addingrto/dev/disknumbertobecome/dev/rdisknumberwhichwilluseitasarawdisk
Thefullcommandwilllooklike:
New:
sudoddbs=1mif=path_of_your_image.imgof=/dev/rdisknumber
Old:
sudoddbs=1mif=path_of_your_image.imgof=/dev/disknumber
Itwasindeedfaster(theprevioustookforever)
2825+0recordsin
2825+0recordsout
2962227200bytestransferredin257.177468secs(11518222bytes/sec)
Licensedunder:Attribution-ShareAlike4.0International(CCBY-SA4.0)
BurntoSDcard
The.imgfilefromtheraspbianimagedoesnotcontainthelatestfilesandupgradingthisfilesbeforepoweringupwillsaveussomeupdatingtimelater.
1.)DownloadthelatestRpifirmwarefrom:https://github.com/raspberrypi/firmware/blob/master/boot/start.elf
2.)DownloadthelatestRpikernelfrom:https://github.com/raspberrypi/firmware/tree/master/boot/kernel.img
OverwritethefilesontheSDandejectthecard!
Licensedunder:Attribution-ShareAlike4.0International(CCBY-SA4.0)
Updatekernel.img&start.elf
NowthattheSDcardhasbeenprepared,plugitintotheRaspberryPiandpowerupwithagoodpowersupply.
Don'tforgettheEthernetcable.
YoushouldnoticesomeLEDactivityontheTxandRx.
Licensedunder:Attribution-ShareAlike4.0International(CCBY-SA4.0)
PoweringupRpi
1. Logintoyourrouterconsoleandlookatthelistofdevices
2. Sometimes,theraspberrypidoesnotpresentahostnameandbecomesachallengetoidentifytheIP!
3. Fortunately,weknowthattheRpiMACaddprefixis:B8:27:EB
OnceyouhaveretrievedtheIPAddress,wearegoodtogo!
Licensedunder:Attribution-ShareAlike4.0International(CCBY-SA4.0)
CheckIPAddressofRpi
LaunchyourfavouriteTerminalprogram(eg.Putty)andloginwiththefollowingdetails:
IPAddress:fromyourrouterPort(SSH):22username:pipassword:raspberry
Licensedunder:Attribution-ShareAlike4.0International(CCBY-SA4.0)
LoginviaSSH
1.)Enterthecommand:passwd
Youshouldsee:
Changingpasswordforpi.
(current)UNIXpassword:
EnternewUNIXpassword:
RetypenewUNIXpassword:
passwd:passwordupdatedsuccessfully
2.)Nextup,wewillmodifyassignastaticIPaddress.
Enterthecommand:ifconfig
Wewillneedtonotedownthefollowing:
INSERTScreenshot
inetaddr–192.168.1.100(currentIPAddress)Bcast–192.168.1.255(broadcastIPRange)Mask–255.255.255.0(subnetMaskAddress)
3.)Now,wewillgrabtheGatewayinfowithnetstat-nr
Writedown:
GatewayAddressDestinationAddress
Great!Wecannowmodifythesettingswith:
sudonano/etc/network/interfaces
Changethefollowingline:
ifaceeth0inetdhcptoifaceeth0inetstatic
Themappingsareassuch:
`address`-->the_ip_you_prefer
`netmask`-->Mask
`network`-->Destination
broadcast-->Bcast
gateway---->Gateway
Whatyouwillseeafteraddingislike:
autolo
ifaceloinetloopback
ifaceeth0inetstatic
Changepassword&assignstaticIP
address192.168.1.200
netmask255.255.255.0
network192.168.1.0
broadcast192.168.1.255
gateway192.168.1.1
allow-hotplugwlan0
ifacewlan0inetmanual
wpa-roam/etc/wpa_supplicant/wpa_supplicant.conf
ifacedefaultinetdhcp
Double-checktheparametersandsave!(CTRL+X)
Tomakesurethingsareworkingok,let'srestartthemachinewithsudoreboot
IfyoumanagedtoconnecttotheRpiwiththenewIPaddress,congratulations!
Let'smakesurethingsareindeedloadingcorrectly:
ifconfig
Tobesuper-surethingsareok,wewillperformapingtothegateway!
pinggateway_ip_add-c4
Licensedunder:Attribution-ShareAlike4.0International(CCBY-SA4.0)
1.)Runsudoapt-getupdatetoensurewehaveallthelatestpackages
pi@raspberrypi~$sudoapt-getupdate
Get:1http://raspberrypi.collabora.comwheezyRelease.gpg[836B]
Hithttp://repository.wolfram.comstableRelease.gpg
Get:2http://archive.raspberrypi.orgwheezyRelease.gpg[490B]
Hithttp://repository.wolfram.comstableRelease
2.)Nextwillbeupgradingwithsudoapt-getupgrade
pi@raspberrypi~$sudoapt-getupgrade
Readingpackagelists...Done
Buildingdependencytree
Readingstateinformation...Done
Thefollowingpackageswillbeupgraded:
dbusdbus-x11gnupggpgvlibdbus-1-3libsmbclientlibwbclient0libxml2
rpi-updatesamba-commonsmbclient
11upgraded,0newlyinstalled,0toremoveand0notupgraded.
Needtoget9673kBofarchives.
Afterthisoperation,42.0kBofadditionaldiskspacewillbeused.
Doyouwanttocontinue[Y/n]?y
Licensedunder:Attribution-ShareAlike4.0International(CCBY-SA4.0)
UpdatePackages
Originalreferencefrom:https://learn.adafruit.com/raspberry-pi-hosting-node-red/setting-up-node-dot-js
1.)DownloadthepackagemadecompatibleforPiwith:
sudowgethttp://node-arm.herokuapp.com/node_latest_armhf.deb
2.)Installthedebianpackage:
sudodpkg-inode_latest_armhf.deb
3.)Checkthenode.jsversionforasuccessinstall!
pi@raspberrypi~$node-v
v0.10.29
4.)thepackagemanagerforNode.jswillalsoberequired.
So:`sudoapt-getinstallnpm
pi@raspberrypi~$sudoapt-getinstallnpm
Readingpackagelists...Done
Buildingdependencytree
Readingstateinformation...Done
Licensedunder:Attribution-ShareAlike4.0International(CCBY-SA4.0)
InstallNode.js&npm
1.)Runsudoapt-getinstallgit
Itshouldinstallfairlyquickly.
pi@raspberrypi~$sudoapt-getinstallgit
Readingpackagelists...Done
Buildingdependencytree
Readingstateinformation...Done
gitisalreadythenewestversion.
gitsettomanuallyinstalled.
0upgraded,0newlyinstalled,0toremoveand0notupgraded.
Next,checktheversionofgitjusttobesure.
pi@raspberrypi~$git--version
gitversion1.7.10.4
pi@raspberrypi~$
Licensedunder:Attribution-ShareAlike4.0International(CCBY-SA4.0)
InstallGit
Withthebasicsetupready,wearenowreadytoinstallSpark-server!
1.)runcdjusttobesureweareinthebasedirectory.Otherwise,youcanchoosewhereyouwanttogitclonetherepo.
2.)Downloadthespark-serverrepo:
gitclonehttps://github.com/spark/spark-server.git
pi@raspberrypi~$gitclonehttps://github.com/spark/spark-server.git
Cloninginto'spark-server'...
remote:Reusingexistingpack:272,done.
remote:Total272(delta0),reused0(delta0)
Receivingobjects:100%(272/272),61.07KiB|80KiB/s,done.
Resolvingdeltas:100%(155/155),done.
3.)gotothespark-serverfolder
cdspark-server
4)Installthemodule!
`npminstall--verbose`
Youusuallywon'tneed--verbosebutthingsarealittleslowontheRpianditwouldbenicetoseewhat'sgoingon.
ALERT:
TheURSAnodemoduleisnotinstallingcorrectlywiththeinstall.jsscriptfromspark-server.
Iamnotsurewhybutitmanagedtobuildfromsourcewhenitriedtofindouttheissue.
Sowehavetomanuallybuilditinsteadby:
cdnode_modules
gitclonehttps://github.com/Medium/ursa.git
cdursa
npminstall-verbose
Anotherissuecameupwiththeexpressmoduleso...
cd
cdspark-server
npminstallexpress-verbose`
InstallLocalCloudRepo
WOOHOO!WenowhaveashinynewserverwhichtalksCOAPprotocolandresponsestoAPIcalls!!
Commandssummarylist:
[email protected]:spark/spark-server.git
cdspark-server
npminstall
nodemain.js
Licensedunder:Attribution-ShareAlike4.0International(CCBY-SA4.0)
1.)fireuptheserver,baby!
nodemain.jsinthespark-serverfolder
ThiswillhavesomelagforthefirsttimewhentheRpicreatesanewkey.
pi@raspberrypi~/spark-server$nodemain.js
-------
Nousersexist,youshouldcreatesomeusers!
-------
connect.multipart()willberemovedinconnect3.0
visithttps://github.com/senchalabs/connect/wiki/Connect-3.0foralternatives
connect.limit()willberemovedinconnect3.0
Startingserver,listeningon8080
staticclassinit!
Loadingserverkeyfromdefault_key.pem
setserverkey
serverpublickeyis:-----BEGINPUBLICKEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0Gv5evNQCYusK+TnLy2B
lt7WLkSMcjKDzf/JQIkA7azKpJ8iYo8/W2ZTVQYHGxzglvPThkAkwjINpEEKHmQg
199tUDFMo46+FpYFa4A4pOVgF765Uhr84eKSMqCkJ4vzcV7mmrDUTFcmq8ERAOee
802deTBRBRoA7vey1ZjOBrP5WBzTfRAsnmX/ysWBAEe+ikE/4dtIeNlGmp1Z12ne
S1BTomc7d2LJZisJjQ3IszOguvW7DpwovMWxXIJjUy6Uh02zHaEth6ljjUaAeTPU
FZyt6FxWKnNubv8fFM59Ma9eFxKHvIZxCoVabYrilvXNqmraG2rHmrvaqE4lM2eN
3QIDAQAB
-----ENDPUBLICKEY-----
YourserverIPaddressis:192.168.1.200
serverstarted{host:'localhost',port:5683}
ThenexttutorialtohelpyouconnectSparkCorestoyourlocalcloudcanbefoundat:
https://community.spark.io/t/tutorial-local-cloud-1st-time-instructions/5589
Havefun!
k
Licensedunder:Attribution-ShareAlike4.0International(CCBY-SA4.0)
FireupLocalCloud!
1.)Copyserverpublickeytoownmachine
[email protected]:spark-server/default_key.pub.pemDesktop
2.)Sendcorepublickeytoserver
scpcore_keys/[email protected]:spark-server/core_keys
MiscInstructions