Jump to content

Persistieren von Sensordaten


Recommended Posts

Hallo zusammen,

ich soll Sensordaten vom RED-Brick persistieren. Kann mir da wer weiterhelfen? Ich stehe gerade voll auf dem Schlauch.//Edit hat sich erledigt:


package com.company;

import com.tinkerforge.IPConnection;
import com.tinkerforge.BrickletAccelerometer;

import java.io.*;

public class Main {
    private static final String HOST = "localhost";
    private static final int PORT = 4223;

    // Change XYZ to the UID of your Accelerometer Bricklet
    private static final String UID = "Cge";

    // Note: To make the example code cleaner we do not handle exceptions. Exceptions
    //       you might normally want to catch are described in the documentation
    public static void main(String args[]) throws Exception {
        IPConnection ipcon = new IPConnection(); // Create IP connection
        BrickletAccelerometer a = new BrickletAccelerometer(UID, ipcon); // Create device object

        ipcon.connect(HOST, PORT); // Connect to brickd
        // Don't use device before ipcon is connected

        // Add acceleration listener
        a.addAccelerationListener(new BrickletAccelerometer.AccelerationListener() {
            public void acceleration(short x, short y, short z)  {

                PrintWriter outputfile = null;
                try {
                    outputfile = new PrintWriter((new BufferedWriter(new FileWriter("Beschleunigung.txt",true))));
//replace your System.out.print("your output");
                }catch (IOException ioe) {
                }finally {
                    if (outputfile != null){

        // Set period for acceleration callback to 1s (1000ms)
        // Note: The acceleration callback is only called every second
        //       if the acceleration has changed since the last call!

        System.out.println("Press key to exit"); System.in.read();
Edited by tinytinkerer
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...