def __init__(self): self.channel = 17 self.camera = camera() self.network = networkPreference() self.device = deviceActivation() self.smokesensor = MQ() self.buzzer = buzzer()
class flame: # GPIO SETUP channel = 17 #pin 17 -- fire sensor GPIO.setmode(GPIO.BCM) #specify the sensor to use the broadcom mode in Pi GPIO.setup(channel, GPIO.IN) #set pin 17 as input port -- fire sensor def __init__(self): self.channel = 17 self.camera = camera() self.network = networkPreference() self.device = deviceActivation() self.smokesensor = MQ() self.buzzer = buzzer() def startFlameRead(self): print('Initializing sensors reading') perc = self.smokesensor.MQPercentage() # self.buzzer.checkBuzzerStatus() flag = GPIO.input(self.channel) if (flag == 0): print('Fire Alert!') self.camera.triggerCamera() self.sendReport(str(perc["SMOKE"]), str(perc["GAS_LPG"]), str(perc["CO"])) self.buzzer.onbuzzer() else: print('No fire detected\n') print("LPG: %g ppm, CO: %g ppm, Smoke: %g ppm" % (perc["GAS_LPG"], perc["CO"], perc["SMOKE"])) self.buzzer.setCurrentState(True) def startSmokeRead(self): # perc = self.smokesensor.MQPercentage() sys.stdout.write("\033[K") sys.stdout.write("LPG: %g ppm, CO: %g ppm, Smoke: %g ppm" % (perc["GAS_LPG"], perc["CO"], perc["SMOKE"])) sys.stdout.flush() time.sleep(0.1) print("\n") def sendReport(self, smoke, gas_lpg, co): test = json.dumps({ "error": False, "firedevice_id": self.device.getDeviceID(), "fire_detect": True, "image_data": self.camera.getImageData(), # "image_data":"donut", "reading_smoke": smoke, "reading_gas": gas_lpg, "reading_lpg": co, "buzzer_flag": "ON", # "buzzer_flag":buzz }) r = self.network.postData(test, "getReading") stat = json.loads(r.data)
def __init__(self, vid, name, cid): self.vid = vid self.name = name self.members = set() self.members_small = [] self.uid_table = {} self.cid = cid self.flag = '' self.attrs = {} self.msgid = 0 self.mq = MQ(msg_max)
Point(1600,1.6), Point(2000,1.4),Point(3000,1.3),Point(5000,0.92), Point(10000,0.7)]}; mq135_data = {"CO2":[Point(10,2.5) ,Point(40,1.5), Point(100,1.1), Point(200,0.8)], "CO":[Point(10,2.9) ,Point(40,1.95), Point(100,1.7), Point(200,1.5)], "NH4":[Point(10,2.7) ,Point(40,1.53), Point(100,1), Point(200,0.785)], "Benzene":[Point(10,1.6) ,Point(40,1.1), Point(100,0.8), Point(200,0.65)]}; mq131_data = {"Ozone":[Point(5,6),Point(10,4),Point(20, 1.5),Point(100,0.5)], "NO2": [Point(5,9),Point(10,8), Point(20,7), Point(100,4.5)], "CL2": [Point(5,8),Point(10,6.8), Point(20,4.8), Point(100,0.8)]}; so2_data = {"SO2":[Point(35,1),Point(100,1.5),Point(200, 1.95), Point(300,2.2),Point(400,2.35),Point(500,2.45),Point(600,2.5)]}; mcp = MCP3008() mq2 = MQ('MQ2', mcp, 0, 5, 9.8, mq2_data) mq135 = MQ('MQ135', mcp, 1, 20, 3.75, mq135_data) mq131 = MQ('MQ131', mcp, 2, 20, 20, mq131_data) o2 = Grove_O2(mcp, 3, 3.3, 7.43) noise = Sound_Detector(mcp, 4) sh12 = MQ('2SH12', mcp, 5, 50, 6, so2_data) tmp36 = TMP36(mcp, 6, 3.3) humidity = Humidity(mcp, 7, 3.3) pm = GP2Y(13, 3.3, 1) print('---------------------------------------') print('Reading MQ-2 sensor...') mq2R = mq2.read() print(mq2R) print('Finished reading MQ-2 sensor') print('---------------------------------------')
else: data += str(args[i]) + "," data += "]}" return data while True: window.get_information("/home/pi/Desktop/EAPMS/device_info.csv") mq131_data = {"Ozone":[Point(10,1.1893),Point(50,2),Point(100, 2.6409),Point(200,4),Point(500,6),Point(1000,8)], "NO2": [Point(5,9),Point(10,8), Point(20,7), Point(100,4.5)], "CL2": [Point(5,8),Point(10,6.8), Point(20,4.8), Point(100,0.8)]} mcp = MCP3008() mq131 = MQ("MQ131", mcp, 2, 20, 20, mq131_data) counter = 0 limit = 30 try: device_infoFile = open("/home/pi/Desktop/EAPMS/device_info.csv", 'r') info = device_infoFile.read().split(',') deviceName = info[0] ozone = 0 cl2 = 0 while True: if counter == limit: ozone /= limit
class Receiver(Daemon): stream = None def __init__(self, pid_file): """ Constructor """ Daemon.__init__(self, pid_file) def setup(self): self.setup_db() self.delete_old() self.setup_mq() def setup_db(self): db = DB() self.conn = db.get_conn() def setup_mq(self): self.mq = MQ() self.mq.init_consumer(self.callback) self.mq.consumer.start_consuming() def run(self): self.setup() def callback(self, ch, method, properties, body): self.insert_tweet(body) def delete_old(self): threading.Timer(300.0, self.delete_old).start() # called every minute cur = self.conn.cursor() cur.execute( "DELETE FROM twitter.tweet WHERE recorded_at <= now() - (10 * interval '1 minute')" ) self.conn.commit() cur.execute( "DELETE FROM twitter.tweet_hashtag WHERE tweet_id NOT IN (SELECT id FROM twitter.tweet)" ) self.conn.commit() cur.close() def insert_tweet(self, body): tweet = json.loads(body.decode('utf-8')) cur = self.conn.cursor() hashtags = tweet['hashtags'] cur.execute( 'INSERT INTO twitter.tweet (id, user_id, user_name, tweet_text, retweeted, retweet_count, favorite_count, search_key) ' 'VALUES (%s, %s, %s, %s, %s, %s, %s, %s)', (tweet['id'], tweet['user_id'], tweet['user'], tweet['text'], tweet['retweeted'], tweet['retweet_count'], tweet['favorite_count'], tweet['search_key'])) self.conn.commit() for tag in hashtags: cur.execute( 'INSERT INTO twitter.tweet_hashtag (tweet_id, hashtag) ' 'VALUES (%s, %s)', (tweet['id'], tag['text'])) self.conn.commit() cur.close()
def setup_mq(self): self.mq = MQ() self.mq.init_consumer(self.callback) self.mq.consumer.start_consuming()
so2_data = { "SO2": [ Point(35, 1), Point(100, 1.5), Point(200, 1.95), Point(300, 2.2), Point(400, 2.35), Point(500, 2.45), Point(600, 2.5) ] } # Initalize the required sensors devices mcp = MCP3008() mq2 = MQ("MQ2", mcp, 0, 5, 9.8, mq2_data) mq135 = MQ("MQ135", mcp, 1, 20, 3.75, mq135_data) mq131 = MQ("MQ131", mcp, 2, 20, 20, mq131_data) o2 = Grove_O2(mcp, 3, 3.3, 7.43) noise = Sound_Detector(mcp, 4) sh12 = MQ("2SH12", mcp, 5, 50, 6, so2_data) tmp36 = TMP36(mcp, 6, 3.3) humidity = Humidity(mcp, 7, 3.3) pm = GP2Y(13, 3.3, 1) # Initialize Connection with UDP Server & MySQL Server device_infoFile = open("/home/pi/Desktop/EAPMS/device_info.csv", 'r') info = device_infoFile.read().split(',') deviceName, serverIp, port = info[0], str(info[1]), int(info[2]) serverSocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) cursor = db.connect_to_mysqlServer(serverIp, 'pi', 'pi', 'eapmsDB', 'data')
pycom.rgbled(0x140000) time.sleep(2.5) pycom.rgbled(0x000000) time.sleep(1.0) print('Not yet joined...') print('OTAA joined') pycom.rgbled(0x001400) # create a LoRa socket s = socket.socket(socket.AF_LORA, socket.SOCK_RAW) # set the LoRaWAN data rate s.setsockopt(socket.SOL_LORA, socket.SO_DR, 5) mq2 = MQ('P16') while True: s.setblocking(True) pycom.rgbled(0x000014) lpp = CayenneLPP() print('\n\n** Mq8 Gas Sensor ppm value') value = mq2.MQRead() print('mq2_gas_ value', value) lpp.add_mq2(1, value) print('Sending data (uplink)...') s.send(bytes(lpp.get_buffer())) s.setblocking(False) data = s.recv(64) print('Received data (downlink)', data) pycom.rgbled(0x001400)