Skip to content
Snippets Groups Projects
Commit 23d6fd44 authored by Puissegur Alexis's avatar Puissegur Alexis
Browse files

testing bluetooth received packets

parent 6fca50f0
No related branches found
No related tags found
No related merge requests found
......@@ -17,6 +17,7 @@ public class BluetoothThread extends Thread implements Observable {
private boolean keepGoing = true;
private String buffer;
private Observer observer;
private boolean bufferHasToBeUpdated = false;
public BluetoothThread(BluetoothConnection connection, Observer observer) {
this.connection = connection;
......@@ -38,9 +39,12 @@ public class BluetoothThread extends Thread implements Observable {
try {
// Each packet must start with two SYNC bytes in a row
byte[] payload = new byte[PACKET_SIZE];
connection.getInputStream().read(payload);
int nbRead = connection.getInputStream().read(payload);
Logger.getLogger(BluetoothThread.class.getName()).log(Level.FINE,"run",nbRead);
if(bufferHasToBeUpdated){
this.buffer = new String(payload, StandardCharsets.UTF_8);
notifyObserver();
notifyObserver();
}
} catch (Exception e) {
Logger.getLogger(BluetoothThread.class.getName()).log(Level.SEVERE,"Could not read stream",e);
......
......@@ -77,7 +77,7 @@
<image>
<Image url="@images/humidity.png" />
</image></ImageView>
<Label fx:id="himidityAir" text="himidité dans l'air" />
<Label fx:id="humidityAir" text="humidité dans l'air" />
<Label text="\%" />
</children>
</HBox>
......
......@@ -39,7 +39,7 @@ public class FXMLVueController implements Initializable, Observer {
@FXML
private Label intensity;
@FXML
private Label himidityAir;
private Label humidityAir;
@FXML
private Label humidityPlante;
@FXML
......
......@@ -12,28 +12,13 @@
#define HEADER_SOUND_ON "SOUND"
#define HEADER_PLANT_OK "STOP"
#define REMAINING_TIME 300000 // 5MIN
#define DATASPAN 10000 // 5MIN
#define DATASPAN 300000 // 5MIN
#define ALARMSPAN 10000 // 10SEC
#define FAb4 740
#define LAb4 932
#define BT_NAME "Thingz-INSA"
#define BT_PASSWORD "1234"
/*
Thingz prend ses mesures et envoie les donnes l'appli java (toutes les 5mins par ex)
l'appli java est une IHM configurable qui :
affiche les donnes en temps rel sur des graphiques
sait s'il faut arroser la plante ou non
envoie un mail au prof si besoin pour arroser
envoie via bluetooth si arrosage possible ou urgent et si en semaine ou weekend
son plus ou moins long
Messages bluetooth :
LIGHT;
SOUND;WEEKEND
SOUND;SEMAINE
*/
Bouton monBouton1;
Led maLed1;
Meteo meteo;
......@@ -100,7 +85,7 @@ void receiveFromBluetooth() {
if (bluetooth.dataAvailable()){
buffer = bluetooth.receive();
}
monEcran1.printMsg(buffer,0);
if (buffer.startsWith(HEADER_LIGHT_ON)){
dealWithLight();
......@@ -149,7 +134,7 @@ void setup()
alarmTimeStamp = 0;
dataTimeStamp = 0;
lightTimeStamp = 0;
bluetooth.setPassword(BT_PASSWORD);
connect();
}
......@@ -170,16 +155,16 @@ if(millis() - timePushed < REMAINING_TIME){
monEcran1.clear();
monEcran1.setContrast(0, false);
}
if (monBouton1.estTenuAppuye()) {
timePushed = millis();
}
if(millis() - dataTimeStamp > DATASPAN){
dataTimeStamp = millis();
sendBluetoothDataToServer(humi,lumi,temp,humiTerre);
}
if(alarmHasBeenTurnedOn){
if(millis() - alarmTimeStamp < ALARMSPAN){
fireAlarm();
......@@ -187,18 +172,16 @@ if(millis() - timePushed < REMAINING_TIME){
alarmHasBeenTurnedOn = false;
}
}
if(ledHasBeenTurnedOn){
if(millis() - lightTimeStamp > ALARMSPAN){
ledHasBeenTurnedOn = false;
maLed1.eteint();
}
}
if(plantInNeed && motion.detectsStartOfMotion()){
dealWithSound();
dealWithLight();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment