NOTE: These directions assume Raspbian on RPi 3 B+.
Starting from your home directory or wherever you want to build this from (in my example, it is /home/pi
):
git clone https://github.com/joewxboy/EdgeMessageBus.git
cd EdgeMessageBus/Mosquitto
export MQTT_USERNAME=[username here, ex. "mqtt"]
export MQTT_PASSWORD=[password here]
This will create an image named mosqtt
.
NOTE: Change /home/pi
to your path prefix.
sudo docker build --build-arg MQTT_PASSWORD=${MQTT_PASSWORD} \
--build-arg MQTT_USERNAME=${MQTT_USERNAME} \
-t mosqtt -f- ./ < Dockerfile.armhf
sudo docker run --rm -it -p 1883:1883 mosqtt
You have now created and exposed an MQTT server with the credentials you specified on the RPi at port 1883.
The server can be stopped by pressing Control-c in the terminal.
TRY: Connect to your MQTT Server with a client (I like MQTTLens), subscribe to your MQTT_TOPIC, and publish a small JSON object to your MQTT_TOPIC and watch it show up in your subscription.
{
"type":"location",
"loctype":"geocode",
"data":{
"lat":"34.02",
"lon":"-84.62"
},
"child":[]
}
Sign up for IBM Cloud and provision the Weather Company Data service. The Weather Company Data service uses the following APIs. You can reference the documentation here.
cd ../Weather
Set your Weather API key <YOUR_API_KEY>
and credentials <YOUR_API_PASSWORD>
when running the application
export WEATHER_API_KEY=<YOUR_API_KEY>
export WEATHER_API_URL=https://<YOUR_API_KEY>:<YOUR_API_PASSWORD>@twcservice.mybluemix.net/api/weather
export MQTT_USERNAME=[username here, ex. "mqtt"]
export MQTT_PASSWORD=[password here]
export MQTT_TOPIC=[topic here, ex. "test/json"]
export MQTT_BROKER="myqt"
NOTE: The image will throw errors and die if an MQTT service is not available as configured.
sudo docker build --build-arg MQTT_PASSWORD=${MQTT_PASSWORD} \
--build-arg MQTT_USERNAME=${MQTT_USERNAME} \
--build-arg MQTT_TOPIC=${MQTT_TOPIC} \
--build-arg MQTT_BROKER=${MQTT_BROKER} \
--build-arg WEATHER_API_KEY=${WEATHER_API_KEY} \
--build-arg WEATHER_API_URL=${WEATHER_API_URL} \
./ -t wxapi
sudo docker run --rm -it wxapi
TRY: Publish a location JSON Object to the MQTT Topic and watch the app respond with the weather forecast
{
"type":"location",
"loctype":"geocode",
"data":{
"lat":"34.02",
"lon":"-84.62"
},
"child":[]
}
cd ../Display
I'll assume you've already done this for a previous step.
sudo docker build --build-arg MQTT_PASSWORD=${MQTT_PASSWORD} \
--build-arg MQTT_USERNAME=${MQTT_USERNAME} \
--build-arg MQTT_TOPIC=${MQTT_TOPIC} \
--build-arg MQTT_BROKER=${MQTT_BROKER} \
./ -t wxhat-pdm
sudo docker run --rm -it --device /dev/i2c-1 --privileged wxhat-pdm
TRY: Publish a location JSON Object to the MQTT Topic and watch the app respond
Assuming you are still in the Display
directory, change over to the Node-RED
folder:
cd ../Node-RED
export MQTT_USERNAME=[username here, ex. "mqtt"]
export MQTT_PASSWORD=[password here]
export MQTT_TOPIC=[topic here, ex. "test/json"]
export MQTT_BROKER="myqt"
NOTE: The TOPIC and BROKER variables are new, and weren't defined earlier.
sudo docker build --build-arg MQTT_PASSWORD=${MQTT_PASSWORD} \
--build-arg MQTT_USERNAME=${MQTT_USERNAME} \
--build-arg MQTT_TOPIC=${MQTT_TOPIC} \
--build-arg MQTT_BROKER=${MQTT_BROKER} \
-t nred -f- ./ < Dockerfile.armhf
sudo docker run --rm -it -p 1880:1880 nred
NOTE: The above refers to a Dockerfile for the armhf
architecture, like the Raspberry Pi.
If you're using an x86_64 machine, use the Dockerfile.amd64
file instead.
TRY: Connect to the Node-RED Dashboard web UI in your browser at: http://[machine IP address]:1880/ui/#/0
If you have the Mosquitto, Weather, and Display services running, then you should be able to click a button for a location and see the corresponding weather for that location load into the center of the dashboard, and the buttons representing the Display light up for five seconds for the relevant indicators for that location's weather.