defbuild_voltage_array(voltage_min: float, voltage_max: float, step: float): result = [] for i inrange(int((voltage_max - voltage_min) / step) + 1): result.append(voltage_min + i * step) return result
if __name__ == '__main__': client = Elasticsearch( "https://192.168.2.77:9200", ca_certs="ca/ca.crt", basic_auth=("elastic", ELASTIC_PASSWORD) ) voltage_array = build_voltage_array(VOLTAGE_MIN, VOLTAGE_MAX, VOLTAGE_STEP) whileTrue: for voltage in voltage_array: data = { "voltage": voltage, "@timestamp": int(time.time()) } time.sleep(10) client.index(index='sensor', document=data)