def status_line(self):
        # read sensor values and return string to dsiplay on the status line
        humidity, temperature, time = self.sensor_read()
        self.mqtt_publish(MESSAGE_DATA, temperature, humidity, time)
        self.set_alert(temperature, humidity, time)

        if humidity is None or temperature is None:
            self.text_statusline.setText('ERROR! Sensor not connected')
            self.mqtt_publish(MESSAGE_ERROR, "Error", "Error", time)
            return

        db = database.db_sql()
        db.load_temp_val(cursor, temperature)
        db.load_humidity_val(cursor, humidity)
        db.commit_db(dbase)

        if is_farenheit is 1:
            temperature_f = temperature * 1.8 + 32
            self.text_statusline.setText('['+ str(time)+ ']'+ \
             '\t\tSensor Status: Connected' + '\t\tTemperature: {0:0.1f} F'.format(temperature_f) \
             + '\t\tHumidity: {0:0.1f} %'.format(humidity))
        else:
            self.text_statusline.setText('['+ str(time)+ ']'+ \
             '\t\tSensor Status: Connected' + '\t\tTemperature: {0:0.1f} C'.format(temperature) \
             + '\t\tHumidity: {0:0.1f} %'.format(humidity))
Пример #2
0
	def refresh(self):
		s3 = boto3.client('s3')
		obj = database.db_sql()
		s3.download_file(bucket_image, image_on_cloud, image_on_pi)
		self.label_img.setPixmap(QtGui.QPixmap(image_on_pi))
		Label,Feedback = obj.get_last_record(cursor)
		
		self.label_recog.setText(Label)
		self.label_rw.setText(Feedback)
 def humidity_graph(self):
     # display a graph of past 10 humidity values
     x = np.linspace(0, 1, 10)
     db = database.db_sql()
     readings = db.read_last_n_records(cursor, TB_HUMID, 10)
     t = ([i[2] for i in readings])
     t.reverse()
     self.matplot_widget.canvas.axes.clear()
     self.matplot_widget.canvas.axes.plot(x, t)
     self.matplot_widget.canvas.axes.legend('Readings', 'Humidity')
     self.matplot_widget.canvas.draw()
    def temperature_graph(self):
        # display a graph of past 10 temperature values
        db = database.db_sql()
        x = np.linspace(0, 1, 10)
        readings = db.read_last_n_records(cursor, TB_TEMP, 10)
        t = ([i[2] for i in readings])
        t.reverse()
        if is_farenheit is 1:
            t = self.Celcuis2Farenheit(t)

        self.matplot_widget.canvas.axes.clear()
        self.matplot_widget.canvas.axes.plot(x, t)
        self.matplot_widget.canvas.axes.legend('Readings', 'Temperature')
        self.matplot_widget.canvas.draw()
Пример #5
0
	def statistics(self):
		obj = database.db_sql()
		obj_percentage = obj.get_right_percentage(cursor)
		command_percentage = obj.get_command_percentage(cursor)

		#set percentage to string
		self.label_obj.setText(str(obj_percentage))
		self.label_cmd.setText(str(command_percentage))
		data = []
		readings = obj.read_last_n_records(cursor,5)
		for rows in  readings:
			data.append(tuple(rows))
		
		row = 0
		for tup in data:
			col = 0
			for item in tup:
				cellinfo = QTableWidgetItem(item)
				self.tableWidget.setItem(row, col, cellinfo)
				col+=1
			row +=1
		print("STATS")
Пример #6
0
def message_handler(message):

	th = display()
	if message == "CurrSensVal":		
		mutex.acquire()
		humidity, temperature, time  = th.sensor_read()
		mutex.release()
		if humidity is None or temperature is None:
			return message + '+' + str(time) + '+' + "Error + Error"
		return message + '+'+ str(time) + '+' + '{0:0.1f}'.format(temperature) + '+' + '{0:0.1f}'.format(humidity)
			
	if message == "TorMySQL":
		data = dict()
		datalist = list()
		db = db_sql()
		readings = db.read_last_n_records(cursor, TB_HUMID, 10)
		print(readings)
		for x,y,z in readings:
			data = {"value":x, "timestamp": str(y),"serialNo":z}
			datalist.append(data)
			
		output= json.dumps(datalist)
		return output
        t = ([i[2] for i in readings])
        t.reverse()
        self.matplot_widget.canvas.axes.clear()
        self.matplot_widget.canvas.axes.plot(x, t)
        self.matplot_widget.canvas.axes.legend('Readings', 'Humidity')
        self.matplot_widget.canvas.draw()

    def terminate(self):
        sys.exit(app.exec_())

if __name__ == "__main__":
    ######## MAIN CODE ###########
    app = QApplication(sys.argv)
    widget = display()
    #create database
    db_obj = database.db_sql()
    db_obj.create_database(cursor, DB_NAME)
    #select the database
    db_obj.use_database(cursor, DB_NAME)
    #create temperature Table
    db_obj.create_temp_tb(cursor)
    #create Humidity table
    db_obj.create_humidity_tb(cursor)
    # commit the changes
    db_obj.commit_db(dbase)

    widget.show()
    print("SETUP")
    # AWS IoT Setup

    mqttClient.configureEndpoint(