1

DHT22センサー用に存在する定義済みコードの一部を変更しようとしています。値とセンサーが出力する値Adafruit's DHT_Driverに対応する配列を返すように変更したいと思います。Python スニペットで出力配列を利用できるように、この変更を加えたいと思います。つまり、出力配列値を使用してデータをフィードにアップロードしたいと考えています。TemperatureHumidityXively

これに似たものを探しています...

#!/usr/bin/env python
import time
import os
import eeml

# Xively variables specific to my account.
API_KEY = 'API Key Here'
FEED = 'FEED # Here'
API_URL = '/v2/feeds/{feednum}.xml' .format(feednum = FEED)

# Continuously read data from the DHT22 sensor and upload
# the results to the Xively feed. 
while True:
    # Read the data from the sensor.
    sensorData = .... // Call on the main method within the DHT_Driver.c file
    temp_C = sensorData[0]
    humidity = sensorData[1]

    if DEBUG:
        print("sensorData:\t", sensorData)
        print("\n")

    if LOGGER:
        # Initialize the users Xively account.
        pac = eeml.Pachube(API_URL, API_KEY)

        # Prepare the data to be uploaded to the Xively
        # account.
        # temp_C & humidity are extracted from their indices
        # above.
        pac.update([eeml.Data(0, temp_C, unit=eeml.Celsius())])
        pac.update([eeml.Data(1, humidity, unit=eeml.%())])

        # Upload the data to the Xively account.
        pac.put()

        # Wait 30 seconds to avoid flooding the Xively feed.
        time.sleep(30)

センサーからの温度値と湿度値の取得に関するフィードバックが必要です。CPython はセンサーからのデータを処理するのに十分な速度ではないため、利用する必要があります。理想的には、2 つの値を含む配列を返すだけで、次のように値にアクセスできます。

temp_C = sensorData[0]
humidity = sensorData[1]

また、この Python スニペット内で、DHT_Driver.c ファイル内のメイン メソッドを呼び出すとしたら、これは Python インタープリターによって制限されますか (つまり、C ベースのプログラムは Python ベースのプログラムと同様のパフォーマンスで実行されますか)?

私は Python に非常に不慣れで、C を始めたばかりなので、何か提案や肯定的な批判があれば、気軽に声をかけてください。

4

1 に答える 1

0

まず、Xively が提供する公式の Python モジュールを使用するようにコードを更新する必要があります。

#!/usr/bin/env python
import time
import os
import xively

# Xively variables specific to my account.
API_KEY = ....
FEED_ID = ....


# Continuously read data from the DHT22 sensor and upload
# the results to the Xively feed. 
while True:

    # Initialize Xively library and fetch the feed
    feed = xively.XivelyAPIClient(API_KEY).feeds.get(FEED_ID)

    feed.datastreams = [
        xively.Datastream(id='tempertature', current_value=getTemperature()),
        xively.Datastream(id='humidity', current_value=getHumidity()),
    ]
    # Upload the data into the Xively feed
    feed.update()

    # Wait 30 seconds to avoid flooding the Xively feed.
    time.sleep(30)

センサードライバーに関しては、AirPiを見てみましょう。

于 2013-08-23T10:58:04.943 に答える