Tutorial: Setting up OurWeather MQTT / System Tests – Part 5/5
We are pleased to announce Version 026+ of the OurWeather software and the big change is that we now support the Amazon Alexa, Echo, Echo Plus, and all other Amazon Voice systems. In this series of tutorials we will show you how to connect up the Alexa systems in your house to your OurWeather station. We will be rolling this really cool feature set into our other major kit offerings including:
- – GroveWeatherPi – Raspberry Pi Based Weather Station Kit
- – SmartPlantPi – Raspberry Pi Based Plant Watering and Environmental Kit
- – The ThunderBoard Raspberry Pi IOT Lightning Detection Kit
This is a five part instructional tutorial to get your Amazon Alexa to OurWeather Interface working. All source code is provided!
While we are focusing on OurWeather in this series, the techniques we developed are good for many projects.
- - Part 1 - Voice Time! OurWeather and Amazon Alexa - Part 1
- - Part 2 - Setting up PubNub MQTT Broker
- - Part 3 - The Alexa Skill
- - Part 4 - The AWS Lambda Serverless Function
- - Part 5 - Setting OurWeather MQTT to Alexa up and System Tests
The Alexa Voice to OurWeather Project
There are four major parts to this project.
- – PubNub – MQTT Broker between OurWeather and the AWS Lambda function
- – The Alexa Skill – Controls Alexa on Echos in your house
- – The AWS Lambda Serverless Function for brokering information from PubNub to the Alexa Skill
- – OurWeather – MQTT Publisher Weather Information to PubNub
In part 4, we address the Lambda function on Amazon AWS and hooking it up to OurWeather.
What is OurWeather?
OurWeather is an ESP8266 based connected weather station containing 7 different sensors that will teach about electronics, software and the weather. It contains all the sensors and wires to make a fully functional, WiFi weather station. No software programming is required, it works right out of the box. However, if you want to change the way OurWeather works, add your own software or do something entirely different, we have the Open Source software available. And what is one of the coolest features of OurWeather? Building the kit requires NO SOLDERING. It uses Grove Connectors. It is all plug and play based building, with a full step-by-step photograph based instruction manual. It is a safe and educational way to learn about weather, electronics and science topics. You can watch our successful kickstarter video here: https://youtu.be/pw6hSNSQnsM
Set up OurWeather
Before starting the next section, make sure you have assembled OurWeather, tested it and updated the software to the latest version available (at least 027+). Look in the downloads section of the OurWeather product page for instructions and manuals to do this.
What Do We Want to Accomplish?
The Alexa to OurWeather Interface works by having OurWeather send weather data every five minutes to PubNub (Part 1) via MQTT. That data is then read by the Lambda function (Part 4) when requested by the Alexa Skill (Part 2) when activated by a voice command to Alexa from an Amazon Echo or similar Alexa enabled device.
In Part 5, we are connecting the OurWeather hardware to PubNub, completing the Design.
Connecting OurWeather To PubNub
Go back to Part 2 and make sure you have your PubNub publish and subscribe keys (we have also used these in Part 4).
Open up the www.switchdoc.com/OurWeatherAdmin.html page.
Step 1) Make sure that your IP Number is set in the page to your OurWeather. The Manuals on the OurWeather page show you how to find your IP Number and do this.
Step 2) Click on “Check For Latest OurWeather Version” to make sure you have the latest software and you are connected to OurWeather
Step 3) Under the OurWeather Alexa Admin Functions section, add the following:
- – Admin Password
- – PubNub Publish Key
- – PubNub Subscribe Key
Now your screen should look something like this:
Click on the “Enable Alexa” button and you should get the following popup:
Reboot OurWeather by removing the power and reapplying the power. You should see the Alexa Screen as it boots up showing that Alexa is enabled and the part of the Publish Key. OurWeather is now connected to PubNub and thus is connected to Alexa.
Wait for five minutes before continuing. OurWeather only sends data to PubNub every five minutes. If you are impatient, look at the “Internals Added to OurWeather” section below for the raw commands that can force an update to PubNub from OurWeather immediately.
Testing
First we can check to see that your MQTT message is getting to PubNub. Go to your PubNub account (that you set up in Part 2) and go down into your SDL2Alexa App and then select your subscribe key from the OurWeather Key (you should have this saved somewhere else too).
Next, Click on the side tab to Debug Console. Make the Default channel “OWIOT1” and place your pub-sub key into the Authorization key. Click on Add Client.
Now you should have a screen that looks like this:
Wait five minutes and you should receive an JSON MQTT message from OurWeather as below:
You are wired up!
Full System Test
Well, now after setting up the Alexa Skill, the Lambda Function, PubNub and OurWeather we are ready to go for our full system test.
Say “Alexa, Ask OurWeather status”
You should hear the following, with your information:
Internals Added to OurWeather
Here are the REST Interface commands added to OurWeather for Alexa.
EnablePubNub | Enable/disable PubNub (Alexa) on OurWeather – sets the Pub and Sub keys | https://https://192.168.1.102/EnablePubNub?params=admin,1,pub-c-cc4d6662-190a-42af-a14d-3be4e6040ff6,sub-c-47725a16-f0e7-11e7-9869-a6bd95f83dd1
Admin password is first parameter. Second parameter is Enable (1) or Disable (0) Alexa. Third Parameter is the MQTT PubNub Publish Key and the Fourth Parameter is the MQTT PubNub Subscribe Key |
As of OurWeather software version 026, return_value will be 0 if password fails, 1 if the set pub/sub key succeeds |
SendPubNubState | Sends an MQTT Message to the PubNub site. Great to start things out. | https://192.168.1.102/SendPubNubState?params=admin
First Parameter is the Admin password |
return value is 1 |
For example, if your OurWeather Admin password is “admin”, you could send the following command by pasting this in a browser to force OurWeather to send an update to PubNub. This assumes that your OurWeather IP is 192.168.1.102, you will need to change that to your OurWeather IP.
https://192.168.1.102/SendPubNubState?params=admin
If it is successful (which doesn’t mean that PubNub was successful by the way, just that OurWeather tried), you will get the following JSON in your browser window.
{"return_value": 1, "id": "1", "name": "OurWeather", "connected": true}
And if you have your keys correct, you should see an update in the PubNub Debug Console.
Ask Alexa “Alexa, Ask OurWeather timestamp” and it should reply with the time close to when you sent the above command.
Coming Next
We are next adding Alexa to our SmartPlantPi project. Talk to your plants!