MQTT demo client for Raspberry Pi
Javascript app (node.js) that reads temperatures on a Pi and makes available using MQTT.
The client code also:
- Talks to Pi GPIO hardware, reading switches and controlling LEDs.
node.js - Recommend node.js installation using NVM. Tested with latest node.js (v7.3.0).
- Refer to PI_PREP.md
MQTT Broker running on network, with WebSockets enabled
- This demo uses mosquitto running on a Pi Model 2. Refer to raspi-demo.conf and Mosquitto on Pi
Raspberry Pi. - Tested with Raspbian jessie on Pi 2 and Pi B+ models
- (OPTIONAL) LEDs, Resistors, capacitor, a switch and wiring. See SCHEMATICS.md for details.
MQTT PubSub topic structure being used in this demo
// Topic Structure
// =================
// iot-demo \
// `-<clientId> } base topic for this client
// | /
// |-> connected - 'true' or 'false'
// `-raspi
// |-> redled - 'on' or 'off'
// |-> greenled - 'on' or 'off'
// |-> cputemp - degrees C
// `-> gputemp - degrees C
So Topic "iot-demo/+/connected
" is status across all the clients
- Publishes information topics using MQTT
- Web server, for displaying MQTT data pages (described below)
- Read and Control GPIO pins on a Raspberry Pi (Switch, LEDs)
Displays a scrolling chart of MQTT temperature data streaming from Raspberry Pi using Javascript
- Uses MQTT over WebSockets + a Javascript graphing library
Displays real-time status "dashboard" for multiple Pis using Javascript.
- Uses web technologies like WebSockets and SVG. Uses MQTT (over WS) for realtime updates.
For the MQTT Broker used in this demo, see PI_PREP.md. Can run broker on same Pi as client.
Getting Started With A Client PiAssuming requirements are met, you can get a copy of the code by cloning git repository from GitHub:
Edit create-config.js
script to match your environment. It has values for broker name/WS port.
cd iot-demo
cd client
npm install
./create-config.js
node index.js
If everything is working, can visit URL to view index.html
( e.g., http://client:3000 ) for a "real-time" graph of the Pi temperatures. Your browser must support WebSockets for graphing to work-- most modern ones do.
Comments