示例#1
0
    def _flushOW(self):
        '''
        Flush and stop connection to owServer
        '''
        # Logger
        localLog = logging.getLogger(self.logPath + "._flushOW")
        localLog.debug("Stoping owServer...")

        ow.finish()
示例#2
0
 def do_reset(self):
     logger.debug("Invoked reset of 1W master")
     try:
         with ModbusClient('127.0.0.1') as client: # Send request to local unipi-tcp in simple sync mode
             ret = client.write_coil(1001, True, unit=1)
             time.sleep(0.2)
             ret = client.write_coil(1001, False, unit=1)
         ow.finish()
         time.sleep(0.05)
         ow.init(self.bus)
     except (ConnectionException):
         pass
示例#3
0
def report_state():
	ow.init('localhost:4304')

	sensorlist = ow.Sensor('/').sensorList()
	for sensor in sensorlist:
		print('Device Found')
		print('Address: ' + sensor.address)
		print('Family: ' + sensor.family)
    	print('ID: ' + sensor.id)
    	print('Type: ' + sensor.type)
    	print(' ')
	ow.finish()
示例#4
0
def handle_time_event():
    global l_first_run

    if not l_first_run:
        
        global l_cnt_1
        global l_cnt_2
        global l_cnt_3
        global l_millis
        l_cnt_1_last = l_cnt_1
        l_cnt_2_last = l_cnt_2
        l_cnt_3_last = l_cnt_3
        l_millis_last = l_millis

        ow.init('localhost:4304')
        l_cnt_1 = int(ow.Sensor( '/1D6CEC0C00000094').counter_A)
        l_cnt_2 = int(ow.Sensor( '/1D00FD0C0000009B').counter_A)
        l_cnt_3 = int(ow.Sensor( '/1D00FD0C0000009B').counter_B)

        
        l_millis = milliseconds()
        interval_millis = l_millis - l_millis_last

        # P(w) = (3600 / T(s)) / ppwh
        # watt = (3600000 / ((interval_millis / interval_count)) / 1) or 0.8
        try:
            watt_total = ( 3600000 / (interval_millis / (l_cnt_1 - l_cnt_1_last))) / 1
        except ZeroDivisionError:
            watt_total = 0 
        try:
            watt_heater = ( 3600000 / (interval_millis / (l_cnt_2 - l_cnt_2_last))) / 0.8
        except ZeroDivisionError:
            watt_heater = 0 
        try:
            watt_ftx = ( 3600000 / (interval_millis / (l_cnt_3 - l_cnt_3_last))) / 1
        except ZeroDivisionError:
            watt_ftx = 0 
        
        watt_household = watt_total - (watt_ftx + watt_heater)

        ow.finish()
        logmsg("Pulses total={}, Pulses heater={}  Pulses FTX={},  Millis={}".format((l_cnt_1 - l_cnt_1_last), (l_cnt_2 - l_cnt_2_last), (l_cnt_3 - l_cnt_3_last), interval_millis))
        json_body = [
        {
            "measurement": "power_total",
            "tags": {
                "dev_id": "1D6CEC0C00000094",
                "instance": "counter.A"
            },
            "fields": {
                "watt": round(watt_total,2)
            }
        },
        {
            "measurement": "power_heater",
            "tags": {
                "dev_id": "1D00FD0C0000009B",
                "instance": "counter.A"
            },
            "fields": {
                "watt": round(watt_heater,2)
            }
        },
        {
            "measurement": "power_ftx",
            "tags": {
                "dev_id": "1D00FD0C0000009B",
                "instance": "counter.A"
            },
            "fields": {
                "watt": round(watt_ftx,2)
            }
        },
        {
            "measurement": "power_household",
            "tags": {
                "dev_id": "calculated",
                "instance": "1"
            },
            "fields": {
                "watt": round(watt_household,2)
            }
        }
        ]
        insert_row(json_body)
        if l_mqtt:
            
            message = []
            message.append({'topic':"power/meter/total/current",
                            'payload': "{}".format(str(round(watt_total,2))),
                            'qos':2})
            message.append({'topic':"power/meter/heater/current", 
                            'payload': "{}".format(str(round(watt_heater,2))),
                            'qos':2})
            message.append({'topic':"power/meter/ftx/current", 
                            'payload': "{}".format(str(round(watt_ftx,2))),
                            'qos':2})
            message.append({'topic':"power/meter/house_hold/current", 
                            'payload': "{}".format(str(round(watt_household,2))),
                            'qos':2})
            
            publish_message(message)

    else:
        l_first_run = False
        ow.init('localhost:4304')
        l_cnt_1 = int(ow.Sensor( '/1D6CEC0C00000094').counter_A)
        l_cnt_2 = int(ow.Sensor( '/1D00FD0C0000009B').counter_A)
        l_cnt_3 = int(ow.Sensor( '/1D00FD0C0000009B').counter_B)
        ow.finish()
示例#5
0
#!/usr/bin/python

import ow
import eeml

# parameters
API_KEY = "4v8OWsHw-K6NI2srUZ2j3Mg7CfaSAKxqS0x4bjV2cmp6VT0g"
API_URL = "/v2/feeds/82543.xml"

# 1-wire sensors
ow.use_logging = True
ow.init("/dev/ttyUSB0")
sensors = ow.Sensor("/").sensorList()
#print sensors
s1 = ow.Sensor("/28.0EA745020000")
#print s1.entryList()
sensor_temp_1 = float(s1.temperature.strip())
ow.finish()
# print "Sensor Temperature: %s" % temperature
cpu_temp = float(
    int(open("/sys/class/thermal/thermal_zone0/temp", "r").read()) / 1000)
# print "CPU Temperature: %s" % cpu_temp
pac = eeml.Cosm(API_URL, API_KEY)
pac.update([
    eeml.Data(0, sensor_temp_1, unit=eeml.Celsius()),
    eeml.Data(1, cpu_temp, unit=eeml.Celsius())
])
pac.put()
示例#6
0
 def finish(self):
     import ow as owbinding
     try:
         owbinding.finish()
     except owbinding.exError as e:
         raise OWError(e)
示例#7
0
文件: owfs.py 项目: hoetzgit/hesweewx
 def shutDown(self):
     ow.finish()
示例#8
0
文件: owfs.py 项目: hoetzgit/hesweewx
 def closePort(self):
     ow.finish()
示例#9
0
#!/usr/bin/python

import ow
import eeml

# parameters
API_KEY = "4v8OWsHw-K6NI2srUZ2j3Mg7CfaSAKxqS0x4bjV2cmp6VT0g"
API_URL = "/v2/feeds/82543.xml"

# 1-wire sensors
ow.use_logging = True
ow.init("/dev/ttyUSB0")
sensors = ow.Sensor("/").sensorList()
#print sensors
s1 = ow.Sensor("/28.0EA745020000")
#print s1.entryList()
sensor_temp_1 = float(s1.temperature.strip())
ow.finish()
# print "Sensor Temperature: %s" % temperature
cpu_temp = float(int(open("/sys/class/thermal/thermal_zone0/temp", "r").read())/1000)
# print "CPU Temperature: %s" % cpu_temp
pac = eeml.Cosm(API_URL, API_KEY)
pac.update([eeml.Data(0, sensor_temp_1, unit=eeml.Celsius()), eeml.Data(1, cpu_temp, unit=eeml.Celsius())])
pac.put()