web.md 2.7 KB

物联网

WIFI

from cocopiPython import Networking

初始化

Networking()

连接WIFI

wifiContent(WiFiSSID,WiFiPSD)

参数信息

参数 类型 说明
WiFiSSID str WIFI名称,必填
WiFiPSD str 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 str 城市代码,必填,详见中国城市代码参照
lang str 语言

样例

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 string 收件人邮箱,必填
content string 邮件内容,必填
title string 邮件标题,必填

样例

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 string 云端事件的API,必填
data 字典 发送的数据,必填,以字典的格式发送,{属性:’123‘}

样例

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)