From cc8e811348a7752a9bb7b723c0bab1b6dd35e4bb Mon Sep 17 00:00:00 2001 From: Tero Paloheimo Date: Fri, 8 Nov 2024 22:00:41 +0200 Subject: [PATCH] docs: update examples (#256) Changes: * Remove adapter setting for asynchronous examples * Set BlueZ adapter for synchronous examples --- examples/find_tags.py | 4 ++++ examples/find_tags_async_bleak.py | 3 --- examples/get_async_bleak.py | 3 --- examples/get_ble_data.py | 4 ++++ examples/get_first_async_bleak.py | 3 --- examples/post_to_influxdb.py | 4 ++++ examples/post_to_mqtt.py | 0 examples/post_to_server.py | 3 +++ examples/print_to_screen.py | 2 ++ examples/print_to_screen_ruuvitag_class.py | 2 ++ examples/rx_async.py | 3 --- examples/send_updated_sync.py | 3 +++ 12 files changed, 22 insertions(+), 12 deletions(-) mode change 100755 => 100644 examples/post_to_mqtt.py diff --git a/examples/find_tags.py b/examples/find_tags.py index 6555ed1..6f6318c 100644 --- a/examples/find_tags.py +++ b/examples/find_tags.py @@ -2,6 +2,10 @@ Find RuuviTags """ +import os + +os.environ["RUUVI_BLE_ADAPTER"] = "bluez" + import ruuvitag_sensor.log from ruuvitag_sensor.ruuvi import RuuviTagSensor diff --git a/examples/find_tags_async_bleak.py b/examples/find_tags_async_bleak.py index 9e78ca7..496a16c 100644 --- a/examples/find_tags_async_bleak.py +++ b/examples/find_tags_async_bleak.py @@ -3,9 +3,6 @@ """ import asyncio -import os - -os.environ["RUUVI_BLE_ADAPTER"] = "bleak" import ruuvitag_sensor.log from ruuvitag_sensor.ruuvi import RuuviTagSensor diff --git a/examples/get_async_bleak.py b/examples/get_async_bleak.py index 40e65ff..49c1732 100644 --- a/examples/get_async_bleak.py +++ b/examples/get_async_bleak.py @@ -1,7 +1,4 @@ import asyncio -import os - -os.environ["RUUVI_BLE_ADAPTER"] = "bleak" import ruuvitag_sensor.log from ruuvitag_sensor.ruuvi import RuuviTagSensor diff --git a/examples/get_ble_data.py b/examples/get_ble_data.py index b4939b8..2ce2248 100644 --- a/examples/get_ble_data.py +++ b/examples/get_ble_data.py @@ -2,6 +2,10 @@ Get all BLE device broadcasts """ +import os + +os.environ["RUUVI_BLE_ADAPTER"] = "bluez" + import ruuvitag_sensor.log from ruuvitag_sensor.adapters.nix_hci import BleCommunicationNix diff --git a/examples/get_first_async_bleak.py b/examples/get_first_async_bleak.py index 0ecc548..e33af9b 100644 --- a/examples/get_first_async_bleak.py +++ b/examples/get_first_async_bleak.py @@ -1,7 +1,4 @@ import asyncio -import os - -os.environ["RUUVI_BLE_ADAPTER"] = "bleak" import ruuvitag_sensor.log from ruuvitag_sensor.decoder import Df5Decoder diff --git a/examples/post_to_influxdb.py b/examples/post_to_influxdb.py index 3373722..746630f 100644 --- a/examples/post_to_influxdb.py +++ b/examples/post_to_influxdb.py @@ -29,8 +29,12 @@ Add new graph to dashboard """ +import os + from influxdb import InfluxDBClient +os.environ["RUUVI_BLE_ADAPTER"] = "bluez" + from ruuvitag_sensor.ruuvi import RuuviTagSensor client = InfluxDBClient(host="localhost", port=8086, database="ruuvi") diff --git a/examples/post_to_mqtt.py b/examples/post_to_mqtt.py old mode 100755 new mode 100644 diff --git a/examples/post_to_server.py b/examples/post_to_server.py index aa69e18..54875f1 100644 --- a/examples/post_to_server.py +++ b/examples/post_to_server.py @@ -5,10 +5,13 @@ Requests - pip install requests """ +import os from urllib.parse import quote import requests +os.environ["RUUVI_BLE_ADAPTER"] = "bluez" + from ruuvitag_sensor.ruuvi import RuuviTagSensor macs = ["F4:A5:74:89:16:57", "CC:2C:6A:1E:59:3D", "BB:2C:6A:1E:59:3D"] diff --git a/examples/print_to_screen.py b/examples/print_to_screen.py index 27ea373..16d2796 100644 --- a/examples/print_to_screen.py +++ b/examples/print_to_screen.py @@ -15,6 +15,8 @@ import os from datetime import datetime +os.environ["RUUVI_BLE_ADAPTER"] = "bluez" + from ruuvitag_sensor.ruuvi import RuuviTagSensor # Change here your own device's mac-address diff --git a/examples/print_to_screen_ruuvitag_class.py b/examples/print_to_screen_ruuvitag_class.py index b54f9fe..5605acc 100644 --- a/examples/print_to_screen_ruuvitag_class.py +++ b/examples/print_to_screen_ruuvitag_class.py @@ -20,6 +20,8 @@ import time from datetime import datetime +os.environ["RUUVI_BLE_ADAPTER"] = "bluez" + from ruuvitag_sensor.ruuvitag import RuuviTag # Change here your own device's mac-address diff --git a/examples/rx_async.py b/examples/rx_async.py index 777f26d..dd7a334 100644 --- a/examples/rx_async.py +++ b/examples/rx_async.py @@ -1,7 +1,4 @@ import asyncio -import os - -os.environ["RUUVI_BLE_ADAPTER"] = "bleak" from ruuvitag_sensor.ruuvi_rx import RuuviTagReactive diff --git a/examples/send_updated_sync.py b/examples/send_updated_sync.py index eeda3af..96d2e06 100644 --- a/examples/send_updated_sync.py +++ b/examples/send_updated_sync.py @@ -12,11 +12,14 @@ """ import copy +import os from datetime import datetime, timedelta from urllib.parse import quote import requests +os.environ["RUUVI_BLE_ADAPTER"] = "bluez" + from ruuvitag_sensor.ruuvi import RuuviTagSensor all_data = {}