def main(): # Menyimpan pin-pin relay dan memasukkan nilai "state"nya ke dalam Dictionary bernama "pins" yang telah diinisiasi sebelumnya for pin in pins: pins[pin]['state'] = GPIO.input(pin) # memasukkan Dictionary "pins" ke dalam dictionary "templateData": templateData = {'pins': pins} var_mainTankWaterLvl = JSNDistance.measureTank(GPIO_TRIGGER_MAIN, GPIO_ECHO_MAIN, mainTankDistance) var_secondaryTankWaterLvl = JSNDistance.measureTank( GPIO_TRIGGER_SECONDARY, GPIO_ECHO_SECONDARY, secondTankDistance) var_mainTankTemperature = DSTemp.read_temp(device_file1) var_secondaryTankTemperature = DSTemp.read_temp(device_file2) return render_template( 'home.html', mainTankWaterLvl=var_mainTankWaterLvl, secondaryTankWaterLvl=var_secondaryTankWaterLvl, mainTankTemperature=var_mainTankTemperature, secondaryTankTemperature=var_secondaryTankTemperature, **templateData)
def main(): # Menyimpan pin-pin relay dan memasukkan nilai "state"nya ke dalam Dictionary bernama "pins" yang telah diinisiasi sebelumnya for pin in pins: pins[pin]['state'] = GPIO.input(pin) # memasukkan Dictionary "pins" ke dalam dictionary "templateData": templateData = {'pins': pins} var_mainTankWaterLvl = JSNDistance.measureTank(GPIO_TRIGGER_MAIN, GPIO_ECHO_MAIN, mainTankDistance) var_secondaryTankWaterLvl = JSNDistance.measureTank( GPIO_TRIGGER_SECONDARY, GPIO_ECHO_SECONDARY, secondTankDistance) var_mainTankTemperature = DSTemp.read_temp(device_file1) var_secondaryTankTemperature = DSTemp.read_temp(device_file2) hour, minutes = CurrentACS.simulate_battery_usage() # hour, minutes = CurrentACS.get_battery_estimated_life(50,4.187,20) return render_template( 'home.html', mainTankWaterLvl=var_mainTankWaterLvl, secondaryTankWaterLvl=var_secondaryTankWaterLvl, mainTankTemperature=var_mainTankTemperature, secondaryTankTemperature=var_secondaryTankTemperature, **templateData, hour=str("%.0f" % hour), minutes=str("%.0f" % minutes), powerMode="Baterai")
def fill_full_tank(): if (float( JSNDistance.measureTank(GPIO_TRIGGER_MAIN, GPIO_ECHO_MAIN, mainTankDistance)) < float(maxWater)): GPIO.output(pengisi, GPIO.LOW) #Nyalakan pompa pengisi time.sleep(2) print("pengisian sedang berlangsung...\n") print("Ketinggian Air : ") print( JSNDistance.measureTank(GPIO_TRIGGER_MAIN, GPIO_ECHO_MAIN, mainTankDistance)) print(" Target volume air :") print(maxWater) print("\n\n") else: GPIO.output(pengisi, GPIO.HIGH) #Matikan pompa pengisi print("mematikan pompa pengisi...") globals()['isWaterChangeCompleted'] = True
def drain_half_tank(): # half = maxWater/2 #kode asli if (float( JSNDistance.measureTank(GPIO_TRIGGER_MAIN, GPIO_ECHO_MAIN, mainTankDistance)) > float(volumeAfterDrain)): GPIO.output(pengisap, GPIO.LOW) #Nyalakan pompa pengisap time.sleep(4) print("penyedotan sedang berlangsung...") print("Target volume air :") print(volumeAfterDrain) print("Ketinggian Air : ") print( JSNDistance.measureTank(GPIO_TRIGGER_MAIN, GPIO_ECHO_MAIN, mainTankDistance)) print("\n\n") else: GPIO.output(pengisap, GPIO.HIGH) #Matikan pompa pengisap globals()['isTankDrained'] = True print("penyedotan telah selesai!\n\n") print("\n\n") time.sleep(1)
time.sleep(2) if (isTankDrained == False): drain_half_tank() else: fill_full_tank() if (isWaterChangeCompleted == True): print("Water Change completed") break #Tinggi Sensor jika tank Kosong mainTankDistance = 70 #calibrate this secondTankDistance = 65 #calibrate this maxWater = JSNDistance.measureTank( GPIO_TRIGGER_MAIN, GPIO_ECHO_MAIN, mainTankDistance) #mengambil nilai ketinggian waterVolumetoChange = float( maxWater) / 15 # mengganti 1/15 volume air di dalam tank untuk testing volumeAfterDrain = float(maxWater) - float(waterVolumetoChange) isTankDrained = False isWaterChangeCompleted = False def drain_half_tank(): # half = maxWater/2 #kode asli if (float( JSNDistance.measureTank(GPIO_TRIGGER_MAIN, GPIO_ECHO_MAIN, mainTankDistance)) > float(volumeAfterDrain)): GPIO.output(pengisap, GPIO.LOW) #Nyalakan pompa pengisap
def store_water_lvl(main_tank, second_tank): conn = sqlite3.connect('/var/www/lab_app/tankwaterlvl.db') curs = conn.cursor() curs.execute("""UPDATE waterlvl SET maintank=(?) WHERE id=1""", (main_tank, )) curs.execute("""UPDATE waterlvl SET secondtank=(?) WHERE id=1""", (second_tank, )) curs.execute("SELECT * FROM waterlvl") temp = curs.fetchall() for row in temp: print(row[2]) print(row[3]) conn.commit() conn.close() main_tank_wlvl = JSNDistance.measureTank(GPIO_TRIGGER_MAIN, GPIO_ECHO_MAIN, mainTankDistance) second_tank_wlvl = JSNDistance.measureTank(GPIO_TRIGGER_SECONDARY, GPIO_ECHO_SECONDARY, secondTankDistance) #main_tank_wlvl = 6 #second_tank_wlvl = 7 if main_tank_wlvl is not None and second_tank_wlvl is not None: store_water_lvl(float(main_tank_wlvl), float(second_tank_wlvl)) else: store_water_lvl(0, 0)