1 package com.lasalle.beehoneyt;
9 import androidx.appcompat.app.AppCompatActivity;
11 import android.content.Intent;
12 import android.os.Bundle;
13 import android.util.Log;
14 import android.widget.TextView;
16 import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken;
17 import org.eclipse.paho.client.mqttv3.MqttCallbackExtended;
18 import org.eclipse.paho.client.mqttv3.MqttMessage;
19 import org.json.JSONException;
20 import org.json.JSONObject;
22 import java.text.ParseException;
23 import java.text.SimpleDateFormat;
24 import java.util.Date;
25 import java.util.Iterator;
26 import java.util.Locale;
27 import java.util.TimeZone;
39 private static final String
TAG =
"RucheActivity";
58 protected void onCreate(Bundle savedInstanceState)
60 super.onCreate(savedInstanceState);
61 setContentView(R.layout.activity_ruche);
63 nom_ruche = (TextView) this.findViewById(R.id.nom_ruche);
64 topic_ruche = (TextView) this.findViewById(R.id.topic_ruche);
65 message_ruche = (TextView) this.findViewById(R.id.message_ruche);
66 poids_ruche = (TextView) this.findViewById(R.id.poids_ruche);
67 temperature_interieure_ruche = (TextView) this.findViewById(R.id.temperature_interieure_ruche);
68 temperature_exterieure_ruche = (TextView) this.findViewById(R.id.temperature_exterieure_ruche);
69 humidite_interieure_ruche = (TextView) this.findViewById(R.id.humidite_interieure_ruche);
70 humidite_exterieure_ruche = (TextView) this.findViewById(R.id.humidite_exterieure_ruche);
71 pression_ruche = (TextView) this.findViewById(R.id.pression_ruche);
72 ensoleillement_ruche = (TextView) this.findViewById(R.id.ensoleillement_ruche);
76 Intent intent = getIntent();
78 ruche = (
Ruche)intent.getSerializableExtra(
"Ruche");
81 Log.d(TAG,
"Ruche : " + ruche.
getNom() +
" " +
ruche);
103 nom_ruche.setText(
"Nom : " + message);
115 topic_ruche.setText(
"Topic : " + message);
124 message_ruche.setText(
"Message : " + message);
134 Log.d(TAG,
"deviceID : " + deviceID);
138 public void connectComplete(
boolean b, String s) {
142 public void connectionLost(Throwable throwable) {
146 public void messageArrived(String topic, MqttMessage mqttMessage)
throws Exception
148 Log.d(TAG,
"Topic : " + topic);
149 Log.d(TAG,
"Message : " + mqttMessage.toString());
156 Log.d(TAG,
"Horodatage formaté : " + horodatageFormate);
162 public void deliveryComplete(IMqttDeliveryToken iMqttDeliveryToken)
178 JSONObject json = null;
179 Iterator<String> it = null;
181 json =
new JSONObject(message);
182 int port = json.getInt(
"port");
187 String cle = it.next();
188 Log.i(TAG,
"clé = " + cle);
189 Log.i(TAG,
"valeur = " + json.getString(cle));
192 if (cle.equals(
"dev_id"))
194 if(json.getString(cle).equals(deviceID)) {
201 catch (JSONException e)
218 SimpleDateFormat df =
new SimpleDateFormat(
"yyyy-MM-dd hh:mm:ss", Locale.FRENCH);
219 df.setTimeZone(TimeZone.getTimeZone(
"UTC"));
221 String horodatageFormate = horodatage;
224 date = df.parse(horodatage);
225 df.setTimeZone(TimeZone.getDefault());
226 horodatageFormate = df.format(date);
228 catch (ParseException e)
233 return horodatageFormate;
242 poids_ruche.setText(
"Poids : " + message +
"kg");
254 temperature_interieure_ruche.setText(
"Temperature interieure : " + message +
" °C");
262 temperature_exterieure_ruche.setText(
"Temperature exterieure : " + message +
" °C");
270 humidite_interieure_ruche.setText(
"Humidité interieure : " + message +
" %");
278 humidite_exterieure_ruche.setText(
"Humidité exterieure : " + message+
" %");
286 pression_ruche.setText(
"Pression atmosphérique : " + message +
" hPa");
294 ensoleillement_ruche.setText(
"Ensoleillement : " + message +
" lux");
static void afficherHumiditerExterieure(String message)
affichie l'humiditer exterieure dans le layout
static TextView temperature_interieure_ruche
void afficherTopic(String message)
afficher le topic
static void afficherTemperatureExterieure(String message)
affichie la Temperature exterieure dans le layout
static void afficherTemperatureInterieure(String message)
affichie la Temperature interieure dans le layout
static TextView poids_ruche
static void afficherPoids(int message)
affichie le poid dans le layout
String getDeviceID()
Accesseur get du device id de la ruche.
static TextView humidite_interieure_ruche
static void afficherEnsoleillement(String message)
affichie l'Ensoleillement dans le layout
void afficherInfo()
afficher les information d'un ruche
static void decoderMessage(String message, Ruche ruche)
decode le message recu
Déclaration de la classe CommunicationMQTT.
static void afficherHumiditeInterieure(String message)
affichie l'humiditer interieure dans le layout
static TextView ensoleillement_ruche
void onCreate(Bundle savedInstanceState)
Déclaration de la classe Ruche.
String getNom()
Accesseur get du nom de la ruche.
static TextView pression_ruche
static void afficherPression(String message)
affichie la pression dans le layout
void communiquerTTN(final String deviceID)
paramete la communication avec le ttn
String formaterHorodatge(String horodatage)
formate l'horodatage
static void setCallback(MqttCallbackExtended callback)
static String extraireHorodatage(String message)
extrait l'horodatage
void afficherJSON(String message)
affiche le dernier message JSON recu
static TextView humidite_exterieure_ruche
boolean estBonneRuche(String deviceID, String message)
verifie si le json reçu correspond a la ruche souhaité
void afficherNom(String message)
afficher le nom d'un ruche
void setPoids(int Poids)
Mutateur set du poids de la ruche.
static TextView temperature_exterieure_ruche
Déclaration de la classe RucheActivity.