Start with the installation process outlined here if you haven't already.
Then, clone this repository into a folder using:
git clone https://github.com/nodebotsau/workshops
cd workshops/iot-intro
npm install
This will install:
- Interchange - useful for flashing your Arduino
- Johnny Five - JS framework for interacting with hardare (RPi & Arduino)
- Node Red - a rapid prototyping environment for event / flow orchestration of IoT devices from a browser
- Node Red plugins - Various plugins to node red that make your life easier and faster.
- Dashboard - provides a full UI suite
- GPIO - allows interaction with GPIO components.
- Mosca - A NodeJS based MQTT broker that provides a message queue
- mqtt.js - NodeJS command line publication and subscribe clients as well as library to interact with MQTT brokers from node or web applications.
From the repo folder execute the following with your arduino plugged into your computer.
./node_modules/.bin/interchange install StandardFirmata -a uno
Assuming no errors, you're good to go, if you get errors, come talk to us.
To make sure you can talk to the arduino okay leave it plugged in and then run the blink example.
node examples/blink.js
If the LED on pin 13 blinks on and off each second then you should be all good.
To run node red, run it with the following command:
./node_modules/.bin/node-red
This will then run an application server which you can access via http://localhost:1880 unless you change the port.
This blog post is a great introduction to Node Red.
To run Mosca:
./node_modules/.bin/mosca -v --http-port 8883
This will give you both an MQTT server on port 1883 locally (which you can point node red or some JS code at). In addition it will expose a websockets host on port 8883 if you want to use that from a browser.
We can use the MQTT node library to publish and subscribe to topics from the command line.
./node_modules/.bin/mqtt_sub -v -h test.mosquitto.org -t "sometopic/#"
Noting you can change the host parameter to your local mosca server for example.
./node_modules/.bin/mqtt_pub -h test.mosquitto.org -t "sometopic/presence" -m "Hi there subscribers"
Noting again that you can change the host parameter to your local mosca server for example.