Ejemplo n.º 1
0
from pymodbus.constants import Endian
from pymodbus.payload import BinaryPayloadDecoder
import asyncio
import logging
import csv

# IP address of the smart meter
meter_1_IP = "192.168.0.116"
meter_2_IP = "192.168.0.80"


async def main(meter_1, meter_2):
    file_name = "results/thread_two_result.csv"
    with open(file_name, mode='a') as csv_file:
        csv_writer = csv.writer(csv_file,
                                delimiter=',',
                                quotechar='"',
                                quoting=csv.QUOTE_MINIMAL)
        print("Executing thread two event loop")
        while True:
            await meter_1.read_all(csv_writer)
            await meter_2.read_all(csv_writer)


loop = asyncio.get_event_loop()
loop, client1 = ModbusClient(schedulers.ASYNC_IO, host=meter_1_IP, loop=loop)
loop, client2 = ModbusClient(schedulers.ASYNC_IO, host=meter_2_IP, loop=loop)
meter_1 = smart_meter(meter_1_IP, client1)
meter_2 = smart_meter(meter_2_IP, client2)
loop.create_task(main(meter_1, meter_2))
loop.run_forever()
from openHAB_Proj import MySQL
from pymodbus.client.asynchronous.tcp import AsyncModbusTCPClient as ModbusClient
from pymodbus.client.asynchronous import schedulers
import asyncio
import csv

meter_2_IP = '192.168.0.80'


async def main(meter):
    print("Executing meter_2 event loop")
    with open('results/meter_2.csv', mode='a') as csv_file:
        csv_writer = csv.writer(csv_file,
                                delimiter=',',
                                quotechar='"',
                                quoting=csv.QUOTE_MINIMAL)
        while True:
            if 'conn' not in locals():
                print(
                    "Creating connection to database using MySQL.connect() function"
                )
                conn = await MySQL.connect()
            await MySQL.query_all_values(conn, meter.IP, csv_writer)


loop = asyncio.get_event_loop()
loop, client = ModbusClient(schedulers.ASYNC_IO, host=meter_2_IP, loop=loop)
meter_2 = smart_meter(meter_2_IP, client)
loop.create_task(main(meter_2))
loop.run_forever()
Ejemplo n.º 3
0
# sys               - Used to add the path of the openHAB Package
# smart_meter       - Class used to read the smart meters currently configured
# JSON              - Used to read the config.json file
# AeotechZW096      - Class for the smart plugs being used   
import sys
sys.path.append(r'/home/openhabian/Environments/env_1/openHAB_Proj/')
from openHAB_Proj.smart_meters import smart_meter
from pymodbus.client.asynchronous.tcp import AsyncModbusTCPClient as ModbusClient
from pymodbus.client.asynchronous import schedulers
from pymodbus.constants import Endian
from pymodbus.payload import BinaryPayloadDecoder
import asyncio
import logging 
import csv

# IP address of the smart meter 
meter_IP = "192.168.0.116"

async def main(meter):
    file_name = "results/thread_five_result.csv"
    with open(file_name, mode='a') as csv_file:
        csv_writer = csv.writer(csv_file, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
        print("Executing thread five event loop")
        while True:
            await meter.read_all(csv_writer)

loop = asyncio.get_event_loop()
loop, client = ModbusClient(schedulers.ASYNC_IO,host =meter_IP, loop=loop)
meter = smart_meter(meter_IP,client)
loop.create_task(main(meter))
loop.run_forever()
# sys               - Used to add the path of the openHAB Package
# smart_meter       - Class used to read the smart meters currently configured
# JSON              - Used to read the config.json file
# AeotechZW096      - Class for the smart plugs being used   
import sys
sys.path.append(r'/home/openhabian/Environments/env_1/openHAB_Proj/')
from openHAB_Proj.smart_meters import smart_meter
from openHAB_Proj import MySQL
from pymodbus.client.asynchronous.tcp import AsyncModbusTCPClient as ModbusClient
from pymodbus.client.asynchronous import schedulers
import asyncio

meter_1_IP = '192.168.0.116'
async def main(meter):
        print("Executing meter_1 event loop")
        while True:
            if 'conn' not in locals():
                print("Creating connection to database using MySQL.connect() function")
                conn = await MySQL.connect()  
            await meter.read_all(conn)


loop = asyncio.get_event_loop()
loop, client = ModbusClient(schedulers.ASYNC_IO,host =meter_1_IP, loop=loop)
meter_1 = smart_meter(meter_1_IP,client)
loop.create_task(main(meter_1))
loop.run_forever()