예제 #1
0
 def monitor_loop(self):
     f = open(self.logdir + '/power.log', 'at')
     data = [0, 0, 0, 0, 0, 0, 0, 0]
     while True:
         try:
             data = self.bus.read_i2c_block_data(0x04, 0)
         except:
             if __debug__:
                 print("Failed to read i2c data")
             sleep(1)
         self.extracted[0] = time.time()
         for i in range(0, 8):
             bytes = data[4 * i:4 * i + 4]
             self.extracted[i + 1] = struct.unpack('f', "".join(map(chr, bytes)))[0]
         if __debug__:
             print("Writing csv row")
         writer = csv.writer(f)
         writer.writerow(self.extracted)
         f.flush()
         sleep(self.interval)
         # If telegram messaging is active, do a few checks and notify
         if self.telegram:
             if __debug__:
                 print("Telegram enabled")
             if (self.extracted[5] != 0) and (self.extracted[5] < 21) and not self.lowbat:
                 if __debug__:
                     print("Battery low")
                 telegram.send("Battery below 21V")
                 self.lowbat = True
         f.close()
예제 #2
0
 def monitor_loop(self):
     f = open(self.logdir + '/power.log', 'at')
     data = [0, 0, 0, 0, 0, 0, 0, 0]
     while True:
         try:
             data = self.bus.read_i2c_block_data(0x04, 0)
         except:
             if __debug__:
                 print("Failed to read i2c data")
             sleep(1)
         self.extracted[0] = time.time()
         for i in range(0, 8):
             bytes = data[4 * i:4 * i + 4]
             self.extracted[i + 1] = struct.unpack('f',
                                                   "".join(map(chr,
                                                               bytes)))[0]
         if __debug__:
             print("Writing csv row")
         writer = csv.writer(f)
         writer.writerow(self.extracted)
         f.flush()
         sleep(self.interval)
         # If telegram messaging is active, do a few checks and notify
         if self.telegram:
             if __debug__:
                 print("Telegram enabled")
             if (self.extracted[5] != 0) and (self.extracted[5] <
                                              21) and not self.lowbat:
                 if __debug__:
                     print("Battery low")
                 telegram.send("Battery below 21V")
                 self.lowbat = True
         f.close()
예제 #3
0
파일: main.py 프로젝트: dpoulson/r2_control
def sendstatus():
    """GET to send system status via telegram"""
    message = ""
    if request.method == 'GET':
        if "telegram" in modules:
            telegram.send(system_status())
            message = "Sent"
        else:
            message = "Telegram module not configured"
    return message
예제 #4
0
파일: main.py 프로젝트: jeffds77/r2_control
def sendstatus():
    """GET to send system status via telegram"""
    message = ""
    if request.method == 'GET':
        if "telegram" in modules:
            telegram.send(system_status())
            message = "Sent"
        else:
            message = "Telegram module not configured"
    return message
예제 #5
0
파일: main.py 프로젝트: dpoulson/r2_control
def shutdown():
    """GET to shutdown Raspberry Pi"""
    logging.info("****** Shutting down ******")
    if "telegram" in modules:
        telegram.send("Night night...")
    if request.method == 'GET':
        os.system('shutdown now -h')
        s = open("controllers/.shutdown", "w+")
        s.write(datetime.datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d %H:%M:%S'))
        s.flush()
        s.close()
    return "Shutting down"
예제 #6
0
파일: main.py 프로젝트: dpoulson/r2_control
def joystick_change(stick):
    """GET to change joystick to <stick> """
    logging.info("Changing joystick to " + stick)
    if request.method == 'GET':
        message = "Invalid stick"
        for valid in list_joysticks():
            logging.info("Checking controller type is valid: " + valid)
            if valid == stick:
                message = "Valid stick. Changed to " + stick
                with open("controllers/.current", "w") as current_joy:
                    current_joy.write(stick)
                if "telegram" in modules:
                    telegram.send("Setting joystick to " + stick)
    return message
예제 #7
0
파일: main.py 프로젝트: jeffds77/r2_control
def shutdown():
    """GET to shutdown Raspberry Pi"""
    logging.info("****** Shutting down ******")
    if "telegram" in modules:
        telegram.send("Night night...")
    if request.method == 'GET':
        os.system('shutdown now -h')
        s = open("controllers/.shutdown", "w+")
        s.write(
            datetime.datetime.fromtimestamp(
                time.time()).strftime('%Y-%m-%d %H:%M:%S'))
        s.flush()
        s.close()
    return "Shutting down"
예제 #8
0
파일: main.py 프로젝트: jeffds77/r2_control
def joystick_change(stick):
    """GET to change joystick to <stick> """
    logging.info("Changing joystick to " + stick)
    if request.method == 'GET':
        message = "Invalid stick"
        for valid in list_joysticks():
            logging.info("Checking controller type is valid: " + valid)
            if valid == stick:
                message = "Valid stick. Changed to " + stick
                with open("controllers/.current", "w") as current_joy:
                    current_joy.write(stick)
                if "telegram" in modules:
                    telegram.send("Setting joystick to " + stick)
    return message
예제 #9
0
 def __init__(self, address, interval):
     # Check for telegram config
     self.telegram = False
     self.address = address
     self.interval = interval
     self.logdir = mainconfig.mainconfig['logdir']
     self.lowbat = False
     self.extracted = [0, 0, 0, 0, 0, 0, 0, 0, 0]
     try:
         self.bus = smbus.SMBus(int(mainconfig.mainconfig['busid']))
     except:
         print("Failed to connect to device on bus")
     if __debug__:
         print("Monitoring....")
     if self.telegram:
         telegram.send("Monitoring started")
     loop = Thread(target=self.monitor_loop)
     loop.daemon = True
     loop.start()
예제 #10
0
 def __init__(self, address, interval):
     # Check for telegram config
     self.telegram = False
     self.address = address
     self.interval = interval
     self.logdir = mainconfig.mainconfig['logdir']
     self.lowbat = False
     self.extracted = [0, 0, 0, 0, 0, 0, 0, 0, 0]
     try:
         self.bus = smbus.SMBus(int(mainconfig.mainconfig['busid']))
     except:
         print("Failed to connect to device on bus")
     if __debug__:
         print("Monitoring....")
     if self.telegram:
         telegram.send("Monitoring started")
     loop = Thread(target=self.monitor_loop)
     loop.daemon = True
     loop.start()