Hallo
Ich habe schon mal das kompilierend und ausgeführt, läuft klasse.
Mus es nur noch in KAD einfügen.
Gruß NetFritz
Ich habe schon mal das kompilierend und ausgeführt, läuft klasse.
Mus es nur noch in KAD einfügen.
Gruß NetFritz
Code:
import java.net.*; import java.io.*; import java.util.*; public class Logictest_writeinflux { private static HttpURLConnection client; public static void main(String[] args) { try { Random rn = new Random(); URL input; while(true) { input = new URL("http", "localhost", 8086, "/write?db=pv_db"); client = (HttpURLConnection) input.openConnection(); client.setRequestMethod("POST"); client.setDoOutput(true); double thermals = rn.nextDouble(); String s = "test_temperature value=" + thermals; try (OutputStreamWriter writer = new OutputStreamWriter(client.getOutputStream())) { writer.write(s); } BufferedReader in = new BufferedReader(new InputStreamReader( client.getInputStream())); String decodedString; while ((decodedString = in.readLine()) != null) { System.out.println(decodedString); } in.close(); System.out.println(s); // for debugging Thread.sleep(1000); // send data every 1 second } } catch(MalformedURLException error) { System.out.println("Malformed URL!"); } catch(SocketTimeoutException error) { System.out.println("Socket Timeout Exception!"); } catch (IOException error) { System.out.println("IOException!"); System.out.println(error); } catch(InterruptedException e) { System.out.println("InterruptedException!"); } finally { if(client != null) { // Make sure the connection is not null. client.disconnect(); } }
Kommentar