From c03d2b299fd56ac2035a2ddb596cf4f6b927f12d Mon Sep 17 00:00:00 2001 From: Dulitha Wijewantha Date: Sat, 17 May 2014 00:42:56 +0530 Subject: [PATCH 1/2] Removed humidity --- .../src/main/java/org/wso2/iot/refarch/rpi/agent/Publisher.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rpi-agent/core/src/main/java/org/wso2/iot/refarch/rpi/agent/Publisher.java b/rpi-agent/core/src/main/java/org/wso2/iot/refarch/rpi/agent/Publisher.java index 9b6a479..d69180b 100644 --- a/rpi-agent/core/src/main/java/org/wso2/iot/refarch/rpi/agent/Publisher.java +++ b/rpi-agent/core/src/main/java/org/wso2/iot/refarch/rpi/agent/Publisher.java @@ -80,7 +80,7 @@ public void run() { String message = "Temperature:" + Float.toString(temperature); String humidityMsg = "Humidity:" + Integer.toString(humidity); mqttClient.publish(1,message.getBytes()); - mqttClient.publish(1,humidityMsg.getBytes()); +// mqttClient.publish(1,humidityMsg.getBytes()); JSONObject infoObject = agent.createInfoObject(); //Inserting the sensors payload to info object infoObject.put("sensors", payload); From d29aea15e82aed36ee9667513b0528978f25bf23 Mon Sep 17 00:00:00 2001 From: Dulitha Wijewantha Date: Sat, 17 May 2014 12:57:35 +0530 Subject: [PATCH 2/2] Added actuator status to message payload --- .../wso2/iot/refarch/rpi/agent/Receiver.java | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/rpi-agent/core/src/main/java/org/wso2/iot/refarch/rpi/agent/Receiver.java b/rpi-agent/core/src/main/java/org/wso2/iot/refarch/rpi/agent/Receiver.java index 49cdbe4..76c976e 100644 --- a/rpi-agent/core/src/main/java/org/wso2/iot/refarch/rpi/agent/Receiver.java +++ b/rpi-agent/core/src/main/java/org/wso2/iot/refarch/rpi/agent/Receiver.java @@ -22,8 +22,14 @@ import com.pi4j.io.gpio.GpioFactory; import com.pi4j.io.gpio.GpioPinDigitalOutput; import com.pi4j.io.gpio.RaspiPin; +import org.json.simple.JSONObject; + +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; public class Receiver{ + private final Agent agent; private MQTTClient mqttClient; private MQTTBrokerConnectionConfig mqttBrokerConnectionConfig; final GpioController gpio; @@ -38,11 +44,34 @@ public Receiver() { String clientId = "R-Pi-Receiver"; String topicName = "iot/demo"; mqttClient = new MQTTClient(mqttBrokerConnectionConfig,clientId,topicName, this); - Agent.startService(); + agent = new Agent(); + } + + private void start() { + ScheduledExecutorService dhtReaderScheduler = Executors.newScheduledThreadPool(1); + dhtReaderScheduler.scheduleWithFixedDelay(new MonitoringTask(), 0, 10, TimeUnit.SECONDS); } + public class MonitoringTask implements Runnable { + + public MonitoringTask() { + } + + @Override + public void run() { + try { + JSONObject infoObject = agent.createInfoObject(); + // If true - Fan is on. If false Fan is off. + infoObject.put("actuator", pin.isHigh()); + agent.httpService.sendPayload(infoObject); + } catch (Exception e) { + e.printStackTrace(); + } + } + } public static void main(String[] args) { Receiver r = new Receiver(); + r.start(); } public void run(String message){ System.out.println("Message received "+message);