IOT Foundation (iotf) サービスにバインドされた Node-RED アプリケーションがあります。デバイスからイベントを受信し、適切に処理できます。
ただし、コマンドをデバイスに送り返すことに関心があり、いくつかの問題があります。デバイスには何も表示されていませんが、ノードでIOTFを作成することで、コマンドがiotfを通過していることを確認できます。
次のコードがうまく機能するため、純粋なpythonを使用してiotfを通過するコマンドを確実に取得できます。
クライアントコード:
#!/usr/bin/python
import ibmiotf.device
from time import sleep
options = {
"org": "cgmncc",
"type": "table",
"id": "b827eb764b7a",
"auth-method": "token",
"auth-token": "redacted"
}
def myCommandCallback(cmd):
print('inside command callback')
print cmd
def main():
client = ibmiotf.device.Client(options)
client.connect()
client.commandCallback = myCommandCallback
while True:
sleep(1)
if __name__ == "__main__":
main()
アプリケーション コード:
#!/usr/bin/python
import ibmiotf.application
options = {
"org": "redacted",
"id": "python app",
"auth-method": "apikey",
"auth-key": "redacted",
"auth-token": "redacted"
}
try:
client = ibmiotf.application.Client(options)
client.connect()
client.publishCommand('table', 'b827eb764b7a', 'test')
client.disconnect()
except ibmiotf.ConnectionException as e:
print e
アプリケーション コードを実行すると、次の出力が表示されます。
root@raspberrypi ~ # ./app.py
inside command callback
<ibmiotf.device.Command instance at 0x14e8490>
以下に示すように Node-RED iotf 出力ノードを構成しましたが、フローをトリガーすると、コマンドのコールバック関数がトリガーされません!
タイムスタンプ トリガーを使用してコマンドを起動しようとしているか、出力ノード自体を構成した方法に何か問題があるのではないかと考えています。提案やアドバイスをいただければ幸いです。