Пример #1
0
def initializeSGSPart1():
    print("###############################################")
    print("SGS2 Version "+SGSVERSION+"  - SwitchDoc Labs")
    print("###############################################")
    print("")
    print("Program Started at:"+ time.strftime("%Y-%m-%d %H:%M:%S"))
    print("")
    
    
    
    # read in JSON
    # read in JSON
    if (readJSON.readJSON("") == False):
        print("#############################")
        print("No SGS.JSON file present - configure with 'sudo python3 SGSConfigure.py'")
        print("#############################")
        exit()

        
    readJSON.readJSONSGSConfiguration("")
    #init blynk app state
    if (config.USEBLYNK):
        updateBlynk.blynkInit()
    message = "SGS Version "+SGSVERSION+" Started"
    pclogging.systemlog(config.INFO,message)
    pclogging.systemlog(config.JSON,"SGS.JSON Loaded: "+json.dumps(config.JSONData ))
    pclogging.systemlog(config.JSON,"SGSConfigurationJSON.JSON Loaded: "+json.dumps(config.SGSConfigurationJSON ))
    pclogging.systemlog(config.CRITICAL,"No Alarm")
    if (config.GardenCam_Present):
        pclogging.systemlog(config.INFO,"Garden Cam Present")
    else:
        pclogging.systemlog(config.INFO,"Garden Cam NOT Present")
        
    # scan and check for resources
    # get if weather is being used
    config.Weather_Present = readJSON.getJSONValue("weather") 


    pass
def fetchValveJSON(myID, valveNumber):

    # read JSON

    readJSON.readJSON("../")
    readJSON.readJSONSGSConfiguration("../")

    myJSON = config.SGSConfigurationJSON

    #print("myJSON=", myJSON)
    #myLoadedJSON = json.loads(str(myJSON))
    #myLoadedJSON = json.loads(str(myJSON).replace("'","\"" ))
    myValves = myJSON["Valves"]

    for singleValve in myValves:
        #singleValve = json.loads(str(singleValve).replace("'","\"" ))
        #singleValve = json.loads(str(singleValve))
        if (str(singleValve["id"]).replace(" ",
                                           "") == str(myID).replace(" ", "")):
            if (str(singleValve["ValveNumber"]) == str(valveNumber)):
                return singleValve
    return {}
Пример #3
0
# SGS imports
sys.path.append("../")

import state
import config
import readJSON
import json

# demo mode
useRandom = False

# read JSON

readJSON.readJSON("../")
readJSON.readJSONSGSConfiguration("../")

import MySQLdb as mdb



################
# Status Page
################
def returnLatestValveRecord(myID):
        try:
                #print("trying database")
                con = mdb.connect('localhost', 'root', config.MySQL_Password, 'SmartGardenSystem');
                cur = con.cursor()
                query = "SELECT State FROM ValveRecord WHERE( DeviceID = '%s')  ORDER BY TimeStamp DESC LIMIT 1" % (myID)
                #print("query=", query)