https://github.com/idcrook/rpi-iot-demo-2017
January 9, 2017
“Oh, so they have internet on computers now!” ~Homer Simpson
Abbreviated as "IoT", refers to physical objects that feature an IP address and can communicate using the Internet.
Examples: Webcams, baby monitors, Weather stations, Hue light bulbs, WeMo plugs, Nest thermostat, Amazon Echo ...
Question: Does anyone know what the “S” in “IoT” stands for?
Answer: Security.
MQTT is an "Internet of Things" connectivity protocol.
Originally created to monitor oil pipelines over satellite links, MQTT is now an open standard.
In MQTT protocol, a "Broker" does the work of message routing.
For our demo, MQTT Broker is:
rpit5 connected -> iot-demo/rpit5/connected
If MQTT streaming is:
iot-demo/rpit5/raspi/cputemp
Raspberry Pi example of a SBC (Single Board Computer)
Name | Price | Year |
---|---|---|
Model B 3 (onboard WiFi, BT) | $35 | 2016 |
Raspberry Pi Zero | $5 | 2015 |
Original Model B | $12 | 2012 |
Raspberry Pi models "B+" or "2" in front of you
Each Pi shares data using MQTT
<name>.local
:
pi
password: raspberry
~/iot-demo/client/index.js
cd iot-demo/client screen -R <Enter> node index.js ... <Ctrl-C> to quit ...
username: pi
password: raspberry
Name | IP Address |
---|---|
rpit3.local |
192.168.8.23 |
rpit4.local |
192.168.8.24 |
rpip5.local |
192.168.8.25 |
rpip6.local |
192.168.8.26 |
rpip7.local |
192.168.8.27 |
rpip8.local |
192.168.8.28 |
rpip9.local |
192.168.8.29 |
rpip10.local |
192.168.8.30 |
Live Dashboard, Served from a Pi
(MQTT + WebSockets + SVG + Javascript)
index.js
has a few things going on:
For that last part to work, it needs to be wired up
Wire Pi up to make a connected switch
Switch presses and LEDs are handled using onoff library.
var button = new Gpio(button_Gpio, 'in', 'both', {debounceTimeout: 20});
var redLed = new Gpio(redLed_Gpio, 'low');
var buttonPressedCount = 0;
button.watch(function (err, value) {
if (value === 0) {
console.log('BUTTON PRESSED!');
// implement a toggle based on button presses
buttonPressedCount += 1;
if (buttonPressedCount % 2) {
client.publish(pubRedLed, 'on', {qos: 1, retain: true});
redLed.writeSync(1); // 1 = on, 0 = off
} else {
client.publish(pubRedLed, 'off', {qos: 1, retain: true});
redLed.writeSync(0); // 1 = on, 0 = off
}
}
}
A mini Breadboard connects all holes in a row on each side
An LED has a direction. Longer lead is "Positive"
Longer lead shown with a bend in diagram