コード例 #1
0
    def Get_RPM():  # IO.RPI_Handler.ReadInfrared() calls this
        # Getting RPM
        global total_rpm
        if System.timer_flag: Max_Power_Wind.Avg_RPM(total_rpm)
        else:
            total_rpm = total_rpm + 1
            print("total_rpm = {}".format(total_rpm))
            Log_Handler.Write_Log(
                os.path.basename(__file__) +
                " total_rpm = {}\n".format(total_rpm))

        Max_Power_Wind.Avg_RPM(total_rpm)
コード例 #2
0
 def Get_Solar_Power():
     global total_solar_pwr
     solar_current = 0
     solar_voltage = 0
     total_solar_pwr = 0
     while True:
         if System.timer_flag: break
         time.sleep(System.delay)
         solar_current = IO.Random_IO.SOLAR_CURR_listener()
         solar_voltage = IO.Random_IO.SOLAR_VOLT_listener()
         total_solar_pwr = (solar_current * solar_voltage) + total_solar_pwr
         Log_Handler.Write_Log(
             os.path.basename(__file__) +
             "solar curr, solar volt, and total solar power calculated\n")
コード例 #3
0
    def Get_RPM():
        # Getting RPM
        global total_rpm
        if System.timer_flag:
            Max_Power_Wind.Avg_RPM(total_rpm)
            # If the timer is up, calculate the avg rpm
        else:  # if a key was pressed, increment
            total_rpm = total_rpm + 1
            print("total_rpm = {}".format(total_rpm))
            Log_Handler.Write_Log(
                os.path.basename(__file__) +
                "total_rpm = {}\n".format(total_rpm))

        Max_Power_Wind.Avg_RPM(total_rpm)
コード例 #4
0
def do(i):
    ## Sub calculations for Wind Power
    print("\nAverage RPM: ", Average_RPM_Wind)
    print("\n")
    Log_Handler.Write_Log(
        os.path.basename(__file__) +
        "\nAverage RPM: {} \n".format(Average_RPM_Wind))
    print("\nAverage Torque: ", Average_TORQUE_Wind)
    print("\n")
    Log_Handler.Write_Log(
        os.path.basename(__file__) +
        "\nAverage Torque: {} \n".format(Average_TORQUE_Wind))

    # Getting Average Power per minute
    Max_Power_Wind.Avg_Pwr(Average_TORQUE_Wind, Average_RPM_Wind)
    # This needs to be called from the main
    print("\nAverage Power per minute for WIND: ", Average_POWER_WIND)
    print("\n")
    Log_Handler.Write_Log(
        os.path.basename(__file__) +
        "\nAverage Power per minute for WIND: {} \n".format(Average_POWER_WIND)
    )
    Max_Power_Solar.Avg_Pwr(total_solar_pwr)
    # Get's the total solar power and gets its average across a minute
    print("\nAverage Power per minute for SOLAR: ", Average_POWER_SOLAR)
    print("\n")
    Log_Handler.Write_Log(
        os.path.basename(__file__) +
        "\nAverage Power per minute for SOLAR: \n".format(Average_POWER_SOLAR))

    # Writes data into the file
    File_Handler.Inject_Data(Average_POWER_WIND, Average_POWER_SOLAR)
    # doesn't write an extra line
    print("\n Total lines in file: {} \n".format(i + 1))
    Log_Handler.Write_Log(
        os.path.basename(__file__) +
        "\n Total lines in file: {} \n".format(i + 1))
コード例 #5
0
 def Get_Solar_Power():
     global total_solar_pwr
     solar_current = 0
     solar_voltage = 0
     total_solar_pwr = 0
     while True:
         if System.timer_flag: break
         time.sleep(1)
         solar_voltage = RPI_Handler.ReadIO(
             MaxPower_ClassesXML.int("SolarVoltagePort"))
         # Voltage
         solar_current = Max_Power_Solar.CalculateCurrent()
         print("\nSolar Voltage = {}\n".format(solar_voltage))
         print("\nSolar Current = {}\n".format(solar_current))
         total_solar_pwr = (solar_current * solar_voltage) + total_solar_pwr
         Log_Handler.Write_Log(
             os.path.basename(__file__) +
             " solar curr, solar volt, and total solar power calculated\n")
コード例 #6
0
    def Get_Torque():
        total_torque = 0
        # Getting Torque
        while True:
            if System.timer_flag: break
            time.sleep(System.delay)
            # Will execute equation after one second passes
            force_of_the_blades = IO.Random_IO.BLADE_FORCE_listener()
            # simulating a analog read of the torque
            # Random is temporary, we will read real values
            num = radius_of_the_blades * force_of_the_blades * math.sin(
                angle_of_the_blades)
            total_torque = total_torque + num
            print("total_torque = {} ".format(total_torque))
            Log_Handler.Write_Log(
                os.path.basename(__file__) +
                "total_torque = {} \n".format(total_torque))

        Max_Power_Wind.Avg_Torque(total_torque)
コード例 #7
0
 def Avg_Pwr(solar_power):
     global Average_POWER_SOLAR
     Average_POWER_SOLAR = solar_power / System.Seconds
     Log_Handler.Write_Log(
         os.path.basename(__file__) + "Avg Pwr Solar calculated\n")
コード例 #8
0
 def Avg_RPM(Total_RPM):
     global Average_RPM_Wind
     Average_RPM_Wind = Total_RPM / System.Seconds
     Log_Handler.Write_Log(
         os.path.basename(__file__) + "Avg RPM Wind calculated\n")
コード例 #9
0
 def Avg_Torque(Total_Torque):
     global Average_TORQUE_Wind
     Average_TORQUE_Wind = Total_Torque / System.Seconds
     Log_Handler.Write_Log(
         os.path.basename(__file__) + "Avg Torque Wind calculated\n")
コード例 #10
0
 def Avg_Pwr(Torque, RPM):  # This gets called from main.py
     global Average_POWER_WIND
     Average_POWER_WIND = (Torque * RPM * math.pi) / 30
     Log_Handler.Write_Log(
         os.path.basename(__file__) + "Avg Pwr Wind calculated\n")
コード例 #11
0
Sender = FTP()

# Init
System.init()
MaxPower_Classes.init()
IO.RPI_Handler.init(IO.RPI_Handler)

# Main loop
while True:
    try:
        # .csv
        if File_Handler.Init_File(): print("Error making file \n")
        else: print("Success created file \n")

        # .log
        if Log_Handler.Init_File(): print("Error making log \n")
        else: print("Success making log \n")

        print("Entering loop\n")

        i = 0
        while i < System.MaxLines:

            ThreadFunctions.do()
            # Threads

            MaxPower_Classes.do(i)
            # Functions for max power
            i = i + 1

        # Closes and saves file
コード例 #12
0
ファイル: FTP.py プロジェクト: bopopescu/DualPowerGeneration
    def send():
        # POWERSHELL
        if type == 'powershell':
            try:
                file = file_basename + '.ps1'
                p = subprocess.Popen(["powershell.exe", "{}".format(file)],
                                     stdout=sys.stdout)
                p.communicate()
                Log_Handler.Write_Log(
                    os.path.basename(__file__) + "\n Sent file\n")
            except Exception as ex:
                print(ex)
                print("File not sent through ftp")
                Log_Handler.Write_Log(
                    os.path.basename(__file__) + "\n\n" + ex +
                    "\n\n File not sent through powershell\n")

        # BATCH
        elif type == 'batch':
            file = file_basename + '.bat'
            try:
                os.system('cmd /c {}'.format(file))
                Log_Handler.Write_Log(
                    os.path.basename(__file__) + "\n Sent file\n")
            except Exception as ex:
                print(ex)
                print("File not sent through ftp")
                Log_Handler.Write_Log(
                    os.path.basename(__file__) + "\n\n" + ex +
                    "\n\n File not sent through batch\n")

        # COMMAND PROMPT
        elif type == 'commandline':
            file = file_basename + '.cmd'
            try:
                os.system('cmd /c {}'.format(file))
                Log_Handler.Write_Log(
                    os.path.basename(__file__) + "\n Sent file\n")
            except Exception as ex:
                print(ex)
                print("File not sent through ftp")
                Log_Handler.Write_Log(
                    os.path.basename(__file__) + "\n\n" + ex +
                    "\n\n File not sent through cmd\n")

        # PYTHON
        elif type == 'python':
            try:
                cnopts = pysftp.CnOpts()
                cnopts.hostkeys = None

                # Establish connection
                with pysftp.Connection(
                        host=Hostname,
                        username=Username,
                        password=Password,
                        cnopts=cnopts,
                        private_key=PrivateKey
                ) as sftp:  # temporarily chdir to allcode
                    dest = DestinationDir + Files.filename.replace("\\", "/")
                    sftp.put(Files.fullpath, dest)
                    # upload file to allcode/pycode on remote

                Log_Handler.Write_Log(
                    os.path.basename(__file__) + "\n Sent file\n")
            except Exception as ex:
                print(ex)
                print(
                    "File not sent through ftp.  Check if folder exists on remote server."
                )
                print(
                    "\nThe error can be traced back with the following stack trace"
                )
                track = traceback.format_exc()
                print(track)
                Log_Handler.Write_Log(
                    os.path.basename(__file__) + "\n\n" + str(ex) +
                    "\n\n File not sent through cmd\n\n" + str(track))
        elif type == 'redirect':
            # The issue is that I do not think I can send ftp files directly to cpanel from rpi
            # Figuring this out but making this just in case
            # Made ps1 script but not pushing since it has sensitive data
            print("Configured to use redirect.")
            time.sleep(NoFTPSleep)
        else:
            print(
                "FTP procedure not defined.  (Please check configuration on MaxPower.xml)"
            )