物聯網
WIFI
from cocopiPython import Networking
初始化
Networking()
連接WiFi
wifiContent(WiFiSSID,WiFiPSD)
参数信息
参数 |
值 |
说明 |
WiFiSSID |
字串 |
WiFi名稱,必填 |
WiFiPSD |
字串 |
WiFi密碼,必填 |
WiFi連接狀態
wifiIsContent()
獲取IP
getWifiIP()
樣例
from cocopiPython import NetWorking
Networking = NetWorking() # 初始化
Networking.wifiContent("CocoRobo_SZ","cocorobo2019")
while not Networking.wifiIsContent():
print("wifi連接中...")
print('wifi連接成功!')
print('IP地址:',Networking.getWifiIP())
天氣預報
from cocopiPython import Weather
初始化
Weather()
獲取天氣
getWeather(city,lang='zh-hans')
參數說明
参数 |
值 |
说明 |
city |
數字 |
城市代碼,必填,詳見中國城市代碼參照 |
lang |
字串 |
語言,選填,預設為簡體中文 |
樣例
from cocopiPython import Weather,NetWorking
# 聯網
Networking = NetWorking()
Weather = Weather()
Networking.wifiContent("CocoRobo_SZ","cocorobo2019")
while not Networking.wifiIsContent():
print("wifi連接中...")
print('wifi連接成功!')
weatherData = Weather.getWeather(101280601,"zh-hans")
print(weatherData)
郵件發送
from cocopiPython import Email
初始化
Email()
發送郵件
send(email,content,title)
參數說明
参数 |
值 |
说明 |
email |
字串 |
要發送的郵箱地址,必填 |
content |
字串 |
郵件內容,必填 |
title |
字串 |
郵件標題,必填 |
樣例
from cocopiPython import NetWorking,Email
Net = NetWorking()
email = Email()
Net.wifiContent("CocoRobo_SZ","cocorobo2019")
while not Net.wifiIsContent():
print("wifi連接中...")
print('wifi連接成功!')
email.send('1101068574@qq.com','who are you?','name')
雲端服務
from cocopiPython import Cloud
初始化
Cloud()
發送
sendData(key,data)
參數說明
参数 |
值 |
说明 |
key |
字串 |
雲端事件的API,必填 |
data |
字典 |
發送的數據,必填,以字典的格式發送,{key:value} |
樣例
from cocopiPython import NetWorking,Cloud
Net = NetWorking()
cloud = Cloud()
Net.wifiContent("CocoRobo_SZ","cocorobo2019")
while not Net.wifiIsContent():
print("wifi連接中...")
print('wifi連接成功!')
params = {"Property0":666}
cloud.sendData("7219bc312639056e95a42480f9870d9f",params)
time.sleep(2)
接收
getData(key,value)
參數說明
参数 |
值 |
说明 |
key |
字串 |
雲端事件的API,必填 |
value |
字串 |
屬性名稱,必填 |
樣例
from cocopiPython import NetWorking,Cloud
Net = NetWorking()
cloud = Cloud()
Net.wifiContent("CocoRobo_SZ","cocorobo2019")
while not Net.wifiIsContent():
print("wifi連接中...")
print('wifi連接成功!')
data_cloud = cloud.getData("7219bc312639056e95a42480f9870d9f",'Property0')
print(data_cloud)