RECO RP200智能插座通过PYTHON脚本获取电压、电流、功率等

用于监测电、气、水等的装置
回复
jhxiaotao
帖子: 3
注册时间: 周五 10月 27, 2017 16:19

RECO RP200智能插座通过PYTHON脚本获取电压、电流、功率等

帖子 jhxiaotao »

RECO RP200智能插座通过PYTHON脚本获取电压、电流、功率等
插座介绍http://www.reco4life.com/bbs/portal.php 自己看去或者百度
代码有点乱,根据论坛里的脚本和官方的API修改拼凑来

代码: 全选

#!/usr/bin/env python  
# -*- coding:utf-8 -*-
#ECO 智能插座PYTHON控制
from socket import *
import time
import datetime
import urllib
import urllib2
import re

#Domoticz服务器
domoticzserver = "127.0.0.1:8084"
#定义设备idx值
Current_idx = "32"
Voltage_idx = "33"
Electric_idx = "34"

#此方法向Domoticz服务器发送请求
def domoticzrequest (url):
    request = urllib2.Request(url)
    response = urllib2.urlopen(request)
    return response.read()
    
HOST = '192.168.100.108'
PORT = 8899
BUFSIZ = 1024
ADDR = (HOST, PORT)
tcpCliSock = socket(AF_INET, SOCK_STREAM)
tcpCliSock.connect(ADDR)
data2 = "AT+YZOUT" + '\r' + '\n'
tcpCliSock.send(data2)
data1 = tcpCliSock.recv(BUFSIZ)
#print data1
tcpCliSock.close()
#截取返回值从第5位开始
data1 = data1[4:]
#去除返回值尾部无用数据
data1 = data1.strip()
#把返回以,区分 存入序列
list_data1 = data1.split(',')
#读取序列
num1 = list_data1[0]
num2 = list_data1[1]
num3 = list_data1[2]
num4 = list_data1[3]
num5 = list_data1[4]
num6 = list_data1[6]
#print('list:{0},num1:{1}'.format(list_data1,num1))
dianliu = float(num1) / 100
print "当前电流为:%.2f" %dianliu + "A"
#改变变量类型
Current = str(dianliu)
print Current
dianya = float(num2) / 100
print "当前电压为:%.2f" %dianya + "V"
Voltage = str(dianya)
print Voltage
pinlv = float(num3) / 100

print "当前频率为:%.2f" %pinlv + "Hz"
gonglv = float(num4) / 10
Electric = str(gonglv)
print "当前功率为:%.2f" %gonglv + "W"
print Electric
nengliang = float(num6) / 1
print "当前功率为:%.2f" %nengliang + "WH"
#通过-连接字符串
#str_list = ('-').join(list_data1)
#print('str_list:{0}'.format(str_list))

domoticzrequest("http://"+domoticzserver+"/json.htm?type=command&param=udevice&idx="+Current_idx+"&nvalue=0&svalue="+Current)
domoticzrequest("http://"+domoticzserver+"/json.htm?type=command&param=udevice&idx="+Voltage_idx+"&nvalue=0&svalue="+Voltage)
domoticzrequest("http://"+domoticzserver+"/json.htm?type=command&param=udevice&idx="+Electric_idx+"&nvalue=0&svalue="+Electric)

后面这个是开关控制:

代码: 全选

#!/usr/bin/env python  
# -*- coding: utf-8 -*-  
#RECO 智能插座PYTHON控制
from socket import *
import time
import datetime

HOST = '192.168.100.108'
PORT = 8899
BUFSIZ = 1024
ADDR = (HOST, PORT)
nowtime = time.strftime('%Y%m%d%H%M%S', time.localtime(time.time()))
tcpCliSock = socket(AF_INET, SOCK_STREAM)
tcpCliSock.connect(ADDR)
data2 = "AT+YZSWITCH=1,ON," + nowtime
#关闭的话把ON改OFFdata2 = "AT+YZSWITCH=1,OFF," + nowtime
tcpCliSock.send(data2)
data1 = tcpCliSock.recv(BUFSIZ)
print data1
tcpCliSock.close()
附件
显示效果
显示效果
63060a17e6b51219183af88f8185838d.png (104.45 KiB) 查看 12316 次
显示效果
显示效果
2090321f61cf4881528211013b623a3e.png (65.74 KiB) 查看 12316 次
blindlight
帖子: 98
注册时间: 周四 3月 30, 2017 00:03

Re: RECO RP200智能插座通过PYTHON脚本获取电压、电流、功率等

帖子 blindlight »

厉害厉害 怎么破解的是
头像
DT27
帖子: 345
注册时间: 周四 3月 30, 2017 08:54
Gender:

Re: RECO RP200智能插座通过PYTHON脚本获取电压、电流、功率等

帖子 DT27 »

blindlight 写了: 周六 10月 28, 2017 20:13 厉害厉害 怎么破解的是
官方开放了api
jhxiaotao
帖子: 3
注册时间: 周五 10月 27, 2017 16:19

Re: RECO RP200智能插座通过PYTHON脚本获取电压、电流、功率等

帖子 jhxiaotao »

是的。。API官方论坛里有的下载。
回复