Commit e845e9be authored by Jan Wagemakers's avatar Jan Wagemakers

hcitool name

parent 8b71f0ac
......@@ -88,3 +88,27 @@ jan@thermoraspbian:~/NetBeansProjects/thermostat/dist $ hcitool info CC:61:E5:D7
Requesting information ...
Can't create connection: Input/output error
-------------------
jan@thermoraspbian:~ l2ping -c 1 CC:61:E5:D7:A3:3F
Can't create socket: Operation not permitted
jan@thermoraspbian:~ $ which l2ping
/usr/bin/l2ping
jan@thermoraspbian:~ $ ls -la `which l2ping`
-rwxr-xr-x 1 root root 90524 Oct 20 2017 /usr/bin/l2ping
jan@thermoraspbian:~ $ su -
Password:
root@thermoraspbian:~# chmod 4755 /usr/bin/l2ping
root@thermoraspbian:~# exit
logout
jan@thermoraspbian:~ $ l2ping -c 1 CC:61:E5:D7:A3:3F
Ping: CC:61:E5:D7:A3:3F from B8:27:EB:D5:08:9B (data size 44) ...
44 bytes from CC:61:E5:D7:A3:3F id 0 time 5.07ms
1 sent, 1 received, 0% loss
jan@thermoraspbian:~ $
-----------------------
wifi laptop probleem:
https://answers.launchpad.net/ubuntu/+question/239371
......@@ -40,4 +40,11 @@ remote java
https://www.instructables.com/id/Efficient-Development-of-Java-for-the-Raspberry-Pi/
-----------------------------------
root@thermoraspbian:/etc/systemd/system# vim thermostat.service
root@thermoraspbian:/etc/systemd/system# systemctl start thermostat.service
root@thermoraspbian:/etc/systemd/system# systemctl enable thermostat.service
Created symlink /etc/systemd/system/multi-user.target.wants/thermostat.service → /etc/systemd/system/thermostat.service.
root@thermoraspbian:/etc/systemd/system#
......@@ -17,15 +17,21 @@ public class Serial {
public Serial() {
rfcomm = SerialPort.getCommPort("/dev/rfcomm0");
rfcomm.setComPortTimeouts(SerialPort.TIMEOUT_READ_BLOCKING |
SerialPort.TIMEOUT_WRITE_BLOCKING, 5000, 0);
SerialPort.TIMEOUT_WRITE_BLOCKING, 2000, 0);
}
private boolean open() {
public boolean open() {
System.out.println("---------------");
System.out.println("open");
return rfcomm.openPort();
boolean status = rfcomm.openPort();
// dummy read to be sure buffer is clear
byte[] in = new byte[80];
rfcomm.readBytes(in, in.length);
return status;
}
private boolean close() {
public boolean close() {
System.out.println("---------------");
System.out.println("close");
return rfcomm.closePort();
}
......@@ -41,7 +47,7 @@ public class Serial {
System.out.println("ERROR - FORMAT SP=x.xx");
return false;
}
if (!open()) return false;
try {
// send SP to thermostat
byte[] out = tx.getBytes();
......@@ -57,15 +63,13 @@ public class Serial {
}
} catch (Exception e) {
System.out.println(e.getMessage());
close();
return false;
}
if (!tx.substring(3, 7).equals(rx)) {
System.out.println("ERROR");
close();
return false;
}
return close();
return true;
}
private float get(String tx) {
......@@ -73,7 +77,6 @@ public class Serial {
System.out.println("---------------");
System.out.println("CMD : " + tx);
if (!open()) return -1;
try {
// send SP? to thermostat
byte[] out = tx.getBytes();
......@@ -87,10 +90,8 @@ public class Serial {
rx = Float.parseFloat(new String(in));
} catch (Exception e) {
System.out.println(e.getMessage());
close();
return -1;
}
if (!close()) return -1;
return rx;
}
......
......@@ -8,54 +8,57 @@ package thermostat;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Calendar;
import java.util.Timer;
import java.util.TimerTask;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author jan
*/
public class Thermostat {
private static final Serial SERIAL = new Serial();
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Serial serial = new Serial();
Timer timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
boolean home = true;
boolean home = false;
float temp = 16.0f;
Calendar rightNow = Calendar.getInstance();
int hour = rightNow.get(Calendar.HOUR_OF_DAY);
int min = rightNow.get(Calendar.MINUTE);
int day = rightNow.get(Calendar.DAY_OF_WEEK);
int hm = 100*hour+min;
String s = null;
String s;
try {
Process p = Runtime.getRuntime().exec("hcitool info CC:61:E5:D7:A3:3F");
//BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));
Process p = Runtime.getRuntime().exec("hcitool name CC:61:E5:D7:A3:3F");
BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
//BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));
// read the output from the command
//System.out.println("Here is the standard output of the command:\n");
//while ((s = stdInput.readLine()) != null) {
// System.out.println(s);
//}
System.out.println("---------------");
System.out.print("GSM? : ");
while ((s = stdInput.readLine()) != null) {
System.out.println(s);
home = true;
}
// read any errors from the attempted command
while ((s = stdError.readLine()) != null) {
System.out.println("NO GSM --> not home");
home = false;
}
//while ((s = stdError.readLine()) != null) {
// System.out.println("NO GSM --> not home");
// home = false;
//}
} catch (IOException e) {
System.out.println("exception happened - here's what I know: ");
e.printStackTrace();
......@@ -100,22 +103,23 @@ public class Thermostat {
break;
}
}
System.out.println(hm);
System.out.println(day);
// System.out.println(hm);
// System.out.println(day);
if (serial.setSP(temp)) System.out.println("OK");
// System.out.println(serial.getSP());
System.out.println(serial.getPV());
if (SERIAL.open()) {
if (SERIAL.setSP(temp)) System.out.println("OK");
// System.out.println(serial.getSP());
System.out.println(SERIAL.getPV());
SERIAL.close();
} else {
System.out.println("No BT connection");
}
}
}, 1*1000, 1*60*1000);
}, 1*60*1000, 1*60*1000);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment