def get_tasks(): api = SixfabPower() return jsonify({ "input": { "temp": get_input_temp(api), "voltage": get_input_voltage(api), "current": get_input_current(api), "power": get_input_power(api) }, "system": { #"temp": get_system_temp(api), "voltage": get_system_voltage(api), "current": get_system_current(api), "power": get_system_power(api) }, "battery": { "temp": get_battery_temp(api), "voltage": get_battery_voltage(api), "current": get_battery_current(api), "power": get_battery_power(api), "level": get_battery_level(api), "health": get_battery_health(api) }, "fan": { 'health': get_fan_health(api), 'speed': get_fan_speed(api) } })
#!/usr/bin/env python3 from power_api import SixfabPower, Definition, Event import time api = SixfabPower() api.reset_mcu()
from power_api import SixfabPower, Definition, Event import time api = SixfabPower() #print( "Return: " + str(api.set_lpm_status(2))) print("LPM: " + str(api.get_lpm_status())) #print( "Battery Temp: " + str(api.get_battery_temp_qwiic())) #print( "Return: " + str(api.set_watchdog_status(2))) print("WDT Status: " + str(api.get_watchdog_status())) #print( "Return: " + str(api.set_watchdog_interval(2))) print("WDT Interval: " + str(api.get_watchdog_interval())) #print( "Return: " + str(api.set_fan_mode(2))) print("Fan Mode: " + str(api.get_fan_mode())) #print( "Return: " + str(api.set_battery_separation_status(1))) print("Battery Separation: " + str(api.get_battery_separation_status())) #print( "Return: " + str(api.set_rgb_animation(2,7,3))) print("RGB Anim: " + str(api.get_rgb_animation())) #print( "Return: " + str(api.set_fan_automation(50))) #print( "Return: " + str(api.set_power_outage_event_status(1))) print("POWER OUT. STAT: " + str(api.get_power_outage_event_status())) #print( "Return: " + str(api.set_power_outage_params(5,30)))
#!/usr/bin/env python3 from power_api import SixfabPower, Definition, Event import time api = SixfabPower() epoch = time.time() # to get timestamp in seconds in GMT0 # to get local time on raspberry pi localtime = time.asctime( time.localtime(time.time()) ) print("Local current time :", localtime) # to get timezone difference as minus print(time.timezone) # standard epoch time with no location specific print("Epoch Time: " + str(int(epoch))) # to calculate epoch with respect to local time # use it for set_rtc_time() function as timestamp (epoch - time.timezone) print("Epoch Local: " + str(int(epoch) - time.timezone + 3600)) print("Result: " + str(api.set_rtc_time(int(epoch) - time.timezone + 3600))) print("RTC Time: " + str(api.get_rtc_time(Definition.TIME_FORMAT_EPOCH))) print("RTC Time: " + str(api.get_rtc_time(Definition.TIME_FORMAT_DATE_AND_TIME)))
#!/usr/bin/env python3 from power_api import SixfabPower, Definition import time import sys, os api = SixfabPower() firmware_path = "/opt/b0x/sixfab_pms_firmware_v0.3.3.bin" error_occured = 0 try: api.reset_mcu() api.reset_for_boot_update() time.sleep(5) for step in api.update_firmware(firmware_path): print(f"{step}%") except: error_occured = 1 print("raised error") finally: update_successful = 0 if error_occured is 0: counter = 0 for i in range(15): print('.', sep=' ', end=' ', flush=True) time.sleep(1)
#!/usr/bin/env python3 from power_api import SixfabPower, Definition, Event import time api = SixfabPower() api.reset_for_boot_update()
#!/usr/bin/env python3 from power_api import SixfabPower, Event, Definition import time api = SixfabPower() print("\r\n") print("************* Fan **************") print("Fan Health: " + str(api.get_fan_health())) print("set Fan Mode: " + str(api.set_fan_mode(3, 10))) print("get Fan Mode: " + str(api.get_fan_mode())) print("get Fan Speed: " + str(api.get_fan_speed(10))) print("set Fan Automation Result: " + str(api.set_fan_automation(20, 60, 10))) print("get Fan Automation: " + str(api.get_fan_automation(10))) print("\r\n") print("************* Others **************") #print("Setting Watchdog Status: " + str(api.set_watchdog_status(1))) #print("Getting Watchdog Status: " + str(api.get_watchdog_status())) print("set RGB Animation.: " + str( api.set_rgb_animation(Definition.RGB_DISABLED, Definition.BLUE, Definition.RGB_SLOW, 10))) print("get RGB Animation Status.: " + str(api.get_rgb_animation(10))) print("set Result Bat. Max Char. Level: " + str(api.set_battery_max_charge_level(80, 10))) print("get Bat. Max Char. Level: " + str(api.get_battery_max_charge_level(10))) print("set Result Safe Shutdown Bat Lev.: " + str(api.set_safe_shutdown_battery_level(40, 10))) print("get Safe Shutdown Bat Lev.: " + str(api.get_safe_shutdown_battery_level(10))) print("set Result Safe Shutdown Bat Status.: " +
def update_firmware(**kwargs): token = kwargs.get("token") remote_repository = kwargs.get("repository", None) mqtt_client = kwargs.get("mqtt_client", None) experimental_enabled = kwargs.get("experimental_enabled", False) def send_status(status): mqtt_client.publish( f"/device/{token}/hive", json.dumps({ "command": "update_status_firmware", "status": status })) send_status("git") if os.path.exists(LOCAL_FIRMWARE_FOLDER): os.system( f"cd {LOCAL_FIRMWARE_FOLDER} {'&& sudo git fetch && sudo git checkout dev' if experimental_enabled else ''} && sudo git pull" ) else: os.system( f"sudo git clone {remote_repository} {LOCAL_FIRMWARE_FOLDER} {'&& sudo git fetch && sudo git checkout dev' if experimental_enabled else ''}" ) latest_version = open( f"{LOCAL_FIRMWARE_FOLDER}/latest_version").read().strip() latest_firmware = f"{LOCAL_FIRMWARE_FOLDER}/sixfab_pms_firmware_{latest_version}.bin" try: current_firmware_version = get_metric("version") except: send_status("error") return #if current_firmware_version == latest_version[1:]: # send_status("finish") # return if not lock_distribution_service(): send_status("error") return if not os.path.exists(latest_firmware): send_status("firmware_not_exists") return hat_api = SixfabPower() try: last_step_cache = 0 for step in hat_api.update_firmware(latest_firmware): if last_step_cache < 100 and step - last_step_cache > 2: last_step_cache = step send_status(step) except: send_status("error") return send_status("finish") release_distribution_service()
#!/usr/bin/env python3 from power_api import SixfabPower, Definition, Event import time api = SixfabPower() print("Hard Pwr-Off set: " + str( api.create_scheduled_event( 2, Definition.EVENT_INTERVAL, Definition.EVENT_ONE_SHOT, 30, Definition.INTERVAL_TYPE_SEC, 0, Definition.HARD_REBOOT, 500)))
from power_api import SixfabPower, Definition, Event import time api = SixfabPower() print("Battery Max Level: " + str(api.get_battery_max_charge_level())) print("Battery Safe Level: " + str(api.get_safe_shutdown_battery_level())) print("Battery Safe Status: " + str(api.get_safe_shutdown_status())) print("Battery Design Cap: " + str(api.get_battery_design_capacity())) #print( "Return: " + str(api.set_lpm_status(2))) print("LPM: " + str(api.get_lpm_status())) #print( "Return: " + str(api.set_watchdog_status(2))) print("WDT Status: " + str(api.get_watchdog_status())) #print( "Return: " + str(api.set_watchdog_interval(2))) print("WDT Interval: " + str(api.get_watchdog_interval())) #print( "Return: " + str(api.set_fan_mode(2))) print("Fan Mode: " + str(api.get_fan_mode())) #print( "Return: " + str(api.set_battery_separation_status(1))) print("Battery Separation: " + str(api.get_battery_separation_status())) #print( "Return: " + str(api.set_rgb_animation(2,7,3))) print("RGB Anim: " + str(api.get_rgb_animation())) #print( "Return: " + str(api.set_fan_automation(50))) #print( "Return: " + str(api.set_power_outage_event_status(1)))
from power_api import SixfabPower, Definition import time api = SixfabPower() print("************* Input Sensors **************") print("Input Temp: " + str(api.get_input_temp())) print("Input Voltage: " + str(api.get_input_voltage())) print("Input Current: " + str(api.get_input_current())) print("Input Power: " + str(api.get_input_power())) #Required delay #default 50 print("************* System Sensors **************") print("System Temp: " + str(api.get_system_temp())) print("System Voltage: " + str(api.get_system_voltage())) print("System Current: " + str(api.get_system_current())) #Required delay #default 50 print("System Power: " + str(api.get_system_power())) #Required delay #default 50 print("************* Battery **************") print("Battery Temp: " + str(api.get_battery_temp())) print("Battery Voltage: " + str(api.get_battery_voltage())) print("Battery Current: " + str(api.get_battery_current())) print("Battery Power: " + str(api.get_battery_power())) print("Battery Level: " + str(api.get_battery_level())) print("Battery Health: " + str(api.get_battery_health())) print("************* Fan **************") print("Fan Health: " + str(api.get_fan_health())) print("Fan Speed: " + str(api.get_fan_speed()))
# Parameter : uint16 timeOrInterval [exact time[epoch] | EVENT_INTERVAL] # Parameter : uint8 interval_type [INTERVAL_TYPE_SEC, INTERVAL_TYPE_MIN, INTERVAL_TYPE_HOUR] # Parameter : uint8 repeatPeriod [day_factor | EVERYDAY] # Parameter : uint8 action [HARD_POWER_ON, HARD_POWER_OFF, HARD_REBOOT, SOFT_POWER_ON, SOFT_POWER_OFF,SOFT_REBOOT] # Return : result # # day_factor : Calculation of day_factor # [monday] –> Bit 0 [tuesday] –> Bit 1 [wednesday] –> Bit 2 [thursday] –> Bit 3 [friday] –> Bit 4 [saturday] –> Bit 5 [sunday] –> Bit 6 [RESERVED] –> Bit 7 (Default 0) # Example Calculation for every day : day_factor = 0b01111111 = 127 # Example Calculation for (sunday + monday + tuesday) : day_factor = 0b01000011 = 67 # ----------------------------------------------------------- from power_api import SixfabPower, Definition, Event import time api = SixfabPower() epoch = time.time() # Remove all events # ----------------- print("Result removing all Scheduled Event: " + str(api.remove_all_scheduled_events(200))) # set HARD_POWER_ON at 6:30AM everyday # ------------------------------------ # see https://www.epochconverter.com # daily_exact_time formula: epoch_time_local % (24x60x60) # daily_exact_time : # –> Thursday, 30 July 2020 06:30:00 # –> epoch_local = 1596090600 (In this case local : GMT) # –> daily exact_time = 1596090600 % 86400 = 23400
from power_api import SixfabPower, Definition, Event import time api = SixfabPower() """ print( "Return: " + str(api.set_lpm_status(2))) print( "LPM: " + str(api.get_lpm_status())) print( "Return: " + str(api.set_fan_mode(1))) print( "LPM: " + str(api.get_fan_mode())) print( "Battery Temp: " + str(api.get_battery_temp_qwiic())) """ """ print( "Return: " + str(api.set_watchdog_status(2))) print( "WDT Status: " + str(api.get_watchdog_status())) print( "Return: " + str(api.set_watchdog_interval(2))) print( "WDT Interval: " + str(api.get_watchdog_interval())) print( "Return: " + str(api.set_fan_mode(2))) print( "Fan Mode: " + str(api.get_fan_mode())) """ #print( "Return: " + str(api.set_battery_separation_status(1))) #print( "Battery Separation: " + str(api.get_battery_separation_status())) #print( "Battery Separation --> Send battery temp result: " + str(api.send_battery_temp())) """ print( "Return: " + str(api.set_rgb_animation(2,7,3))) print( "RGB Anim: " + str(api.get_rgb_animation()))
#!/usr/bin/env python3 from power_api import SixfabPower, Definition import time api = SixfabPower() print("************* Input Sensors **************") print("Input Temp: " + str(api.get_input_temp())) print("Input Voltage: " + str(api.get_input_voltage())) print("Input Current: " + str(api.get_input_current())) print("Input Power: " + str(api.get_input_power())) #Required delay #default 50 print("************* System Sensors **************") print("System Temp: " + str(api.get_system_temp())) print("System Voltage: " + str(api.get_system_voltage())) print("System Current: " + str(api.get_system_current())) #Required delay #default 50 print("System Power: " + str(api.get_system_power())) #Required delay #default 50 print("************* Battery **************") print("Battery Temp: " + str(api.get_battery_temp())) print("Battery Voltage: " + str(api.get_battery_voltage())) print("Battery Current: " + str(api.get_battery_current())) print("Battery Power: " + str(api.get_battery_power())) print("Battery Level: " + str(api.get_battery_level())) print("Battery Health: " + str(api.get_battery_health())) print("Battery Max Charge Level: " + str(api.get_battery_max_charge_level())) print("Battery Capacity: " + str(api.get_battery_design_capacity())) print("************* Safe Shutdown **************")
from power_api import SixfabPower import time api = SixfabPower() epoch = time.time() # to get timestamp in seconds in GMT0 # to get local time on raspberry pi localtime = time.asctime(time.localtime(time.time())) print("Local current time :", localtime) # to get timezone difference as minus print(time.timezone) # standard epoch time with no location specific print("Epoch Time: " + str(int(epoch))) # to calculate epoch with respect to local time # use it for set_rtc_time() function as timestamp (epoch - time.timezone) print("Epoch Local: " + str(int(epoch) - time.timezone)) print("Result: " + str(api.set_rtc_time(int(epoch) - time.timezone)))
from power_api import SixfabPower, Definition import time pms = SixfabPower() epoch = time.time() print("RTC Time: " + str(pms.get_rtc_time(Definition.TIME_FORMAT_EPOCH))) print("RTC Time: " + str(pms.get_rtc_time(Definition.TIME_FORMAT_DATE_AND_TIME))) print("RTC Time: " + str(pms.get_rtc_time(Definition.TIME_FORMAT_DATE))) print("RTC Time: " + str(pms.get_rtc_time(Definition.TIME_FORMAT_TIME)))
#!/bin/python3 import sys sys.path.append('./') from power_api import SixfabPower, Definition, Event import time api = SixfabPower() #api.reset_mcu() if (not api.get_working_mode()): exit() print("Time: " + str(api.get_rtc_time(Definition.TIME_FORMAT_DATE_AND_TIME))) print(api.get_firmware_ver()) print("************* Input Sensors **************") print("Input Temp: " + str(api.get_input_temp())) print("Input Voltage: " + str(api.get_input_voltage())) print("Input Current: " + str(api.get_input_current())) print("Input Power: " + str(api.get_input_power())) #Required delay #default 50 print("************* System Sensors **************") print("System Temp: " + str(api.get_system_temp())) print("System Voltage: " + str(api.get_system_voltage())) print("System Current: " + str(api.get_system_current())) #Required delay #default 50
from power_api import SixfabPower, Definition, Event import time pms = SixfabPower() epoch = time.time() # Remove all events print("Result removing all Scheduled Event: " + str(pms.remove_all_scheduled_events(200))) # create power off event to power off the device in 20 seconds event = Event() event.id = 1 event.schedule_type = Definition.EVENT_INTERVAL event.repeat = Definition.EVENT_ONE_SHOT event.time_interval = 20 event.interval_type = Definition.INTERVAL_TYPE_SEC event.action = Definition.HARD_POWER_OFF result = pms.create_scheduled_event_with_event(event, 500) print("Create S. Event Result: " + str(result)) print("IDs of Scheduled Events: " + str(pms.get_scheduled_event_ids()))
#!/usr/bin/env python3 from power_api import SixfabPower, Definition, Event import time api = SixfabPower() print("Soft Pwr-Off set: " + str( api.create_scheduled_event(1, Definition.EVENT_INTERVAL, Definition.EVENT_ONE_SHOT, 15, Definition.INTERVAL_TYPE_SEC, 0, 3, 500))) print("Hard Pwr-Off set: " + str( api.create_scheduled_event(2, Definition.EVENT_INTERVAL, Definition.EVENT_ONE_SHOT, 30, Definition.INTERVAL_TYPE_SEC, 0, 2, 500)))
from power_api import SixfabPower, Definition, Event import time import os api = SixfabPower() intiateShutdown = False def main(): global intiateShutdown try: print(api.get_button1_status()) except Exception: print("Exception") while True: try: if (api.get_button1_status() == 1): print("Turning OFF") intiateShutdown = True # print("Soft Pwr-Off set: " + str(api.create_scheduled_event(1, Definition.EVENT_INTERVAL, Definition.EVENT_ONE_SHOT, 1, Definition.INTERVAL_TYPE_SEC, 0, 3, 500))) except Exception: time.sleep(5) print("Exception") else: if (intiateShutdown): time.sleep(5) turnOff() # return time.sleep(1)
import sys sys.path.append('/home/pi/gits/sixfab-power-python-api/') from power_api import SixfabPower, Definition, Event print("Powering down") while True: try: api = SixfabPower() print("success" if api.set_edm_status(1, 500) == 1 else "failed") except: print("exception")