電子發(fā)燒友App

硬聲App

0
  • 聊天消息
  • 系統(tǒng)消息
  • 評論與回復(fù)
登錄后你可以
  • 下載海量資料
  • 學(xué)習(xí)在線課程
  • 觀看技術(shù)視頻
  • 寫文章/發(fā)帖/加入社區(qū)
會(huì)員中心
創(chuàng)作中心

完善資料讓更多小伙伴認(rèn)識你,還能領(lǐng)取20積分哦,立即完善>

3天內(nèi)不再提示
創(chuàng)作
電子發(fā)燒友網(wǎng)>電子資料下載>電子資料>使用涂鴉云SDK構(gòu)建的假期旅行開源

使用涂鴉云SDK構(gòu)建的假期旅行開源

2022-11-01 | zip | 0.24 MB | 次下載 | 免費(fèi)

資料介紹

描述

概述

每當(dāng)我因工作和學(xué)習(xí)而感到壓力時(shí),假期真的是讓我興奮的地方。假日季節(jié)通常被認(rèn)為是從 11 月下旬到 1 月初。為什么不游覽這座城市或參觀新的地方,看看該鎮(zhèn)提供的所有亮點(diǎn)。由于旅行的速度,我們在探索所有地方時(shí)經(jīng)常會(huì)錯(cuò)過一些著名的目的地,慢慢地詳細(xì)描述賽道上的所有地標(biāo)(有時(shí)也是不可預(yù)測的天氣)。所以我想到的是一個(gè)簡單的解決方案來解決這個(gè)問題。Holidays Traveler 設(shè)備旨在按照您的步調(diào)穿越地標(biāo),只需將其連接到網(wǎng)絡(luò)即可。

設(shè)備將根據(jù) IP 地址、天氣更新和附近的著名地點(diǎn)和簡要摘要自動(dòng)檢測位置,并將這些更新通過電子郵件和短信發(fā)送到我們的手機(jī)上,讓觀光更有趣。

功能性

該設(shè)備是使用涂鴉云 SDK構(gòu)建的,這個(gè)涂鴉項(xiàng)目用例可以幫助開發(fā)人員為旅游業(yè)思考和創(chuàng)新——尤其是在營銷您的產(chǎn)品或其他方面。想象一下這樣的創(chuàng)新用例——當(dāng)用戶到達(dá)特定位置時(shí)向他們發(fā)送警報(bào),并建議他們參觀著名的公園、餐館、建筑物等。

Tuya到底是什么?

涂鴉智能是一個(gè)全球物聯(lián)網(wǎng)開發(fā)平臺(tái),構(gòu)建互連標(biāo)準(zhǔn),以橋接品牌、OEM、開發(fā)商和零售連鎖店在廣泛的智能設(shè)備和行業(yè)中的智能需求。

涂鴉基于全球公有云,通過提供硬件開發(fā)工具、整合公有云服務(wù)、提供智能業(yè)務(wù)開發(fā)平臺(tái),連接不同的智能場景和智能設(shè)備。

先決條件

$ pip install tuya-iot-py-sdk

設(shè)置涂鴉云賬號和項(xiàng)目:

注冊后,您將前往儀表板。從那里,轉(zhuǎn)到“云”并創(chuàng)建一個(gè)插入以下信息的項(xiàng)目。

poYBAGNgfReASUsvAAGmmqHCpYI249.png
?

授權(quán)所需的 API(我們將需要天氣、位置、電子郵件和 SMS API)

?
?
?
pYYBAGNgfRqAXui6AAIFVp6FvO8908.png
?
1 / 2
?

涂鴉云 API

最重要的是,您需要 ACCESS_ID 和 ACCESS_KEY 才能使用 API

poYBAGNgfR2AaPC9AACAf5fZR5Q860.png
?
from tuya_connector import (
TuyaOpenAPI
)
ACCESS_ID = "*************123"
ACCESS_KEY = "*************56565"
API_ENDPOINT = "https://openapi.tuyain.com"

# Project configuration
USERNAME = 'youremail@mail.com'  # email address or phone number
PASSWORD = 'yourpassword'

# Initialization of tuya openapi
openapi = TuyaOpenAPI(ENDPOINT, ACCESS_ID, ACCESS_KEY, AuthType.CUSTOM)
print(openapi.connect(USERNAME, PASSWORD))

如果一切正確,您將不會(huì)收到錯(cuò)誤代碼,并且可以繼續(xù)執(zhí)行其他步驟。我們將需要我們的位置數(shù)據(jù)來使用涂鴉天氣 API,因此我們將首先獲取我們的 IP 地址,然后使用涂鴉 LBS 服務(wù) API 找出我們的坐標(biāo)。獲得地理坐標(biāo)后,我們將使用 Wikipedia API 搜索地標(biāo)和摘要。

# Device IP
url = 'http://ipinfo.io/json'
response = urlopen(url)
data = json.load(response)
IP = data[ 'ip' ]

# Get location of device through IP
location = openapi.get(f'/v1.0/iot-03/locations/ip?ip={IP}')
print(location)
location = location[ 'result' ]
latitude, longitude = location[ 'latitude' ], location[ 'longitude' ]

現(xiàn)在我們將使用天氣 API 獲取我們所在位置的天氣數(shù)據(jù)

weather_url = f'/v2.0/iot-03/weather/current?lat={latitude}&lon={longitude}'
weather = openapi.get(weather_url)
condition = weather['result']['current_weather']['condition']
air_quality = weather['result']['air_quality']['aqi']
print(condition, air_quality)

現(xiàn)在我們將構(gòu)建消息,但在此之前讓我們探索涂鴉短信和電子郵件 API,

sent = openapi.post("/v1.0/iot-03/messages/mails/actions/push", dict({  "to_address": "hello@gmail.com",
  "template_id": "MAIL_1624531323",
  "reply_to_address": "hi@gmail.com"}))

上面是請求參數(shù), 1. template_id:是郵件模板的ID。涂鴉提供默認(rèn)設(shè)置,您也可以創(chuàng)建自己的。公共默認(rèn)模板,MAIL_1624531323, MAIL_1624531338

2. reply_to_address:表示用戶將發(fā)送回復(fù)的地址。

我們將根據(jù)我們的項(xiàng)目創(chuàng)建一個(gè)新的電子郵件模板,您可以直接從涂鴉云 API 瀏覽器中制作它https://iot.tuya.com/cloud/explorer

{
  "name": "Don't Miss These Places Traveller!",
  "title": "Hello!",
  "sender_name": "Jimmy",
  "content": "Hey! We found some amazing places near you, ${landmarks}. Today's weather is ${condition} and AQI is ${aqi}.",
  "type": 2,
  "remark": "This email is for tourists to get aware of nearby landmarks based upon their locations"
}

第一個(gè)字符串是請求參數(shù)。字典是為了內(nèi)容。

  • name是您的模板的名稱。
  • content代表消息內(nèi)容。
  • type用于消息的類型 - 驗(yàn)證碼、通知或促銷。我一直把它作為促銷(2)

成功信息應(yīng)該是這樣的,

pYYBAGNgfSCAGWP9AAG-iy5nid8508.png
?
{
  "result": {
    "template_id": "MAIL_9584653696"
  },
  "success": true,
  "t": 1640579722731
}

保存 template_id,我們將需要它進(jìn)行進(jìn)一步的步驟。請注意,在審核并允許之前,您將無法使用此模板。別擔(dān)心,這個(gè)過程將需要不到 2 個(gè)工作日。

短信模板也一樣,直接在涂鴉云API瀏覽器

poYBAGNgfSOAZmTWAAIDki_Yi-4334.png
?

初始測試對模板有好處,請參閱下面的 SMS 和電子郵件的外觀

pYYBAGNgfSWAMMPGAABigKnWPi8523.png
?
poYBAGNgfSqALv3dAADznpaQ8D4037.jpg
?

準(zhǔn)備好兩個(gè)模板后,讓我們跳到我們的代碼。

landmarks = wikipedia.geosearch(lat, lon, results=2)
landmarksListToStr = ' '.join(map(str, landmarks))

params = {
    "landmarks": landmarksListToStr,
    "condition": condition,
    "aqi": air_quality
}

payload_json = json.dumps(params)
print(payload_json)

email_sent = openapi.post("/v1.0/iot-03/messages/mails/actions/push", dict({"to_address": "gadecito@ryteto.me",
                                                                            "template_id": "MAIL_9584653696",
                                                                            "template_param": payload_json,
                                                                            "reply_to_address": ""
                                                                            }))

print(email_sent)

在代碼部分中找到完整的代碼。在聯(lián)網(wǎng)的 Raspberry Pi 設(shè)備上運(yùn)行程序并隨身攜帶(使用按鈕等觸發(fā)機(jī)制來防止收件箱填滿)

連接按鈕后,在腳本中使用以下代碼

import RPi.GPIO as GPIO
import time
from tuya_iot import (
    TuyaOpenAPI,
    AuthType,
)
from urllib.request import urlopen
import json
import wikipedia

url = 'http://ipinfo.io/json'
# Cloud project authorization info
ACCESS_ID = 'ecnthtncb7d2tpmuzlzs'
ACCESS_KEY = 'b75ce52xxxxxxxxxxxxxxxxxx'

# Select an endpoint base on your project availability zone
# For more info: https://developer.tuya.com/en/docs/iot/api-request?id=Ka4a8uuo1j4t4
ENDPOINT = "https://openapi.tuyain.com"

# Project configuration for authorized account
USERNAME = 'test1@gmail.com'  # email address or phone number
PASSWORD = 'Job894455'

SMS_TEMPLATE_ID = "SMS_2460072921"  # SMS template ID
EMAIl_TEMPLATE_ID = "MAIL_9584653696"  # Email template ID

# Initialization of tuya openapi
openapi = TuyaOpenAPI(ENDPOINT, ACCESS_ID, ACCESS_KEY, AuthType.CUSTOM)
print(openapi.connect(USERNAME, PASSWORD))

# Setup the Pin with Internal pullups enabled and PIN in reading mode. 
GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.IN, pull_up_down = GPIO.PUD_UP)

# Add our function to execute when the button pressed event happens 
GPIO.add_event_detect(18, GPIO.FALLING, callback = SendMsg, bouncetime = 2000)

def SendMsg():
    response = urlopen(url)
    data = json.load(response)
    print(data)
    IP = data['ip']

    # Get location of device through IP
    location = openapi.get(f'/v1.0/iot-03/locations/ip?ip={IP}')
    print(location)
    location = location['result']
    latitude, longitude = location['latitude'], location['longitude']

    landmarks = wikipedia.geosearch(latitude, longitude, results=5)
    landmarksListToStr = ' '.join(map(str, landmarks))

    # get weather based on geo location
    weather_url = f'/v2.0/iot-03/weather/current?lat={latitude}&lon={longitude}'
    weather = openapi.get(weather_url)
    print(weather)
    condition = weather['result']['current_weather']['condition']
    air_quality = weather['result']['air_quality']['aqi']
    print(condition, air_quality)

    params = {
        "landmarks": landmarksListToStr,
        "condition": condition,
        "aqi": air_quality
    }

    payload_json = json.dumps(params)
    print(payload_json)

    email_sent = openapi.post("/v1.0/iot-03/messages/mails/actions/push", dict({"to_address": "gadecito@ryteto.me",
                                                                                "template_id": "MAIL_9584653696",
                                                                                "template_param": payload_json,
                                                                                "reply_to_addr}))

    sms_sent = openapi.post("/v1.0/iot-03/messages/sms/actions/push", dict({"country_code": "91",
                                                                            "phone": "748000000",
                                                                            "template_id": "SMS_2460072921",
                                                                            "template_param": payload_json,
                                                                            "sign_name": ""
                                                                            }))

    print(email_sent)
    print(sms_sent)                                                                  }))

    sms_sent = openapi.post("/v1.0/iot-03/messages/sms/actions/push", dict({"country_code": "91",
                                                                            "phone": "748000000",
                                                                            "template_id": "SMS_2460072921",
                                                                            "template_param": payload_json,
                                                                            "sign_name": ""
                                                                            }))

    print(email_sent)
    print(sms_sent)

未來的步驟:

為什么不加入涂鴉云,為您的下一個(gè) SMS 和 EMAIL 通知智能項(xiàng)目使用云 API 進(jìn)行創(chuàng)新。幾乎所有這些 API 都以幾乎相同的方式使用。請求參數(shù)和包含所有所需內(nèi)容的字典。文檔非常易于遵循。


下載該資料的人也在下載 下載該資料的人還在閱讀
更多 >

評論

查看更多

下載排行

本周

  1. 1山景DSP芯片AP8248A2數(shù)據(jù)手冊
  2. 1.06 MB  |  532次下載  |  免費(fèi)
  3. 2RK3399完整板原理圖(支持平板,盒子VR)
  4. 3.28 MB  |  339次下載  |  免費(fèi)
  5. 3TC358743XBG評估板參考手冊
  6. 1.36 MB  |  330次下載  |  免費(fèi)
  7. 4DFM軟件使用教程
  8. 0.84 MB  |  295次下載  |  免費(fèi)
  9. 5元宇宙深度解析—未來的未來-風(fēng)口還是泡沫
  10. 6.40 MB  |  227次下載  |  免費(fèi)
  11. 6迪文DGUS開發(fā)指南
  12. 31.67 MB  |  194次下載  |  免費(fèi)
  13. 7元宇宙底層硬件系列報(bào)告
  14. 13.42 MB  |  182次下載  |  免費(fèi)
  15. 8FP5207XR-G1中文應(yīng)用手冊
  16. 1.09 MB  |  178次下載  |  免費(fèi)

本月

  1. 1OrCAD10.5下載OrCAD10.5中文版軟件
  2. 0.00 MB  |  234315次下載  |  免費(fèi)
  3. 2555集成電路應(yīng)用800例(新編版)
  4. 0.00 MB  |  33566次下載  |  免費(fèi)
  5. 3接口電路圖大全
  6. 未知  |  30323次下載  |  免費(fèi)
  7. 4開關(guān)電源設(shè)計(jì)實(shí)例指南
  8. 未知  |  21549次下載  |  免費(fèi)
  9. 5電氣工程師手冊免費(fèi)下載(新編第二版pdf電子書)
  10. 0.00 MB  |  15349次下載  |  免費(fèi)
  11. 6數(shù)字電路基礎(chǔ)pdf(下載)
  12. 未知  |  13750次下載  |  免費(fèi)
  13. 7電子制作實(shí)例集錦 下載
  14. 未知  |  8113次下載  |  免費(fèi)
  15. 8《LED驅(qū)動(dòng)電路設(shè)計(jì)》 溫德爾著
  16. 0.00 MB  |  6656次下載  |  免費(fèi)

總榜

  1. 1matlab軟件下載入口
  2. 未知  |  935054次下載  |  免費(fèi)
  3. 2protel99se軟件下載(可英文版轉(zhuǎn)中文版)
  4. 78.1 MB  |  537798次下載  |  免費(fèi)
  5. 3MATLAB 7.1 下載 (含軟件介紹)
  6. 未知  |  420027次下載  |  免費(fèi)
  7. 4OrCAD10.5下載OrCAD10.5中文版軟件
  8. 0.00 MB  |  234315次下載  |  免費(fèi)
  9. 5Altium DXP2002下載入口
  10. 未知  |  233046次下載  |  免費(fèi)
  11. 6電路仿真軟件multisim 10.0免費(fèi)下載
  12. 340992  |  191187次下載  |  免費(fèi)
  13. 7十天學(xué)會(huì)AVR單片機(jī)與C語言視頻教程 下載
  14. 158M  |  183279次下載  |  免費(fèi)
  15. 8proe5.0野火版下載(中文版免費(fèi)下載)
  16. 未知  |  138040次下載  |  免費(fèi)