예제 #1
0
def logging():

    chk = rep.startCommunication(0, 1, 2)
    if (chk == -1):
        sleep = {
            "inverter-state": {
                "value": 4,
                "context": {
                    "state": "Sleep-Mode"
                }
            }
        }
        chk = rep.postData(rep.url, rep.header, sleep, 3)
        if (chk == -1):
            print("[ERROR] Unable to update inverter state in Cloud...")
        print("[ERROR] MODBUS Connection Error...")
        return -1

    elif (chk[0] == 0):
        s = {
            "inverter-state": {
                "value": chk[0],
                "context": {
                    "state": rep.STATE[str(chk[0])]
                }
            }
        }
        chk = rep.postData(rep.url, rep.header, s, 3)

        if (chk == -1):
            print("[ERROR] Unable to update inverter state in Cloud...")

        print("[INFO] Posting previous error values...")
        chk = db2cloud.main()
        if (chk == -1):
            return -1
    elif (chk[0] == 1 or chk[0] == 3):
        s = {
            "inverter-state": {
                "value": chk[0],
                "context": {
                    "state": rep.STATE[str(chk[0])]
                }
            }
        }
        chk = rep.postData(rep.url, rep.header, s, 3)
        if (chk == -1):
            print("[ERROR] Unable to update inverter state in Cloud...")
        print("[INFO] Calling Main Logging Function...")
        time.sleep(10)
        main_logger.main()
        print("[INFO] Posting Todays energy generated data...")
        chk = energyPost()

        if (chk == -1):
            return -1
        return 0
예제 #2
0
def main():
    while True:
        chk = rep.startCommunication(0,42,retries = 5)
        if (chk == -1):
            print("[ERROR] Maximum Retries Reached... Retrying ...")
            return -1
        if(chk[0] == 0):#chk[0] is the status of the inverter 0-fault, 1-normal,3-waiting#
            print("[ERROR] Inverter under fault state...")
            return -1
        to_get = [2,3,4,6,7,8,10,12,13,27,28,29,32,41] # register numbers wee needed, refer 'rep module' for name of registers
        trimmedRegArray = []
        for i in range(len(to_get)):
            trimmedRegArray.append(chk[to_get[i]]) 
        dbList = copy.deepcopy(trimmedRegArray)#deep copy is used to make the copy of the list completely immutable#
        print("[INFO] Updating database with values...")
        rep.post_into_database(rep.DB_NAME, INSERT_INV_TABLE,[rep.genTimeStamp(datetime.datetime.now())]+dbList )    
        payloaddict = payloadGenerator(rep.VAR_NAME, trimmedRegArray)
        rep.fault_switch()
        chk = rep.postData(url = rep.url, header=rep.header, payload = payloaddict)
        if(chk == -1):
            print("[ERROR] Posting into Error Database...")
            rep.post_into_database(rep.DB_NAME, INSERT_ERROR_TABLE,[rep.genTimeStamp(datetime.datetime.now())]+dbList )
        elif(chk == 200):
            print("[INFO] Request Successful, Data posted to cloud Successfully...")
        time.sleep(NORM_WAIT_TIME)
예제 #3
0
def energyPost():
    rows = rep.post_into_database(
        rep.DB_NAME, "SELECT TIMESTAMP,ENERGY_TODAY from INVERTER")
    data = {
        "energy_today": {
            "value": (rows[len(rows) - 1])[1],
            "timestamp": (rows[len(rows) - 1])[0]
        }
    }
    chk = rep.postData(rep.url, rep.header, data, 2)
    print("[INFO]Energy today posted into cloud...")
    if (chk == -1):
        print("[ERROR] Unable to post Energy data to cloud... Retrying...")
        return -1
    return 0
예제 #4
0
def main():
    data = rep.startCommunication(90,25, 5)
    if(data == -1):
        print("[INFO] Fault table not recieved...")
        return -1
    to_send ={}
    fault =[]
    x = list(divide_chunks(data, 5))
    for j in range(0,len(x)):
        t = datetime.datetime(((x[j][1]>>8)+2000),(x[j][1]&255),(x[j][2]>>8),(x[j][2]&255),(x[j][3]>>8),(x[j][3]&255))
        fault.append({"value":x[j][4]*0.1,"timestamp":rep.genTimeStamp(t),"context":{"fault_type":error_dict[str(x[j][0])]}})
    to_send = {"fault":fault}
    chk = rep.postData(rep.url, rep.header, to_send, 2)
    if(chk == -1):
        print("[ERROR] Error posting fault to cloud...")
        return -1
    print(chk)
    return 0
예제 #5
0
def main():
    rows = rep.post_into_database(rep.DB_NAME, SELECT_ERROR_TABLE)
    if (rows == -1):
        print("[INFO] Error Table empty / previously uploaded...")
        return -1
    print(rows)
    tup_len = len(rows[1])
    row_len = len(rows)
    list1 = []
    tString = {}
    for i in range(tup_len - 1):
        for j in range(row_len):
            list1.append({"value": rows[j][i + 1], "timestamp": rows[j][0]})
        tString.update({rep.VAR_NAME[i]: list1})
        list1 = []
    print(tString)
    chk = rep.postData(rep.url, rep.header, tString, 5)
    if (chk == -1):
        print("[ERROR] Internet Failure, Couldnt upload values to cloud...")
        return -1
    rep.post_into_database(rep.DB_NAME, "DROP TABLE IF EXISTS ERROR_TABLE")
    print("[INFO] Values uploaded and table deleted...")