次のページを参考にしました。
データ投入処理
Ubuntu 22.10 でのライブラリーのインストール
sudo apt install python3-influxdb
プログラム
influxdb_insert.py
#! /usr/bin/python
#
# influxdb_insert.py
#
# Dec/07/2022
# ------------------------------------------------------------------
import sys
import time
from influxdb import InfluxDBClient
# ------------------------------------------------------------------
def insert_proc(temperature_in):
import_array = [
{
"fields" : {
"IDX" : 1,
"temperature" : temperature_in,
},
"measurement" : "Data"
}
]
client.write_points(import_array)
#
# ------------------------------------------------------------------
sys.stderr.write("*** 開始 ***\n")
client = InfluxDBClient('example.com', 8086,"","", 'example')
dbs = client.get_list_database()
sample_db = {'name' : 'example'}
if sample_db not in dbs:
client.create_database('example')
temperatures=[20.3,21.4,22.5,23.6,24.2]
for value in temperatures:
print(value)
insert_proc(value)
#
time.sleep(1.0)
#
sys.stderr.write("*** 終了 ***\n")
# ------------------------------------------------------------------