Skip to content

Latest commit

 

History

History
 
 

lesson6

Lesson 6: Alternative Devices

Lab 6A: Node.js

Node.js Downloads include latest Long Term Support (LTS) version and npm

  • Pre-built installer and binary for Windows with an option to install (or upgrade) the necessary tools such as Chocalatey, Python, and Visual Studio
    • WARNING: Upgrading Python resets pip list with only pip and setuptools, requiring package reinstallation
  • Pre-built installer and binary for macOS (/usr/local/bin)
  • Linux binaries for x64 and ARM
  • Refresh the webpage at http://127.0.0.1:8080/ or http://localhost:8080/ to see server activities
$ node -v
$ npm -v
$ node -h
$ cd ~/iot/lesson6
$ node hello-world.js
$ node hello.js
Server running at http://127.0.0.1:8080/
response end call done
request end event fired
response end call done
request end event fired
^C
$ node http.js
0

1
2
^C
$

On Raspberry Pi via VNC Viewer, click the application menu on the left upper corner, select Programming to check whether Node-RED is installed

  • If Node-RED is not installed, select Preferences > Recommended Software to install Node-RED
  • Alternative installation as follows
$ bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered)
  • Run and view Node.js server at http://127.0.0.1:8080 on Raspberry Pi via VNC viewer or directly on a laptop computer at the Raspberry Pi IP address such as http://192.168.1.204:8080
  • Reload the web page to see the server responses and press control-c (^C) to quit
$ node -v
$ npm -v
$ node -h
$ cd ~/iot/lesson6
$ node hello.js
Server running at http://127.0.0.1:8080/
response end call done
request end event fired
response end call done
request end event fired
^C
$ node http.js
0

1
2
^C
$

Lab 6B: Pystache

Install Pystache and run example code

$ sudo pip3 install pystache
$ cd ~/iot/lesson6
$ cat say_hello.mustache
$ cat say_hello.py
$ python3 say_hello.py
Hi Alexa!
Hello, World!

['Hey ', _SectionNode(key='who', index_begin=12, index_end=18, parsed=[_EscapeNode(key='.'), '!'])]
Hey Google!
Hey Siri!
$

Optional Lab 6C: Particle Cloud

Sign up and log in Particle at https://www.particle.io

Install the Particle Agent on Raspberry Pi, log in the Particle account, and claim Raspberry Pi to the Particle account

$ bash <( curl -sL https://particle.io/install-pi )

If the Raspberry Pi hostname has changed, unclaim it on Particle Console, and run particle-agent again

$ sudo particle-agent setup

Download, install, and open Particle Mobile App on a smartphone

Log in Particle account and select Raspberry Pi

Tinker > D7 > digitalWrite() > HIGH or LOW to toggle the green activity LED

To remove the Particle Agent and its dependencies

$ sudo apt remove particle-agent
$ sudo apt autoremove
$ sudo rm -rf /var/lib/particle

Alternately, install Particle CLI on a laptop (not recommended for Raspberry Pi since it disables the Bash color prompt)

Windows

macOS or Linux

$ bash <( curl -sL https://particle.io/install-cli )
$ particle login
$ particle call <device_name> digitalwrite D7=HIGH
$ particle call <device_name> digitalwrite D7=LOW
$ particle logout