### Install aranet4 Python Package Source: https://github.com/anrijs/aranet4-python/blob/master/README.md Install the aranet4 library and its dependencies using pip. ```bash pip3 install aranet4 ``` -------------------------------- ### MQTT Topic Structure Example Source: https://github.com/anrijs/aranet4-python/blob/master/examples/mqtt/README.md When the TOPIC_BASE is set to "bedroom/aranet4/", sensor data will be published to specific topics under this base. This shows the expected topic structure for each sensor reading. ```text /bedroom/aranet4/temperature /bedroom/aranet4/pressure /bedroom/aranet4/humidity /bedroom/aranet4/co2 /bedroom/aranet4/battery ``` -------------------------------- ### Automate Data Collection with Crontab Source: https://github.com/anrijs/aranet4-python/blob/master/examples/mqtt/README.md This example shows how to set up a cron job to automatically run the MQTT publishing script at regular intervals. Ensure the script path and device address are correctly specified. ```bash crontab -e ``` ```bash * * * * * python /PATH_TO_THIS_FILE/publish.py XX:XX:XX:XX:XX:XX HOSTNAME bedroom/ar4/ ``` -------------------------------- ### Automate Data Collection with Crontab Source: https://github.com/anrijs/aranet4-python/blob/master/examples/influx/README.md Schedule the influx.py script to run automatically at regular intervals using crontab. This example runs the script every minute. ```bash crontab -e ``` ```bash * * * * * python /PATH_TO_THIS_REPO/influx.py XX:XX:XX:XX:XX:XX anrijsAR4 ``` -------------------------------- ### Get Current Aranet4 Readings Source: https://github.com/anrijs/aranet4-python/blob/master/README.md Fetches and prints the current CO2, temperature, humidity, and pressure readings from a specified Aranet4 device. Ensure the device MAC address is correctly configured. ```python import aranet4 device_mac = "XX:XX:XX:XX:XX:XX" current = aranet4.client.get_current_readings(device_mac) print("co2 reading:", current.co2) print("Temperature:", current.temperature) print("Humidity:", current.humidity) print("Pressure:", current.pressure) ``` -------------------------------- ### Get Logged Readings Source: https://github.com/anrijs/aranet4-python/blob/master/README.md Fetches historical sensor data stored on the Aranet4 device, with options to filter the data. ```APIDOC ## get_all_records(mac_address: str, entry_filter: dict) ### Description Get stored datapoints from device. Apply any filters if required. ### Method ```python aranet4.client.get_all_records(device_mac, entry_filter={"humi": False, "pres": False}) ``` ### Parameters #### Path Parameters - **mac_address** (str) - Required - The MAC address of the Aranet4 device. #### Query Parameters - **entry_filter** (dict) - Optional - A dictionary to filter the records. Possible keys: - `last` (int): Get the last n entries. - `start` (datetime): Get entries after the specified time. - `end` (datetime): Get entries before the specified time. - `temp` (bool): Include temperature data points (default: True). - `humi` (bool): Include humidity data points (default: True). - `pres` (bool): Include pressure data points (default: True). - `co2` (bool): Include CO2 data points (default: True). ### Response #### Success Response Returns a **Record** object containing historical data. ```python class Record: name: str version: str records_on_device: int filter: Filter value: List[RecordItem] class RecordItem: date: datetime temperature: float humidity: int pressure: float co2: int class Filter: begin: int end: int incl_temperature: bool incl_humidity: bool incl_pressure: bool incl_co2: bool ``` ``` -------------------------------- ### Get Current Readings Source: https://github.com/anrijs/aranet4-python/blob/master/README.md Retrieves the most recent sensor measurements (CO2, temperature, humidity, pressure) from the Aranet4 device. ```APIDOC ## get_current_readings(mac_address: str) ### Description Get current measurements from device. ### Method ```python aranet4.client.get_current_readings(device_mac) ``` ### Parameters #### Path Parameters - **mac_address** (str) - Required - The MAC address of the Aranet4 device. ### Response #### Success Response Returns a **CurrentReading** object containing the latest sensor data. ```python class CurrentReading: name: str version: str temperature: float humidity: int pressure: float co2: int battery: int status: int interval: int ago: int stored: int ``` ``` -------------------------------- ### Get Current Aranet4 Readings Source: https://github.com/anrijs/aranet4-python/blob/master/README.md Fetch and display the current sensor readings from a specified Aranet4 device using its Bluetooth address. ```text aranetctl XX:XX:XX:XX:XX:XX ``` ```text -------------------------------------- Connected: Aranet4 00000 | v0.3.1 Updated 51 s ago. Intervals: 60 s 5040 total readings -------------------------------------- CO2: 904 ppm Temperature: 19.9 C Humidity: 51 % Pressure: 997.0 hPa Battery: 96 % Status Display: GREEN ``` -------------------------------- ### Get Logged Aranet4 Readings Source: https://github.com/anrijs/aranet4-python/blob/master/README.md Retrieves all historical sensor data from an Aranet4 device, with options to filter out humidity and pressure readings. It then prints the date, CO2, and temperature for each entry. Requires the device MAC address. ```python import aranet4 device_mac = "XX:XX:XX:XX:XX:XX" history = aranet4.client.get_all_records( device_mac, entry_filter={"humi": False, "pres": False} ) print(f"{ 'Date':^20} | {'CO2':^10} | {'Temperature':^10} ") for entry in history.value: print(f"{entry.date.isoformat():^20} | {entry.co2:^10} | {entry.temperature:^10})" ``` -------------------------------- ### Aranetctl Command Line Help Source: https://github.com/anrijs/aranet4-python/blob/master/README.md Displays the help message for the `aranetctl` command-line tool, outlining all available arguments and options for interacting with Aranet devices. ```text usage: aranetctl.py [-h] [--scan] [-u URL] [-r] [-s DATE] [-e DATE] [-o FILE] [-w] [-l COUNT] [--xt] [--xh] [--xp] [--xc] [--set-interval MINUTES] [--set-integrations {on,off}] [--set-range {normal,extended}] [device_mac] positional arguments: device_mac Aranet Bluetooth Address options: -h, --help show this help message and exit --scan Scan for Aranet devices -r, --records Fetch historical log records Options for current reading: -u URL, --url URL Remote url for current value push Filter History Log Records: -s DATE, --start DATE Records range start (UTC time, example: 2019-09-29T14:00:00 -e DATE, --end DATE Records range end (UTC time, example: 2019-09-30T14:00:00 -o FILE, --output FILE Save records to a file -w, --wait Wait until new data point available -l COUNT, --last COUNT Get last records --xt Don't get temperature records --xh Don't get humidity records --xp Don't get pressure records --xc Don't get co2 records Change device settings: --set-interval MINUTES Change update interval --set-integrations {on,off} Toggle Smart Home Integrations --set-range {normal,extended} Change bluetooth range ``` -------------------------------- ### Run influx.py for Current Readings Source: https://github.com/anrijs/aranet4-python/blob/master/examples/influx/README.md Use this command to send current sensor readings to InfluxDB. Ensure DEVICE_ADDRESS and DEVICE_NAME are correctly set. ```bash python influx.py DEVICE_ADDRESS DEVICE_NAME ``` -------------------------------- ### Publish Aranet4 Data to MQTT Broker Source: https://github.com/anrijs/aranet4-python/blob/master/examples/mqtt/README.md Use this command to send data from an Aranet4 device to an MQTT broker. Specify the device address, MQTT broker hostname, and a base topic for the data. Optional arguments allow for specifying the broker port, username, and password. ```bash python publish.py DEVICE_ADDRESS HOSTNAME TOPIC_BASE [OPTIONS] ``` -------------------------------- ### Run influx.py for History Data Source: https://github.com/anrijs/aranet4-python/blob/master/examples/influx/README.md Use this command to retrieve and send historical sensor data to InfluxDB. The optional -l flag limits the number of records. ```bash python influx.py DEVICE_ADDRESS DEVICE_NAME -h [-l ] ``` -------------------------------- ### Import History Files with import.py Source: https://github.com/anrijs/aranet4-python/blob/master/examples/influx/README.md Use this script to import historical data files generated by aranet.py into InfluxDB. Provide the FILE_NAME and DEVICE_NAME. ```bash python import.py FILE_NAME DEVICE_NAME ``` -------------------------------- ### Fetch Full Aranet Device History Log Source: https://github.com/anrijs/aranet4-python/blob/master/README.md Retrieve and display all historical log records from an Aranet device to the console. This command requires the device's Bluetooth MAC address and the `-r` flag. ```shell aranetctl XX:XX:XX:XX:XX:XX -r ``` ```shell ------------------------------------------------------------- Device Name : Aranet4 00000 Device Version : v0.3.1 ------------------------------------------------------------- id | date | co2 | temp | hum | pressure | ------------------------------------------------------------- 1 | 2022-02-18T14:15:44 | 844 | 21.8 | 50 | 985.6 | 2 | 2022-02-18T14:20:44 | 846 | 21.8 | 50 | 985.9 | 3 | 2022-02-18T14:25:44 | 843 | 22.0 | 50 | 986.4 | 4 | 2022-02-18T14:30:44 | 881 | 22.1 | 50 | 986.4 | 5 | 2022-02-18T14:35:44 | 854 | 22.1 | 50 | 987.3 | 6 | 2022-02-18T14:40:44 | 867 | 22.2 | 50 | 987.5 | 7 | 2022-02-18T14:45:44 | 883 | 22.1 | 50 | 988.1 | 8 | 2022-02-18T14:50:44 | 921 | 22.1 | 50 | 988.6 | 9 | 2022-02-18T14:55:44 | 930 | 22.0 | 50 | 989.1 | 10 | 2022-02-18T15:00:44 | 954 | 22.0 | 50 | 989.5 | ------------------------------------------------------------- ``` -------------------------------- ### Scan for Aranet Devices Source: https://github.com/anrijs/aranet4-python/blob/master/README.md Use the `--scan` option with `aranetctl` to discover nearby Aranet devices and view their basic information. ```text $ aranetctl --scan ``` ```text ======================================= Name: Aranet4 00001 Address: AA:BB:CC:DD:EE:FF RSSI: -83 dBm --------------------------------------- CO2: 484 ppm Temperature: 20.9 °C Humidity: 43 % Pressure: 1024.8 hPa Battery: 3 % Status Display: GREEN Age: 9/60 ``` -------------------------------- ### Upload History to InfluxDB Source: https://github.com/anrijs/aranet4-python/blob/master/examples/influx/README.md Manually upload historical data to InfluxDB using the influx.py script with the -h flag. The -l flag can limit the number of records uploaded. ```bash python influx.py XX:XX:XX:XX:XX:XX anrijsAR4 -h ``` -------------------------------- ### Save Aranet Device History to CSV Source: https://github.com/anrijs/aranet4-python/blob/master/README.md Save the historical log records from an Aranet device to a CSV file. Specify the output file name using the `-o` option along with the `-r` flag. ```shell aranetctl XX:XX:XX:XX:XX:XX -r -o aranet4.csv ``` ```text date,co2,temperature,humidity,pressure 2022-02-18 10:05:47,1398,23.2,53,986.6 2022-02-18 10:10:47,1155,23.1,50,986.3 ``` -------------------------------- ### Aranet4 Record Data Structure Source: https://github.com/anrijs/aranet4-python/blob/master/README.md Defines the structure of the Record object returned by `get_all_records`. This object contains historical sensor data and metadata about the retrieved records. ```python class Record: name: str version: str records_on_device: int filter: Filter value: List[RecordItem] = field(default_factory=list) ``` -------------------------------- ### Aranet4 RecordItem Data Structure Source: https://github.com/anrijs/aranet4-python/blob/master/README.md Represents a single historical data point within the Record object. Includes the timestamp and sensor measurements for that point. ```python class RecordItem: date: datetime temperature: float humidity: int pressure: float co2: int ``` -------------------------------- ### Aranet4 CurrentReading Data Structure Source: https://github.com/anrijs/aranet4-python/blob/master/README.md Defines the structure of the CurrentReading object returned by `get_current_readings`. This object contains real-time sensor data and device status information. ```python class CurrentReading: name: str = "" version: str = "" temperature: float = -1 humidity: int = -1 pressure: float = -1 co2: int = -1 battery: int = -1 status: int = -1 interval: int = -1 ago: int = -1 stored: int = -1 ``` -------------------------------- ### Aranet4 Filter Data Structure Source: https://github.com/anrijs/aranet4-python/blob/master/README.md Represents the filter criteria applied when retrieving historical records. This structure details which sensor types were included in the query. ```python class Filter: begin: int end: int incl_temperature: bool incl_humidity: bool incl_pressure: bool incl_co2: bool ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.