# Publishing-related constants.
PUBLISH_INTERVAL = 60 # seconds
PROJECT_ID = '<YOUR_PROJECT_ID>'
DEVICE_ID = '<YOUR_EMULATED_DEVICE_ID>'
# Authenticate the disruptive package.
dt.default_auth = dt.Auth.service_account(
key_id='YOUR_SERVICE_ACCOUNT_KEY_ID>',
secret='YOUR_SERVICE_ACCOUNT_SECRET>',
email='<YOUR_SERVICE_ACCOUNT_EMAIL>',
# Create sensor object, communicating over the board's default I2C bus.
bme680 = adafruit_bme680.Adafruit_BME680_I2C(i2c)
# Set sea-level barometric pressure to match your location.
bme680.sea_level_pressure = 1006 # hPa
# Initialize a buffer list to hold values between publishing.
# Start a timer for tracking publishing interval.
# Suspend in an infinite loop, exiting at KeyboardInterrupt.
# Read and append barometric pressure reading from bme680.
pressures.append(bme680.pressure)
# Print new pressure value to stdout.
print(f'Pressure: {pressures[-1]:.2f}')
if time.time() - t0 > PUBLISH_INTERVAL:
# Have pressure be the median buffer value.
pressure = statistics.median(pressures)
# Publish a new event for the emulated device.
dt.Emulator.publish_event(
data=dt.events.Temperature(pressure),
# Reset timer, clear list, and tell stdout what you did.
print(f'Published event with value {pressure:.2f}.')
except KeyboardInterrupt: