-
Notifications
You must be signed in to change notification settings - Fork 0
/
Driver.java
85 lines (74 loc) · 2.71 KB
/
Driver.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package handler;
import java.io.File;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.JFrame;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.json.JSONObject;
import com.github.sarxos.webcam.Webcam;
import com.github.sarxos.webcam.WebcamPanel;
import com.github.sarxos.webcam.WebcamResolution;
/**
*
* @author Yatin Kewale
*
*/
public class Driver {
// static
private static final Logger _Logger = Logger.getLogger(Driver.class.getName());
// private
private static CoapCli _cp;
// constructors
// static methods
public static void start2() throws MqttException, IOException {
_cp = new CoapCli(); // instantiating new COAP Client
String x = "RAESSL"; // TOPIC
Webcam webcam = Webcam.getDefault(); // Instantiate new Webcam Object
webcam.setViewSize(WebcamResolution.VGA.getSize()); // Resolution for images to be captured
WebcamPanel wbpnl = new WebcamPanel(webcam); // call webpanel method to create a new screen
JFrame frame = new JFrame(); // new Java Frame to display the panel
frame.add(wbpnl); // add the panel to the frame
frame.setLocationRelativeTo(null); // Image centred
frame.pack(); // Occupies entire frame
frame.setVisible(true);// Frame visible
int i = 0;
while (i < 15) { // loop for taking 15 images each every 0.5 seconds
try {
Thread.sleep(500);
} catch (InterruptedException ex) {
Thread.currentThread().interrupt();
}
i++;
ImageIO.write(webcam.getImage(), "PNG", new File(i + "hello-world.png"));
}
webcam.close();
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
Calendar cal = Calendar.getInstance();
String y = dateFormat.format(cal.getTime());
JSONObject jsonObj = new JSONObject( // creating a JSON message
"{\"Category\":\"HomeSecurity\",\"What\":\"Somebody out there!\",\"Where\":\"at Darling street\",\"When\":\"now\"}");
String z = (" with sensors Triggered at time = " + y + "}");
CoapCommServer ab = new CoapCommServer(x); // passing resource name to new coap server object
ab.start();
_cp.getMessage(x);
_cp.postMessage(x, jsonObj.toString() + z);
// _cp.getMessage(x);
// _cp.putMessage(x, "Hi there");
ReceivingApp r = new ReceivingApp();
r.connect();
// r.subscribeMessage(null);
r.subscribeMessage(x);
// r.subscribeMessage("/MDAS");
// r.subscribeMessage("SafeDoor");
// r.subscribeMessage("/SafeDoor");
// _cp.discoverMessage();
// _cp.deleteMessage(x);
_Logger.log(Level.SEVERE, "Done%");
ab.stop();
}
}