smartgadget.sht3x module

class smartgadget.sht3x.SHT3X(device, interface=None)[source]

Bases: SmartGadget

Base class for a Smart Gadget.

Parameters
  • device – A MAC address as a str or a ScanEntry object.

  • interface (int, optional) – The Bluetooth interface to use for the connection. For example, 0 or None means /dev/hci0, 1 means /dev/hci1.

APPEARANCE_HANDLE = 5
BATTERY_LEVEL_HANDLE = 29
DEVICE_NAME = 'Smart Humigadget'
DEVICE_NAME_HANDLE = 3
FIRMWARE_REVISION_STRING_HANDLE = 24
HARDWARE_REVISION_STRING_HANDLE = 22
HUMIDITY_CHARACTERISTIC_UUID = <bluepy.btle.UUID object>
HUMIDITY_HANDLE = 50
HUMIDITY_NOTIFICATION_HANDLE = 52
HUMIDITY_SERVICE_UUID = <bluepy.btle.UUID object>
LOGGER_INTERVAL_MS_CHARACTERISTIC_UUID = <bluepy.btle.UUID object>
LOGGER_INTERVAL_MS_HANDLE = 46
LOGGER_SERVICE_UUID = <bluepy.btle.UUID object>
MANUFACTURER_NAME_STRING_HANDLE = 16
MODEL_NUMBER_STRING_HANDLE = 18
NEWEST_TIMESTAMP_MS_CHARACTERISTIC_UUID = <bluepy.btle.UUID object>
NEWEST_TIMESTAMP_MS_HANDLE = 39
OLDEST_TIMESTAMP_MS_CHARACTERISTIC_UUID = <bluepy.btle.UUID object>
OLDEST_TIMESTAMP_MS_HANDLE = 36
PERIPHERAL_PREFERRED_CONNECTION_PARAMETERS_HANDLE = 7
SERIAL_NUMBER_STRING_HANDLE = 20
SOFTWARE_REVISION_STRING_HANDLE = 26
START_LOGGER_DOWNLOAD_CHARACTERISTIC_UUID = <bluepy.btle.UUID object>
START_LOGGER_DOWNLOAD_HANDLE = 42
SYNC_TIME_MS_CHARACTERISTIC_UUID = <bluepy.btle.UUID object>
SYNC_TIME_MS_HANDLE = 33
SYSTEM_ID_HANDLE = 14
TEMPERATURE_CHARACTERISTIC_UUID = <bluepy.btle.UUID object>
TEMPERATURE_HANDLE = 55
TEMPERATURE_NOTIFICATION_HANDLE = 57
TEMPERATURE_SERVICE_UUID = <bluepy.btle.UUID object>
battery() int[source]

Returns the battery level.

Returns

float – The current battery level [%].

disable_humidity_notifications()[source]

Disable humidity notifications.

disable_temperature_notifications()[source]

Disable temperature notifications.

enable_humidity_notifications()[source]

Enable humidity notifications.

enable_temperature_notifications()[source]

Enable temperature notifications.

fetch_logged_data(*, enable_temperature=True, enable_humidity=True, sync=None, oldest=None, newest=None, as_datetime=False) Tuple[list, list][source]

Returns the logged temperature and humidity values.

The maximum number of temperature and humidity values that can be logged is 15872 (for each).

It can take approximately 80 seconds to fetch the maximum amount of data that can be saved in the internal memory of the Smart Gadget.

The data is returned as an N x 2 list:

Parameters
Returns

  • list – The logged temperature values [degree C].

  • list – The logged humidity values [%RH].

humidity() float[source]

Returns the current humidity.

Returns

float – The current humidity [%RH].

humidity_notifications_enabled() bool[source]

Returns whether humidity notifications are enabled.

Returns

bool – Whether humidity notifications are enabled.

info() dict[source]

Returns all available information from the Smart Gadget.

Returns

dict – Includes information such as the firmware, hardware and software version numbers, the battery level, the temperature, humidity and dew point values and the timing information about the data logger.

logger_interval() int[source]

Returns the data logger interval.

Returns

int – The time between log events [milliseconds].

newest_timestamp() int[source]

Returns the newest timestamp of the data logger.

Returns

int – The newest timestamp [milliseconds]. See also milliseconds_to_datetime().

oldest_timestamp() int[source]

Returns the oldest timestamp of the data logger.

Returns

int – The oldest timestamp [milliseconds]. See also milliseconds_to_datetime().

set_logger_interval(milliseconds)[source]

Set the data logger interval.

Attention

This will clear all values that are currently saved in memory.

Parameters

milliseconds (int) – The time between log events [milliseconds].

set_newest_timestamp(timestamp)[source]

Set the newest timestamp of the data logger.

Parameters

timestamp – Can be a datetime object, an ISO-8601 formatted str, a float in seconds, or an int in milliseconds.

set_oldest_timestamp(timestamp)[source]

Set the oldest timestamp of the data logger.

Parameters

timestamp – Can be a datetime object, an ISO-8601 formatted str, a float in seconds, or an int in milliseconds.

set_sync_time(timestamp=None)[source]

Sync the timestamps of the data logger.

Parameters

timestamp – Can be a datetime object, an ISO-8601 formatted str, a float in seconds, or an int in milliseconds. If None then uses the current time of the Raspberry Pi.

temperature() float[source]

Returns the current temperature.

Returns

float – The current temperature [degree C].

temperature_humidity() Tuple[float, float][source]

Returns the current temperature and humidity.

Returns

  • float – The current temperature [degree C].

  • float – The current humidity [%RH].

temperature_notifications_enabled() bool[source]

Returns whether temperature notifications are enabled.

Returns

bool – Whether temperature notifications are enabled.

class smartgadget.sht3x.SHT3XService(interface=None)[source]

Bases: SmartGadgetService

The Service for a SHT3X Smart Gadget.

Parameters

interface (int, optional) – The Bluetooth interface to use for the connection. For example, 0 or None means /dev/hci0, 1 means /dev/hci1.

disable_humidity_notifications(mac_address)[source]

Disable humidity notifications.

Parameters

mac_address (str) – The MAC address of the Smart Gadget.

disable_temperature_notifications(mac_address)[source]

Disable temperature notifications.

Parameters

mac_address (str) – The MAC address of the Smart Gadget.

enable_humidity_notifications(mac_address)[source]

Enable humidity notifications.

Parameters

mac_address (str) – The MAC address of the Smart Gadget.

enable_temperature_notifications(mac_address)[source]

Enable temperature notifications.

Parameters

mac_address (str) – The MAC address of the Smart Gadget.

fetch_logged_data(mac_address, *, enable_temperature=True, enable_humidity=True, sync=None, oldest=None, newest=None, as_datetime=False, num_iterations=1) Tuple[list, list][source]

Returns the logged temperature and humidity values.

The maximum number of temperature and humidity values that can be logged is 15872 (for each).

It can take approximately 80 seconds per iteration to fetch the maximum amount of data that can be saved in the internal memory of the Smart Gadget.

The data is returned as an N x 2 list:

  • The first column is the timestamp \(\rightarrow\) int or datetime

  • The second column is the value \(\rightarrow\) float or None (if there was an error downloading the value)

Parameters
  • mac_address (str) – The MAC address of the Smart Gadget.

  • enable_temperature (bool, optional) – Whether to download the temperature values.

  • enable_humidity (bool, optional) – Whether to download the humidity values.

  • sync – Passed to SHT3X.set_sync_time().

  • oldest – Passed to SHT3X.set_oldest_timestamp().

  • newest – Passed to SHT3X.set_newest_timestamp().

  • as_datetime (bool) –

    If True then return the timestamps as datetime objects otherwise return the timestamps as an int in milliseconds. If you are calling this method from a remote computer (i.e., you are not running your script on a Raspberry Pi) then you must keep this value as False otherwise you will get the following error:

    TypeError: Object of type datetime is not JSON serializable

    You can convert the timestamps after getting the data from the Raspberry Pi by calling milliseconds_to_datetime() on each timestamp.

  • num_iterations (int, optional) – Bluetooth does not guarantee that all data packets are received by default, its connection principles are equivalent to the same ones as UDP for computer networks. You can specify the number of times to download the data to fix missing packets.

Returns

  • list – The logged temperature values [degree C].

  • list – The logged humidity values [%RH].

humidity_notifications_enabled(mac_address) bool[source]

Returns whether humidity notifications are enabled.

Parameters

mac_address (str) – The MAC address of the Smart Gadget.

Returns

bool – Whether humidity notifications are enabled.

logger_interval(mac_address) int[source]

Returns the data logger interval.

Parameters

mac_address (str) – The MAC address of the Smart Gadget.

Returns

int – The time between log events [milliseconds].

newest_timestamp(mac_address) int[source]

Returns the newest timestamp of the data logger.

Parameters

mac_address (str) – The MAC address of the Smart Gadget.

Returns

int – The newest timestamp [milliseconds]. See also milliseconds_to_datetime().

oldest_timestamp(mac_address) int[source]

Returns the oldest timestamp of the data logger.

Parameters

mac_address (str) – The MAC address of the Smart Gadget.

Returns

int – The oldest timestamp [milliseconds]. See also milliseconds_to_datetime().

set_logger_interval(mac_address, milliseconds)[source]

Set the data logger interval.

Attention

This will clear all values that are currently saved in memory.

Parameters
  • mac_address (str) – The MAC address of the Smart Gadget.

  • milliseconds (int) – The time between log events [milliseconds].

set_newest_timestamp(mac_address, timestamp)[source]

Set the newest timestamp of the data logger.

Parameters
  • mac_address (str) – The MAC address of the Smart Gadget.

  • timestamp – Can be a datetime object, an ISO-8601 formatted str, a float in seconds, or an int in milliseconds.

set_oldest_timestamp(mac_address, timestamp)[source]

Set the oldest timestamp of the data logger.

Parameters
  • mac_address (str) – The MAC address of the Smart Gadget.

  • timestamp – Can be a datetime object, an ISO-8601 formatted str, a float in seconds, or an int in milliseconds.

set_sync_time(mac_address, timestamp=None)[source]

Sync the timestamps of the data logger.

Parameters
  • mac_address (str) – The MAC address of the Smart Gadget.

  • timestamp – Can be a datetime object, an ISO-8601 formatted str, a float in seconds, or an int in milliseconds. If None then uses the current time of the Raspberry Pi.

temperature_notifications_enabled(mac_address) bool[source]

Returns whether temperature notifications are enabled.

Parameters

mac_address (str) – The MAC address of the Smart Gadget.

Returns

bool – Whether temperature notifications are enabled.