Status Beacon


import argparse
import subprocess #carrier



#import os

from epevermodbus.driver import EpeverChargeController


def main():

    #Carrier Detect
    tmobile = '192.168.0.1'
    starlink = '192.168.100.1'
    
    tmo = subprocess.run(['ping', '-c', '1', '-W', '1', tmobile], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
    sl = subprocess.run(['ping', '-c', '1', '-W', '1', starlink], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
    #End
    
    parser = argparse.ArgumentParser()
    parser.add_argument(
        "--portname", help="", default="/dev/ttyUSB0"
    )
    parser.add_argument(
        "--slaveaddress", help="Slave address 1-247", default=1, type=int
    )
    args = parser.parse_args()

    controller = EpeverChargeController(args.portname, args.slaveaddress)
    
    fault = (controller.get_battery_fault())
    status = (controller.get_charge_status())
    load = (controller.get_load_status())
    
    current = (controller.get_real_battery_current())
    current = float("%0.1f" % (current))
    battery = (controller.get_battery_voltage())
    battery = float("%0.2f" % (battery))
    solarvolt = (controller.get_solar_voltage())
    watts = (battery * current)
    watts = float("%0.0f" % (watts))
    temp = (controller.get_battery_temperature())
    if temp > 500:
        temp = temp - 655.35
    temp = (temp * 9 / 5 + 32)
    temp = float("%0.0f" % (temp))
    maxvolt = (controller.get_maximum_battery_voltage_today())
    maxvolt = float("%0.2f" % (maxvolt))
    minvolt = (controller.get_minimum_battery_voltage_today())
    minvolt = float("%0.2f" % (minvolt))
    watthour = (controller.get_watt_hour_today())
    soc = (controller.get_battery_state_of_charge())

    print (battery,"v",sep="")
#   print (current,"A",sep="")
    print (f'{current:g}A')
    print (f'{watts:g}W')
    print (f'{temp:g}F')
    #print ("L:",minvolt,"/H:",maxvolt,sep="")
    print ("(",minvolt,"/",maxvolt,")",sep="")
    print (f'{watthour:g}Wh')
    print (f'{soc:g}%')
    
    
    if status == 1:
        print("0")
    elif status == 7:
        print ("F")
    elif status == 11:
        print ("B")
    else: 
        print ("?")
        
    if load == 1:
        print ("L1")
    elif load == 0:
        print ("L0")
    else: 
        print ("L?")
    
    #Carrier Detect
    if sl.returncode == 0:
        print(f"S")
    elif tmo.returncode == 0:
        print(f"T")
    else:
        print (f"U")
    #End
   

if __name__ == "__main__":
    main()

#os.system("python /home/pi/stat.py")    
  
exit