smartgage.de Docs

influxdb with Python Script

write data with Python


# sudo apt-get install python-influxdb
# https://influxdb-python.readthedocs.io/en/latest/api-documentation.html

from influxdb import InfluxDBClient 

influx_host = 'smartgage.de'
influx_port = 8086
influx_user = 'username'
influx_pw = '*********'
influx_db = 'mydatabase'

json_body = [
	{
		"measurement": "MeinInfluxProjekt",
		"tags": {
			"SN": 12345678,
			"Standort": "Hennigsdorf"
		},
		"time": 1561306371000,
		"fields": { 
			"field_key1": 1.0000,
			"field_key2": 1.0101,
			"field_key3": 1.0234
		}
	},
	{
		"measurement": "MeinInfluxProjekt",
		"tags": {
			"SN": 12345678,
			"Standort": "Hennigsdorf"
		},
		"time": 1561306372000,
		"fields": { 
			"field_key1": 1.1000,
			"field_key2": 1.1101,
			"field_key3": 1.0234
		}
	}
]

client = InfluxDBClient(host=influx_host, port=influx_port, username=influx_user, \
						password=influx_pw, database=influx_db, ssl=True)
client.write_points(json_body)