Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
afkham committed May 17, 2014
2 parents e4652ce + d29aea1 commit 3c2e7fb
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down

0 comments on commit 3c2e7fb

Please sign in to comment.