Influxdb client for data import

Hi

I’m setting up a routine which is writing data from an external source into the influx db on my raspberry with an python script.
Therefore i use the pandas module to import the external data source and then work with the dateframe afterwards. In order to write the dataframe into the influxdb I try to use the influxdb client which isn’t installed on the setup I guess. How can I acces to the influxdb client in order that the script as follow can write the data into the DB? Thx for your help!

Blockquote
import sys
import pandas as pd
import re
from Influxdb import InfluxDBClient
client = InfluxDBClient(host=‘localhost’, port=8086, username=‘admin’, password=’’)
df = pd.read_csv(’/etc/openhab2/scripts/grafiek’+room+’.dat’,
header=None,
skiprows = 1,
encoding=‘ISO-8859-1’,
names=[‘datum’,‘Lufttemperatur’,‘Feuchtigkeit Temperatur’,‘Kompost temp1’,‘Kompost temp2’,'Kompost tem$
df1 = df.iloc[:,[0,1,6,7,10,14,16,17,18,20,21,24,49,50]]
df1[df.duplicated(keep=False)]
db = Gicompar++room++
timeValues.index = df[ [‘datum’] ]
tags = {‘Lufttemperatur’: df[[‘Lufttemperatur’]], ‘Zuluft Temperatur’: df[[‘Zuluft Temperatur’]], ‘CO2’:df[[‘CO2’]]}
client.switch_database(‘db’)
client.write_points(db, tbName, timeValues, tags = tags)

  • Platform information:
    • Hardware:Raspberry 4
    • OS: Openhabian
    • Java Runtime Environment: which java platform is used and what version
    • openHAB version: Openhab 2.5
  • first check which version of influx client is available / provided by your OS
  • you also can install more recent influx client software from influx home page
  • the man page of the influx client shell describes how to use the command itself:
    https://docs.influxdata.com/influxdb/v1.8/tools/shell/
  • to upload the output of your R script you either could do it in separate steps:
    a) run your R script and e.g. generate csv formatted file output
    b) upload the csv file ( see manual page of influxdb shell )
    or alternatively to a + b
    c) call a shell script from withinR

THX for your advices
I’m still a rookie in the world of openhab and it’s not that easy to get things working with external modules due to the fast changing interfaces for those. By example there is an influxDB-client for InfluxDB 1.8 or newer: [https://pypi.org/project/influxdb-client/](https://pypi.org/project/influxdb-
But a lot of the API example on the internet is for the old client version.
So i did install the client and my script is running but the method of writing the data frame to my database is still not solved.

Is there any reference project in python for this?

Due to the fact that im running with 15 exec bindings simultaneously this script to to 15 individual data sources (CSV-files) I would like to use a method which generates as less data transactions as possible and not generating a new CSV file which will be uploaded by the influx shell script.

it’s still the code from your first post ? what’s not working ? do you get any error message ?

Hey Wolfgang i did adapt the code a little bit due to the installed influxDBclient:

    import sys

import pandas as pd
import re
from influxdb_client import InfluxDBClient

client = InfluxDBClient(url=“http://localhost:8086”, token=“my-token”, org=“my-org”)

if len(sys.argv) < 1:
print(“Missing argument”)
exit()

room = re.sub(“LOT\d{4}”, “”, sys.argv[1])
print("Room Nr: "+room)

try:
roomint = int(room)
except ValueError:
print("Illegal LOT-Nr: "+sys.argv[1])
exit()

if roomint < 0 or roomint > 15:
print(“Illegal Room Nr.”)
exit()

df = pd.read_csv(’/etc/openhab2/scripts/grafiek’+room+’.dat’,
header=None,
skiprows = 1,
encoding=‘ISO-8859-1’,
names=[‘datum’,‘Lufttemperatur’,‘Feuchtigkeit Temperatur’])
df1 = df.iloc[:,[0,1,6,7,10,14,16,17,18,20,21,24,49,50]]
df1[df.duplicated(keep=False)]

db = ‘Gicompar’+room+’’

timeValues.index = df[ [‘datum’] ]
tags = {‘Lufttemperatur’: df[[‘Lufttemperatur’]], ‘Zuluft Temperatur’: df[[‘Zuluft Temperatur’]], ‘CO2’:df[[‘CO2’]]}

client.switch_database(‘db’)
client.write_points(db, tbName, timeValues, tags = tags)

SO the point where I’m converting the data frame into the right format for the write module is not clear for me and I can run the script but nothing will be written into the specific Database.