新大陆物联网云平台 (python (一)

在主流的物联网云平台中 ,作者用的最多的是新大陆的,有幸参加过2023年的新大陆举行的金砖职业技能大赛物联网赛项。荣获浙江省赛区的第四名。当时主要有两人合作,一人配置物联网云平台,一人主硬件,我是主硬件+硬件跟软件联合运行。

 
先贴当时给的题目里面的第一套题



 

当时给的题目之一,当时遇到的主要问题是获取不到返回回来的token  ,还好后面请教了新大陆一个大哥,向我讲解了,一点就通啊,请求头的问题。现在将这份代码开源一下,比较简略。毕竟比赛争分多秒,也不会写出很好看的代码,越快越好,完成得分项就行。

效果实际图,
代码如下,因为在新大陆中id都是唯一的,我用**这个来代替,大家自己根据在自己实际的来进行修改

import requests
import os
import time
import tkinter
login_url=f'http://api.nlecloud.com/users/login'

baoticanshu={
    'Account':'135*****',
    'Password':'123456789'
}
shebeiid='78***19'
window=tkinter.Tk()
window.geometry("300x300")
window.title("安全文明出行监控系统")
image_show=tkinter.Label(window,width=200,height=200)
image_show.pack()
absfile=os.path.dirname(os.path.abspath(__file__))
red_image=tkinter.PhotoImage(file=os.path.join(absfile,"red_light.png"))
green_image=tkinter.PhotoImage(file=os.path.join(absfile,"green_light.png"))
jinzhi_image=tkinter.PhotoImage(file=os.path.join(absfile,"jinzhi.PNG"))
wu_image=tkinter.PhotoImage(os.path.join(absfile,"wu.PNG"))

hongdengfile=f'http://api.nlecloud.com/devices/{shebeiid}/sensors/m_redlight'
huangdengfile=f'http://api.nlecloud.com/devices/{shebeiid}/sensors/m_yellowlight'
greenfile=f'http://api.nlecloud.com/devices/{shebeiid}/sensors/m_greenlight'
rentifile=f'http://api.nlecloud.com/devices/{shebeiid}/sensors/m_body'
baojingdengfile=f'http://api.nlecloud.com/devices/{shebeiid}/sensors/m_alarm'


def huoqudata(file):
    breakdata = requests.get(file, headers={"AccessToken": token})
    if breakdata.status_code == 200:
        breakdatavalue = breakdata.json()
        datavalue = breakdatavalue["ResultObj"]["Value"]
        if datavalue == '':
            return 0
        return int(datavalue)
while(1):
    denglu = requests.post(url=login_url, data=baoticanshu)
    if denglu.status_code == 200:
        breakvalue = denglu.json()
        token = breakvalue["ResultObj"]["AccessToken"]
    hondengdata=huoqudata(hongdengfile)
    greendata=huoqudata(greenfile)
    huangdengdata=huoqudata(huangdengfile)
    rentidata=huoqudata(rentifile)
    baojingopen = f'http://api.nlecloud.com/Cmds?deviceId={shebeiid}&apiTag=m_alarm'
    if hondengdata==1 and rentidata==1:
        image_show.configure(image=jinzhi_image)
        requests.post(baojingopen,json=1,headers={"AccessToken":token})
    elif hondengdata==1 and rentidata==0 :
        image_show.configure(image=red_image)
        requests.post(baojingdengfile, json=0, headers={"AccessToken": token})
    elif huangdengdata==1:
        image_show.configure(image=wu_image)
        requests.post(baojingopen, json=0, headers={"AccessToken": token})
    elif greendata==1:
        image_show.configure(image=green_image)
        requests.post(baojingopen, json=0, headers={"AccessToken": token})
    else:
        image_show.configure(image=wu_image)
        requests.post(baojingopen, json=0, headers={"AccessToken": token})
    baojingdata=huoqudata(baojingdengfile)
    if(baojingdata==1):
        print("报警灯打开")
    else:
        print("报警灯关闭")

    if hondengdata==1:
        print("红灯打开")
    else:
        print("红灯关闭")
    if greendata==1:
        print("绿灯打开")
    else:
        print("绿灯关闭")
    if huangdengdata==1:
        print("黄灯打开")
    else:
        print("黄灯关闭")
    if(rentidata==1):
        print("有人")
    else:
        print("无人")
    window.update_idletasks()
    window.update()
    time.sleep(10)
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值