Exemplo n.º 1
0
  public static void main(String[] args) throws Exception {

    final Pang httpClient =
        //        PreverClientFactory.createHttpClient("demo", "Fj8QBK",
        // "http://192.168.56.101:9191");
        PangFactory.createHttpClient("demo", "Fj8QBK", "http://192.168.0.4:9191");
    final Random generator = new Random();
    // 2pi = 6.28....
    final double period = 1000;
    final double amplitude = 10;

    Timer timer = new Timer();
    timer.schedule(
        new TimerTask() {
          @Override
          public void run() {
            String value = null;
            double sin = Math.sin(System.currentTimeMillis() / period);
            value = ((Double) (amplitude * sin)).toString();
            System.out.println((new Date()).toString() + "@" + value);

            try {
              //          httpClient.sendData("test_sin", value);
            } catch (Throwable e) {

            }
          }
        },
        0,
        1 * 1000);
    timer.wait();
    httpClient.disconnect();
  }
Exemplo n.º 2
0
  @Test
  public void sendMultipleDataByTimerTask() throws Exception {

    Pang httpClient = PangFactory.createHttpClient("josh", "abc2fk");
    httpClient.connect("http://localhost:9191");

    httpClient.startTimerTask(
        new MultipleDataCallback() {

          public boolean isRunning(int count) {
            return count < 10;
          }

          public void onSuccess(Object value) {}

          public Object getData() {
            sensor.setHumidity((int) (Math.random() * 30 + 30));
            sensor.setTemperature((int) (Math.random() * 20 + 20));
            sensor.setTimeStamp(new Date());
            return sensor;
          }
        },
        5,
        TimeUnit.SECONDS);

    httpClient.waitTimerTask();

    httpClient.disconnect();
  }
Exemplo n.º 3
0
  @Test
  public void sendByTimerTask() throws Exception {
    final Random r = new Random();

    Pang httpClient = PangFactory.createHttpClient("josh", "abc2fk", "http://localhost:9191");

    httpClient.startTimerTask(
        "temperature",
        new SingleDataCallback() {

          public void onSuccess(String data) {
            System.out.println(data);
          }

          public boolean isRunning(int currentCount) {
            return currentCount < 10;
          }

          public String getData() {
            return Integer.toString(r.nextInt(10));
          }
        },
        5,
        TimeUnit.SECONDS);

    httpClient.waitTimerTask();

    httpClient.disconnect();
  }
Exemplo n.º 4
0
  @Test
  public void senddata() throws Exception {
    Pang httpClient = PangFactory.createHttpClient("josh", "abc2fk", "http://localhost:9191");

    httpClient.sendData("temperature", "12");

    httpClient.disconnect();
  }
Exemplo n.º 5
0
  @Test
  public void sendMultipledata() throws Exception {
    Pang httpClient = PangFactory.createHttpClient("josh", "abc2fk", "http://localhost:9191");

    sensor.setHumidity((int) (Math.random() * 30 + 30));
    sensor.setTemperature((int) (Math.random() * 20 + 20));
    sensor.setTimeStamp(new Date());

    httpClient.sendData(sensor);

    httpClient.disconnect();
  }