1. 程式人生 > >Let's hear the weather today!

Let's hear the weather today!

As a cloud developer advocate, my job is to explore and work with different IBM Cloud services. Based on my interest in IoT, Node-RED and Watson have always grabbed my attention. Recently, I was searching through some recipes and came across Weather service integration with Watson Text–to–Speech on Node-RED

. Following are my experiences in completing the recipe.

Node-RED primer


Node-RED is a drag-and-drop programming tool based on a web browser. It’s used for wiring hardware devices, APIs, and other IoT systems with online services. Built on Node.js, it can run locally or in the cloud.

Nodes used in the recipe

The most common nodes used in flows are:

  • Inject: Sends messages in the flow, either manually or at regular intervals
  • Function: Run the message
  • Debug: Displays selected message properties


  • common nodes

The other nodes used in this recipe are: Template, Http In, Weather Insights, and Watson Text-to-Speech service

  • Template: Sets a property based on the provided guide
  • Http In: Sends HTTP requests and returns the response
  • Weather Insights: Enables you to access historical and real-time weather data from The Weather Company
  • Watson Text-to-Speech service: Understands text and natural language to generate synthesized audio output complete with appropriate cadence and intonation
main nodes

Process

Start with an inject node, which will trigger the message into the flow. Add a function node and define the location for which you want to hear out the weather.

msg={ street: "Hilal road", city: "Islamabad", country: "pakistan" }; 
return msg;

Next, add a template node that will fetch the location from the HTTP request for Geo Location. The address will be extracted in the form of latitude and longitude using the following code

msg.payload=msg.payload[0].lat+","+msg.payload[0].lon; 
return msg;

After collecting the location data, join the Weather Insight node in the flow to call the Weather Company data service. In this recipe, I extracted the temperature from the data collected from the Weather Company for my location using the following code:

msg={ temp: msg.observation.temp, city: msg.observation.obs_name}; 
return msg;

After collecting and extracting data, I now had to create a complete answer sentence. For this purpose, the recipe suggests to add another template node with the following configurations:

Temperature

Adding a debug node at this point will display the temperature as output, which is a traditional way to check the temperature.

The most interesting and fun part for me was the ending where I integrated Watson Text-to-Speech (TTS) service to hear the weather. I dragged the TTS node from the palette and connected it with the answer node.

Text-to-Speech

After setting the values, I added a function that acts like a buffer to reorder the parameters:

return {payload:msg.speech};

Finally, I added the Play Audio node. This node takes the audio file and plays it directly from the Node-RED framework on your computer's speakers.

flow

This recipe was a fun way to integrate multiple services of IBM Cloud with each other. We can also play around with the flow and further refine it by extracting weather data for different dates or changing the locations. It can also be used as a demo by cloud developer advocates for engaging developers and grabbing their attention.

I'd love to hear your results! Leave me a comment below and let me know how you do with the recipe.

相關推薦

Let's hear the weather today!

As a cloud developer advocate, my job is to explore and work with different IBM Cloud services. Based on my interest in IoT, Node-RED and Watson have al

What are the ten most cited sources on Wikipedia? Lets ask the data.

Why does this data matter?First off, it allows us to analyze, at scale, where Wikipedia gets its information from. Understanding the provenance of informat

Lets Build the Tiniest Blockchain

Note: Part 2 of this piece can be found here.Although some think blockchain is a solution waiting for problems, there’s no doubt that this novel technology

Lets clear up the confusion around the slice( ), splice( ), & split( ) methods in JavaScript

JavaScript built-in methods help us a lot while programming, once we understand them correctly. I would like to explain three of them in this article: the

Hi friends. Lets talk about the IPCC report.

I’ve marked the calendar to indicate the US election cycle because I live in the US and we’re due for one in a few weeks so it felt like a relevant framing

Let's Explain A.I. With the Help of This Dog Presented by Facebook

Engineers train computers to recognize common patterns in mountains of data by exposing them to numerous variations of the same thing. This process is call

【Jackery's Special Column 】Today is difficult,tomorrow is more difficult,but the day after tomorrow is beautiful,Keep Fight !

Today is difficult,tomorrow is more difficult,but the day after tomorrow is beautiful,Keep Fight !...

在Ubuntu 16.04安裝 Lets Encrypt並配置ssl

lan 域名 rtb blank cert org 配置 pac 安裝配置 1.安裝前準備 1)要確保python的默認版本為2.7及以上版本。 2)需要配置的apache、nginx需要提前配置綁定域名。 2.安裝ssl 在這個https://certbot.eff.or

make: Warning: File `Makefile' has modification time 1.8e+06 s in the future

通過 系統 -m time war rom 我想 warning mes 通過這個錯誤提示信息我們可以知道,Makefile的修改時間點是Linux當前的一個未來時間點。可以通過修改Linux的當前時間來解決這個問題: $sudo date -s ‘hh:mm:ss yy

HawkHost主機cPanel面板快速安裝Lets Encrypt免費SSL證書

HawkHost主機 老鷹主機 虛擬主機 如今我們越來越多的網站需要使用到SSL安全證書,尤其是我們做電商業務的網站,一來可以確保用戶信息的安全,二來可以增加用戶的安全意識識別,三來外貿類網站一般在谷歌中的排名優勢如果有SSL證書還是有一定的加分的。如果我們有使用HawkHost老鷹主機虛擬

lets encrypt之nginx-https沒有小鎖

body img header pos secure str javascrip bubuko port 1、使用let‘s encrypt 加密後的nginx,訪問的時候,發現沒有小鎖,chrome中: 火狐瀏覽器上: 會看到如上信息,這是因為css、圖片或

Using Lets Encrypt for free SSL Certs with Netscaler

module putty rar perl 4th com via pac services Using Let’s Encrypt for free SSL Certs with Netscaler If you haven’t heard, Let’s Encryp

【Lv1-Lesson005】Small Talk about the Weather

mat new 白雪公主 真的 相對 nice ace log lar When two Englishmen meet, their first talk is of the weather. --Samuel Johnson 兩個英國人相遇,他們第一句話一定是聊天

CentOS 7配置Lets Encrypt支持免費泛域名證書

證書 token rep -h clas oot serve 執行 details Let’s Encrypt從2018年開始支持泛域名證書,有效期3個月,目前僅支持acme方式申請,暫不支持certbot。 1、安裝acme.sh curl https://get.ac

解決 Lets Encrypt SSL 證書配置錯誤

apt work 更新 pass 問題: rest 原因 ubuntu pos 解決 Let’s Encrypt SSL 證書配置錯誤”DNS problem: NXDOMAIN looking up A for xxx.com” 一、問題:Let’s Encrypt 配置

bzoj 1753: [Usaco2005 qua]Who's in the Middle【排序】

name ostream AS esp AR read asc AC AI ……這可能是早年Pascal盛行的時候考排序的吧居然還是Glod…… #include<iostream> #include<cstdio> #include<algo

快速簽發Lets Encrypt證書指南

文件 ocs adc 目前 shel url issue 安裝 頁面 本文僅記錄給自己的網站添加“小綠鎖”的動手操作過程,不涉及HTTPS工作原理等內容的講解,感興趣的同學可以參考篇尾的文章自行了解。 簡單了解下我的實驗環境: 雲服務器:CentOS 7.4 網站宿主:N

Let`s go!

lin for man while esp cau with line HERE Here`s to the crazy ones.The misfits.The rebels.The troublemakers.The round pegs in the square h

使用Lets Encrypt為自己的子域名分配證書

最近由於想要同時部署多個服務到自己的主機上,而自己又懶得記ip地址,所以想要用子域名來代替,。, 這裡安裝的certbot是針對centos的,安裝教程由certbot提供 按照上面的教程安裝完之後,主機會增加certbot命令,執行命令 certbot cert

Let Me Count The Ways(Kickstart Round H 2018)

題目連結:https://code.google.com/codejam/contest/3324486/dashboard#s=p2 題目: 思路:      程式碼實現如下:   1 #include <set> 2 #include &l