ix. Source Code “iixbw.py”
usrbinpython from bandwidthscript import maincode
from time import sleep while True :
filename = ind.txt tabeldb = p2piix
tabeldb30 = p2piix30 maincodefilename,tabeldb,tabeldb30
sleep2
x. Source Code “gtwbw.py”
usrbinpython from bandwidthscript import maincode
from time import sleep while True :
filename = gate254.txt tabeldb = gtw254
tabeldb30 = gtw25430 maincodefilename,tabeldb,tabeldb30
sleep2
xi. Source Code “temperatur.py”
usrbinpython3 import os, glob, time, sys, datetime
from database import db_conn db = db_conn
os.systemsudo modprobe w1-gpio os.systemsudo modprobe w1-therm
device_folder = glob.globsysbusw1devices28 while True :
device_file = [] lendevice = lendevice_folder
temp_list=[] for i in rangelendevice:
folder = device_folder[i] + w1_slave device_file.appendfolder
filestemp = opendevice_file[i],r lines = filestemp.read
gettemp = lines.findt= temp = floatlines[gettemp+2:]1000
if temp = 0 : if temp = 40:
temp_list.appendtemp else :
pass cursor = db.cursor
_query = INSERT INTO temperatur waktu,suhu1,suhu2,suhu3 VALUESNOW,{},{},{} .formattemp_list[0],temp_list[1],temp_list[2]
cursor.execute_query db.commit
_query30 = INSERT INTO temperatur30 waktu,suhu1,suhu2,suhu3 VALUESNOW,{},{},{} .formattemp_list[0],temp_list[1],temp_list[2]
selectdata = SELECT COUNTwaktu FROM temperatur30 cursor.executeselectdata
hasil = cursor.fetchall hasil = ziphasil
data = hasil[0][0] if data = 30:
deldata = DELETE FROM temperatur30 ORDER BY DATEwaktu ASC LIMIT 1
cursor.executedeldata cursor.execute_query30
db.commit else :
cursor.execute_query30 db.commit
suhu1 = temp_list[0]
suhu2 = temp_list[1] suhu3 = temp_list[2]
if suhu1 18 or suhu2 18 or suhu3 18: tempstat = dingin
elif suhu1 27 or suhu2 27 or suhu3 27: tempstat = panas
else: tempstat = aman
files = opentempresult.txt,w files.writetempstat
files.close
xii. Source Code “getlistrik.py”
usrbinpython import RPi.GPIO as GPIO
import time def readgpio:
GPIO.setmodeGPIO.BCM channelIN = GPIO.setup27, GPIO.IN
return channelIN def readvolt:
channel = readgpio files = openlistrikresult.txt,w
if GPIO.input27 : status = 1
files.writehidup else:
status = 0 files.writemati
files.close return status
def sql: from database import db_conn
db = db_conn cur = db.cursor
result = readvolt selects = SELECT COUNTwaktu FROM listrik30
cur.executeselects counts = cur.fetchone
len = counts[0] if result == 1:
cur.executeINSERT INTO listrik VALUESNOW,1 if len = 30:
cur.executeDELETE FROM listrik30 ORDER BY DATEwaktu ASC LIMIT 1
cur.executeINSERT INTO listrik30 VALUESNOW,1 else:
cur.executeINSERT INTO listrik30 VALUESNOW,1 elif result == 0:
cur.executeINSERT INTO listrik VALUSENOW,0 if len = 30:
cur.executeDELETE FROM listrik30 ORDER BY DATEwaktu ASC LIMIT 1
cur.executeINSERT INTO listrik30 VALUESNOW,0 else:
cur.executeINSERT INTO listrik30 VALUESNOW,0
db.commit while True:
readvolt sql
time.sleep2
xiii. Source Code “smsscript.py”
usrbinpython from database import db_conn
from hplist import nohp import time
import datetime import MySQLdb
import os from sendsms import sendsms
def sqlreadtabel: db = db_conn
query = SELECT status FROM {} ORDER BY DATEwaktu DESC LIMIT 7; .formattabel
cursor = db.cursor cursor.executequery
getdata = cursor.fetchall result = zipgetdata
result = result[0] list = []
for i in rangelenresult: if result[i] == 0:
list.appendresult[i] else :
pass hasil = lenlist
return hasil def waktunamalink:
tanggal = datetime.datetime.now date = tanggal.strftimeH:M:S dmY
sambung = Raspberry Report : Jaringan {} Tersambung Kembali Pada Pukul : {}.formatnamalink,date
putus = Rasberry Report : Jaringan {} Putus Pada Pukul : {}.formatnamalink,date
return sambung, putus def prosestabel,namalink,filestatus:
listhp = nohp datasql = sqlreadtabel
statussambung =waktunamalink[0] statusputus = waktunamalink[1]
if datasql = 7: files = openfilestatus,r
status = files.readlines status = status[0]
print status files.close