All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.lhings.java.TemperatureSensor Maven / Gradle / Ivy

package com.lhings.java;

import java.io.IOException;

import com.lhings.java.annotations.Action;
import com.lhings.java.annotations.Event;
import com.lhings.java.annotations.StatusComponent;
import com.lhings.java.exception.LhingsException;
import com.lhings.java.pushprotocol.TCPSocketManager;

public class TemperatureSensor extends LhingsDevice {

	private float initialTemp = 25;

	@StatusComponent
	float temperature;

	@Event
	String overThreshold;

	@Action(argumentNames = {})
	public void accion() {
		System.out.println("Acción ejecutada. " + this.getName());
	}

	
	public TemperatureSensor(String name) throws IOException, LhingsException {
		super("[email protected]", "xxxx", name);
	}

	@Override
	public void loop() {
		temperature = (float) Math.random() * 10 + initialTemp;
		if (temperature > initialTemp + 9.9999) {
			sendEvent("overThreshold", "T: " + temperature);
			System.out.println("Enviado evento.");
		}
	}

	@Override
	public void setup() {
		temperature = 25f;
		overThreshold = "pimba";
	}

	public static void main(String[] args) throws IOException, LhingsException, InterruptedException {
		// Thread.sleep(90000);
		for (int j = 2; j < 15; j++) {
			LhingsDevice dev = new TemperatureSensor("PruebaUDP" + j);
			dev.setThreads(5);
			dev.setLoopFrequency(100f);
			dev.setSocketManager(new TCPSocketManager());
			dev.start();
		}
		// Accionador acc = new Accionador();
		// (new Thread(acc)).start();
		// Thread.sleep(600000);
		// dev.stop();
		// acc.running = false;
	}

	public static class Accionador implements Runnable {

		boolean running = true;
		int tries = 0;

		public void run() {
			// try {
			// WebServiceCom.executeGet("https://www.lhings.com/laas/api/v1/admin/retry_stats?reset",
			// "");
			// } catch (IOException e) {
			// e.printStackTrace();
			// } catch (LhingsException e) {
			// e.printStackTrace();
			// }
			// while(running) {
			// try {
			// WebServiceCom.executePost("bc3cd849-e5de-4ca1-ba4d-2e5e78c8fc77",
			// "https://www.lhings.com/laas/api/v1/devices/35bac728-7a45-4bc2-a821-63c4dbd95bfc/actions/accion",
			// "[]");
			// tries ++;
			// Thread.sleep(5000);
			// } catch (Exception e) {
			// e.printStackTrace();
			// }
			// }
			// String results = null;
			// try {
			// results =
			// WebServiceCom.executeGet("https://www.lhings.com/laas/api/v1/admin/retry_stats",
			// "");
			// } catch (IOException e) {
			// e.printStackTrace();
			// } catch (LhingsException e) {
			// e.printStackTrace();
			// }
			// System.out.println(results);
			// System.out.println("Tries: " + tries);
		}

	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy