Esempio n. 1
0
    def showPI(self):
        logging.debug('OLED : showPI')
        if( self.disp == None ):
            return

        cmd = "/bin/hostname -I | /usr/bin/cut -d\' \' -f1"
        IP = getIPAddr()
        if( IP == '0.0.0.0' ):
            IP = "[No IP Address!]"
        elif( IP.startswith('169.254') ):
            IP = f"inPriv! {IP}"

        cmd = "/bin/df -h | /usr/bin/awk '$NF==\"/\"{printf \"disk %d/%dGB %s\", $3,$2,$5}'"
        Disk = subprocess.check_output(cmd, shell = True ).decode()

        Temp = getMachine_Temp()
        Volt = getMachine_Volt()

        SSID = getSSID()
     
        ## --- display
        self.draw.rectangle(( 0, 0,self.width,self.height), outline=0, fill=0)
        self.draw.text((0,  0), f"{IP}",font=self.font, fill=255)
        self.draw.text((0, 16), f" {SSID}", font=self.fontS, fill=255)
        self.draw.text((0, 32), f"name {getHostname()}", font=self.font, fill=255)
        self.draw.text((0, 49), f"{Disk}",  font=self.font, fill=255)
        #self.draw.text((0, 38), f"Temp:{Temp:.1f}C Volt:{Volt:.1f}V", font=self.fontS, fill=255)
        self.disp.image(self.image)
        self.disp.display()
Esempio n. 2
0
    def showPI(self):
        logging.debug('OLED : showPI')
        if (self.disp == None):
            return

        self.clear()

        cmd = "/bin/df -h | /usr/bin/awk '$NF==\"/\"{printf \"Disk: %d/%dGB %s\", $3,$2,$5}'"
        Disk = subprocess.check_output(cmd, shell=True).decode()

        IP = getIPAddr()
        Temp = getMachine_Temp()
        Volt = getMachine_Volt()
        SSID = getSSID()

        # Write two lines of text.
        self.draw.text((0, 0), f"{IP}", font=self.fontS, fill=255)
        self.draw.text((0, 10), f"{SSID}", font=self.fontS, fill=255)
        self.draw.text((0, 25), f"Temp:{Temp:.1f}C", font=self.fontS, fill=255)
        self.draw.text((0, 35), f"Volt:{Volt:.1f}V", font=self.fontS, fill=255)
        self.draw.text((0, 45), f"{Disk}", font=self.fontS, fill=255)
        self.disp.image(self.image)
        self.disp.display()
Esempio n. 3
0
# 起動時にラズパイの情報をSSD1306に表示

import logging
from libSSD1306 import OLED
from libMachineInfo import getIPAddr, getHostname
import time
import subprocess
import json
import time

if __name__ == '__main__':
    logging.info("STAT start! {}".format(time.strftime("%Y-%m-%d %H:%M:%S")))
    o = OLED()
    #OLE接続時にステータスを表示
    if (o != None):
        o.text(2, 32, "PLEASE WAIT...")
        ipAddr = ""
        st_time = time.time()
        while True:
            ipAddr = getIPAddr()
            if (ipAddr != ""):
                time.sleep(1)
                break

        span = time.time() - st_time
        logging.info(" - display STATUS {0:5.2f}sec".format(span))
        o.showPI()
    #    time.sleep(10)
    #    print(" - clear Display")
    #    oled.clear()
Esempio n. 4
0
def main():
    logging.info(f"[SAST_monitor] into Main LOOP")
    # --- Main LOOP
    showSTAT()
    while END:
        logging.debug("Check send error data for Ambient(NET1)")
        rows = DB.get_NET1_Error()
        if (len(rows) != 0 and AMBIENT['use']):
            logging.info(f"find SendError DATA(Ambient) num={len(rows)}")
            sendDATA = []
            ids = []
            for d in rows:
                ids.append(d.pop('id'))
                del d['opt1'], d['opt2'], d['opt3'], d['net1'], d['net2'], d[
                    'net3']
                logging.debug(f"sendDATA = {d}")
                sendDATA.append(d)

            ## --- Ambientは纏めて送信可能
            ret = sent_Ambient(AMBIENT, sendDATA)
            if (ret):
                DB.update_NET1(ids)
            else:
                logging.error("Amdient ReSend Error")

        logging.debug("Check send error data for GAS(NET2)")
        rows = DB.get_NET2_Error()
        if (len(rows) != 0 and GAS['use']):
            logging.info(f"Find SendError DATA(GAS) num={len(rows)}")
            ids = []
            for d in rows:
                ids.append(d.pop('id'))
                del d['opt1'], d['opt2'], d['opt3'], d['net1'], d['net2'], d[
                    'net3']
                logging.debug("sendDATA = {d}")
                # --- GASは1行毎に処理のため
                ret = sent_GAS(GAS, d)
                if (ret == False):
                    ## --- 送信失敗はIDを削除
                    logging.error("GAS ReSend Error")
                    ids.remove(-1)
            DB.update_NET2(ids)

        # --- Netowork Check
        logging.debug("Check Network")
        MyIP = getIPAddr()
        logging.debug(f"MyIP = {MyIP}")
        if (getTypeIP(MyIP) == True):
            gateIP = getDefaultRoute()
            if (IsAlive(gateIP) == False):
                logging.warning("ERROR! No reach DefaultRoute {gateIP}")
        else:
            logging.warning(f"ERROR! ignore MyIP={MyIP}")

        ## --- NetworkRESET ? ->

        ## --- get BATTERY STAT 10sec
        BATT = [None, None, None]
        num = 0
        for sens in SENS:
            BATT[num] = DB.getBattery(sens['MAC'])
            num += 1
        logging.debug(f"BAT = {BATT} ")
        D.updateStatus2(BATT)

        ## --- Wait 10sec to Main Loop
        time.sleep(INTERVAL)
Esempio n. 5
0
        logging.debug(f"BAT = {BATT} ")
        D.updateStatus2(BATT)

        ## --- Wait 10sec to Main Loop
        time.sleep(INTERVAL)


if __name__ == '__main__':
    # -- START UP
    logging.info("[SAST_monitor] Waiting Assign IP Assress")
    D.text(2, 32, "PLEASE WAIT...")
    st_time = time.time()

    # --- Check IP Address
    while END:
        ip = getIPAddr()
        if (getTypeIP(ip)):
            logging.info(f"[SAST_monitor] IP is {ip}({getHostname()})")
            logging.info("IP waiting span is {0:5.2f}sec".format(time.time() -
                                                                 st_time))
            D.showPI()
            time.sleep(5)
            break
        logging.debug("[SAST_monitor] while DHCP")
        time.sleep(2)
        continue

    ## --- show status
    showSTAT()

    ## --- Valid SIGNAL hook