D4E1: No-code IoT Weather Station With Micro:bit and Google Home / Nest

by FrederikDC in Circuits > Microcontrollers

1169 Views, 7 Favorites, 0 Comments

D4E1: No-code IoT Weather Station With Micro:bit and Google Home / Nest

scheme-ext.jpg

This project is an extension to the project No-code IoT weather station with Micro:bit. The basic project passed the inside temperature and light intensity to a public MQTT broker to be used in any kind of web or mobile application.

This extended version also allows to read the current outside weather conditions using a Google Home (currently known as Google Nest) when the logo on the micro:bit is pushed.

Schematically, the extended project looks like this:

  • micro:bit connects via USB to the Raspberry Pi
  • Raspberry Pi connects via Wifi with the OpenWeatherMap API and the Google Home device.

Little to no code was written to realise this project as MakeCode for micro:bit and the Node-RED environment are both no-code / low-code environments.

Supplies

supplies-ext.jpg

The following materials were used during this project:

  • Raspberry Pi model 3 B+ including
  • A power adapter
  • A 16GB SD card for storage (you can also use a 8GB card)
  • micro:bit including
  • A USB cable to connect to the Raspberry Pi
  • A Google Home / Nest device
  • Some elastics to attach the micro:bit to the Pi

Programming the Micro:bit

microbit-code-ext.jpg

If you have little or no experience with the micro:bit, first read the getting started tutorial on how to connect the micro:bit to your computer and transfer a program from your machine to the micro:bit.

The code on the micro:bit itself is simple to reproduce. You can also download the hex file.

  • Sending light and temperature is explained in the project No-code IoT weather station with Micro:bit
  • When the user touches the logo, the string "weather" followed by the new-line character is send over USB to the Node-red flow

"Writing Code" in Node-red

node-red-code-ext.jpg
google-devices.jpg

You can find the basics about installing and configuring a Raspberry Pi with Node-red in the project No-code IoT weather station with Micro:bit. It also discusses the code to send data from the micro:bit to a public MQTT broker.

This part focusses on getting the weather forecast from an external server and read it on a Google Home / Nest. The application will:

  1. check if the string "weather" was passed (Node Split light, temperature and weather) from the micro:bit
  2. send a request to the OpenWeatherMap API to get the current weather conditions
  3. Parse the results so that they can be used by the library node-red-contrib-castv2. This library allows using Text to Speech on Google Nest and Google Chromecast devices. The payload must be in the following format:
const info = msg.payload

const forecast = `
Vandaag wordt het ${info.weather[0].description} in ${info.name} 
met een maximum van ${Math.round(info.main.temp_max)} en een minimum van ${Math.round(info.main.temp_min)}.
Op dit moment is het ${Math.round(info.main.temp)} graden.`

msg.payload = {
    "app": "DefaultMediaReceiver",
    "type": "TTS",
    "text": forecast,
    "speed": 1.2,
    "language": "nl"
}

return msg;


Take the following steps to reproduce the code:

  1. Open the menu --> Manage pallete and install the node node-red-contrib-castv2. This is required to connect with Google devices in the network.
  2. Open the menu --> Import and copy / paste the code in json format
  3. Check the micro:bit node. It is possible that you need to adjust the serial port name (in my flow /dev/ttyACM0)
  4. Check the get weather forecast node and search for the URL property: https://api.openweathermap.org/data/2.5/weather?lat=50.823&lon=3.2649&appid=YOUR_API_KEY&units=metric&lang=nl
  5. change YOUR_API_KEY with your own key that you can get from https://openweathermap.org/api
  6. change the lat en long attributes to adjust the location
  7. Check the parse forecast node. You can change the forecast variabele, but be sure not to change the structure for the msg.payload object.
  8. Check the Google Home / Nest node and click the pencil next to Home or Add new castv2-connection...
  9. Click the magnifier icon to detect your Google devices
  10. Click the desired Home / Nest or Chromecast
  11. Deploy the code

Test Your Application

D4E1: a No-code IoT weather station (extended with Google Home / Nest)

Test the code by pressing the logo on the micro:bit and check the debug panel for potential errors.