def new(): # https://stackoverflow.com/a/735978/3339274 time = (datetime.datetime.now() - START_TIME).total_seconds() acc = [ IMU.readACCx() * IMU_ACC_COEFF, -IMU.readACCy() * IMU_ACC_COEFF, -IMU.readACCz() * IMU_ACC_COEFF ] # Compensate for gravitational acceleration. # TODO: Do we want to do some angle calculations to figure out how much to subtract from x, y, and z? acc[0] += 9.81 gyro = [ IMU.readGYRx() * IMU_GYRO_COEFF, IMU.readGYRy() * IMU_GYRO_COEFF, IMU.readGYRz() * IMU_GYRO_COEFF ] # TODO: Conversion needed? mag = [IMU.readMAGx(), IMU.readMAGy(), IMU.readMAGz()] baro_tuple = barometer.get_baro_values(i2c_bus) baro_p = baro_tuple[0] baro_temp = baro_tuple[1] return Timestep(time=time, acc=acc, gyro=gyro, mag=mag, baro_p=baro_p, baro_temp=baro_temp)
def do_GET(self): ''' handle the HTTP GET request ''' # first time through get create the controller if self.__device is None: self.__device = BMP280.BMP280() # Send response status code self.send_response(200) # Send headers self.send_header('Content-type', 'application/json') self.end_headers() result = [] sample = {} sample['type'] = self.__device.get_chip_type() sample['id'] = self.__device.get_uid() temperature,pressure = \ self.__device.retrieve_temperature_pressure() sample['temp_C'] = temperature sample['pressure'] = pressure sample['when'] = \ datetime.datetime.now(datetime.timezone.utc).isoformat() result.append(sample) # Write content as utf-8 data self.wfile.write(bytes(json.dumps(result, indent=1), "utf8")) return
def __init__(self, flight_state, time=None, acc=None, gyro=None, mag=None, baro=None): self.flight_state = flight_state if (time == None): if (IMUData.start_time == None): IMUData.start_time = datetime.datetime.now() self.time = (datetime.datetime.now() - IMUData.start_time).total_seconds() else: self.time = time if (acc == None): self.acc = [ IMU.readACCx() * IMU_ACC_COEFF, -IMU.readACCy() * IMU_ACC_COEFF, -IMU.readACCz() * IMU_ACC_COEFF ] # Compensate for gravitational acceleration. # TODO: Do we want to do some angle calculations to figure out how much to subtract from x, y, and z? self.acc[0] += 9.81 else: self.acc = acc if (gyro == None): self.gyro = [ IMU.readGYRx() * IMU_GYRO_COEFF, IMU.readGYRy() * IMU_GYRO_COEFF, IMU.readGYRz() * IMU_GYRO_COEFF ] else: self.gyro = gyro if (mag == None): # TODO: Conversion needed? self.mag = [IMU.readMAGx(), IMU.readMAGy(), IMU.readMAGz()] else: self.mag = mag if (baro == None): tuple = barometer.get_baro_values(i2c_bus) self.baro = [tuple[0], tuple[1]] else: self.baro = baro # Start events list off as empty. self.events = []
def main(): ssid = config.SSID password = config.WIFI_PASSWORD api_key = config.API_KEY mac_address = config.MAC_ADDRESS field = '2' # 2nd temperature sensor is field 2 wifitools.connect(ssid, password) time.sleep(5) i2c = machine.I2C(scl=machine.Pin(5), sda=machine.Pin(4)) sensor = BMP280.BMP280(i2c) for i in range(60 * 8): data = str(sensor.values[0]) try: wifitools.flaskiot_post(api_key, mac_address, field, data) except: pass time.sleep(60)
def bmp280_creerObjet(): """ Crée un objet capteur BMP280 (Mesure température et pression atmosphérique) """ global captTempIn518, sensor, isCaptBmp280ready errorMsg = "OK" dateHeureMes = datetime.now().strftime('%Y-%m-%d %H:%M:%S') try: sensor = BMP280.BMP280() except OSError as err : errorMsg = "OSError capteur BMP280 (Température et pression), vérifiez connectique ! " + str(err) except: errorMsg = "Error unknown création objet BMP280" if errorMsg == "OK": isCaptBmp280ready = True else: logger.error(errorMsg) errorMsg2 = errorMsg journal_ecrire_bdd(dateHeureMes, 'Error', captTempIn518["nom"], errorMsg2) journal_ecrire_bdd(dateHeureMes, 'Error', captPres518["nom"], errorMsg2)
def read_sensors(self): time = (datetime.datetime.now() - START_TIME).total_seconds() acc = [ IMU.readACCx() * IMU_ACC_COEFF, -IMU.readACCy() * IMU_ACC_COEFF, -IMU.readACCz() * IMU_ACC_COEFF ] # Compensate for gravitational acceleration. # TODO: Do we want to do some angle calculations to figure out how much to subtract from x, y, and z? acc[0] += 9.81 gyro = [ IMU.readGYRx() * IMU_GYRO_COEFF, IMU.readGYRy() * IMU_GYRO_COEFF, IMU.readGYRz() * IMU_GYRO_COEFF ] # TODO: Conversion needed? mag = [IMU.readMAGx(), IMU.readMAGy(), IMU.readMAGz()] self.filter.add_data(acc, gyro, mag) filtered = self.filter.update_filter() baro_tuple = barometer.get_baro_values(i2c_bus) baro_p = baro_tuple[0] baro_temp = baro_tuple[1] self.data = Timestep(time=time, acc=acc, gyro=gyro, mag=mag, acc_f=filtered[0], gyro_f=filtered[1], mag_f=filtered[2], baro_p=baro_p, baro_temp=baro_temp)
# ici, nous sommes en France donc format JJ/MM/AA HH:MM:SS locale.setlocale(locale.LC_TIME, '') # ----- Base de données : paramètres configuration ----- host = "217.128.90.45" port = 3306 user = "******" password = "******" database = "dbsupervis" # ----- Système embarqué et capteurs ----- # nom du capteur de temperature intérieur dans la bdd connecté au système embarqué # -> nom du champ "nom" de la table "capteur" SYSTEME_EMBARQUE = "raspi3-J518" # Création objet capteur température et pression (BMP280) ----- sensor = BMP280.BMP280() captTempIn518 = {} captTempIn518["nom"] = "Temperat_in_518" # capteur de température captTempIn518[ "corr"] = -1 # correctif, ce capteur retourne une valeur très souvent 1°C au-dessus de la valeur réelle captTempIn518[ "periodeSec"] = 1 # durée entre 2 mesures en secondes, cette valeur sera écrasée par la valeur stockée dans la bdd captPres518 = {} captPres518["nom"] = "Pression_518" # capteur de température captPres518[ "periodeSec"] = 1 # durée entre 2 mesures en secondes, cette valeur sera écrasée par la valeur stockée dans la bdd ETAT_INCONNU = 999 # contact dans un état inconnu ETAT_ON = 0 # contact fermé, porte fermée
jour_semaine = date_complete.weekday() liste_jours = [ "Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi", "Dimanche" ] # Mise en forme de la date du jour. Exemple : "Lundi 14/10/2019" Txt_date = str(liste_jours[jour_semaine]) + " " + str(jour) + "/" + str( mois) + "/" + str(annee) longueur_chaine = len(Txt_date) varY_date = int( (320 - (longueur_chaine * 13)) / 2) #Position Y de la date à afficher try: # création d'un objet basé sur la classe BMP280 capteur_bmp280 = BMP280.BMP280() # initialisation du capteur capteur_bmp280.init() # Lecture de la température + arrondi à un chiffre après la virgule temp_bmp280 = "T. int : " + str(round(capteur_bmp280.temperature(), 1)) + " °C" # lecture de la pression + arrondi à un chiffre après la virgule pression_bmp280 = "P : " + str(round(capteur_bmp280.pressure(), 1)) + " hPa" # pause time.sleep(1) except KeyboardInterrupt: GPIO.cleanup() print("Au revoir...")
#!/usr/bin/env python import serial import string import BMP280 as BMP280 #init sensor = BMP280.BMP280(mode=BMP280.BMP280_ULTRAHIGHRES) # initialize BMP ser = serial.Serial('/dev/ttyAMA0') # open serial port datavalid = 0 previous_time = 0 #find last file ID key = open('/home/ap/repos/gps-py/key','r') last_key = int(key.read()) key.close() #open last file and close the tags properly file = open('/var/www/html/tracklog'+str(last_key)+'.gpx','a') file.write(' </trkseg>\n') file.write(' </trk>\n') file.write('</gpx>\n') #increase file ID last_key += 1 key = open('/home/ap/repos/gps-py/key','w') key.write(str(last_key)) key.close() #open new file for current operation, write header file = open('/var/www/html/tracklog'+str(last_key)+'.gpx','w')
import bmp280 as BMP280 from time import sleep bmp = BMP280() while 1: print('temp = {}'.format(bmp.temp())) print('pressure = {}'.format(bmp.pressure())) sleep(1)
#!/usr/bin/env python # -*- coding: utf-8 -*- from BMP280 import * ps = BMP280() while True: ps_data = ps.get_data() print "Temperature:", ps_data['t'], "°C", "Pressure:", ps_data['p'], "Pa", "Altitude:", ps.get_altitude(ps_data['p']),"m" time.sleep(1)
file = csv.writer(open(folder_path + file_root + str(file_suffix) + ".csv", 'w'), delimiter=',') file.writerow(["time (s)", "accX", "accY", "accZ", "gyroX", "gyroY", "gyroZ", "magX", "magY", "magZ", "baroTemp", "baroPressure", "accX Filter", "accY Filter", "accZ Filter", "gyroX Filter", "gyroY Filter", "gyroZ Filter", "magX Filter", "magY Filter", "magZ Filter"]) IMU.detectIMU() # Detect if BerryIMUv1 or BerryIMUv2 is connected. IMU.initIMU() # Initialise the accelerometer, gyroscope and compass try: filter = mean_filter.IMUFilter(10) start_time = datetime.datetime.now() while True: baroValues = baro.get_baro_values(bus) # Units: g's acc = [IMU.readACCx() * IMU_ACC_COEFF, -IMU.readACCy() * IMU_ACC_COEFF, -IMU.readACCz() * IMU_ACC_COEFF] # Units: deg/s gyro = [IMU.readGYRx() * IMU_GYRO_COEFF, IMU.readGYRy() * IMU_GYRO_COEFF, IMU.readGYRz() * IMU_GYRO_COEFF] # Units: ? mag = [IMU.readMAGx(), IMU.readMAGy(), IMU.readMAGz()] filter.add_data(acc, gyro, mag) clean = filter.update_filter() print(form((datetime.datetime.now() - start_time).total_seconds(), 4) + DEL +
def __init__(self): sensor.__init__(self) self.unit = "kPa" self.bmp280 = BMP280.BMP180()