smartgadget.sht3x module¶
- class smartgadget.sht3x.SHT3X(device, interface=None)[source]¶
Bases:
SmartGadget
Base class for a Smart Gadget.
- Parameters
- 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>¶
- 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
:The first column is the timestamp \(\rightarrow\)
int
ordatetime
The second column is the value \(\rightarrow\)
float
orNone
(if there was an error downloading the value, seeSHT3XService.fetch_logged_data()
for more details)
- Parameters
enable_temperature (
bool
, optional) – Whether to download the temperature values.enable_humidity (
bool
, optional) – Whether to download the humidity values.sync – Passed to
set_sync_time()
.oldest – Passed to
set_oldest_timestamp()
.newest – Passed to
set_newest_timestamp()
.as_datetime (
bool
) – IfTrue
then return the timestamps asdatetime
objects otherwise return the timestamps as anint
in milliseconds.
- Returns
- 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 alsomilliseconds_to_datetime()
.
- oldest_timestamp() int [source]¶
Returns the oldest timestamp of the data logger.
- Returns
int
– The oldest timestamp [milliseconds]. See alsomilliseconds_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].
- temperature() float [source]¶
Returns the current temperature.
- Returns
float
– The current temperature [degree C].
- class smartgadget.sht3x.SHT3XService(interface=None)[source]¶
Bases:
SmartGadgetService
The
Service
for aSHT3X
Smart Gadget.- Parameters
interface (
int
, optional) – The Bluetooth interface to use for the connection. For example, 0 orNone
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
ordatetime
The second column is the value \(\rightarrow\)
float
orNone
(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 asdatetime
objects otherwise return the timestamps as anint
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 asFalse
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
- humidity_notifications_enabled(mac_address) bool [source]¶
Returns whether humidity notifications are enabled.
- 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 alsomilliseconds_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 alsomilliseconds_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.