Projet Bee-Honey't (Mobile)  0.2
BTS SNIR LaSalle Avignon 2020
Référence de la classe com.lasalle.beehoneyt.CommunicationMQTT

Déclaration de la classe CommunicationMQTT. Plus de détails...

Graphe de collaboration de com.lasalle.beehoneyt.CommunicationMQTT:
Collaboration graph

Fonctions membres publiques

 CommunicationMQTT (Context context, final Handler handler)
 Constructeur de la classe CommunicationMQTT. Plus de détails...
 
void deconnecter ()
 deconetion du ttn Plus de détails...
 
void reconnecter ()
 reconnection au ttn Plus de détails...
 

Fonctions membres publiques statiques

static void decoderDonneExterieure (String payload, Ruche ruche)
 decode les donné de l'exterieure de la ruche Plus de détails...
 
static void decoderDonneInterieure (String payload, Ruche ruche)
 decode les donné de l'interieur de la ruche Plus de détails...
 
static void decoderMessage (String message, Ruche ruche)
 decode le message recu Plus de détails...
 
static void decoderPayload (int port, String payload, Ruche ruche)
 d'ecode le payload Plus de détails...
 
static boolean estConnecte ()
 boolaine retourne si le ttn est connecter Plus de détails...
 
static String extraireHorodatage (String message)
 extrait l'horodatage Plus de détails...
 
static void setCallback (MqttCallbackExtended callback)
 
static boolean souscrireTopic (String topic)
 S'abone a un device. Plus de détails...
 

Attributs publics statiques

static String clientId = "mes_ruches"
 Application ID. Plus de détails...
 
static MqttAndroidClient mqttAndroidClient
 
static final int TTN_CONNECTE = 1
 
static final int TTN_DECONNECTE = 2
 
static final int TTN_MESSAGE = 3
 

Fonctions membres privées

void connecter ()
 connection au ttn Plus de détails...
 

Attributs privés

Handler handler = null
 
String password = "ttn-account-v2.vC-aqMRnLLzGkNjODWgy81kLqzxBPAT8_mE-L7U2C_w"
 mot de passe TTN Plus de détails...
 
String serverUri = "tcp://eu.thethings.network:1883"
 lien vers TTN Plus de détails...
 
String username = "mes_ruches"
 nom d'utilisateur Plus de détails...
 

Attributs privés statiques

static final String TAG = "CommunicationMQTT"
 

Description détaillée

Déclaration de la classe CommunicationMQTT.

Définition à la ligne 32 du fichier CommunicationMQTT.java.

Documentation des constructeurs et destructeur

◆ CommunicationMQTT()

com.lasalle.beehoneyt.CommunicationMQTT.CommunicationMQTT ( Context  context,
final Handler  handler 
)

Constructeur de la classe CommunicationMQTT.

Paramètres
context

Définition à la ligne 63 du fichier CommunicationMQTT.java.

Références com.lasalle.beehoneyt.CommunicationMQTT.connecter(), et com.lasalle.beehoneyt.CommunicationMQTT.handler.

64  {
65  Log.v(TAG, "CommunicationMQTT() clientId = " + clientId);
66  this.handler = handler;
67  mqttAndroidClient = new MqttAndroidClient(context, serverUri, clientId);
68  mqttAndroidClient.setCallback(new MqttCallbackExtended()
69  {
70  @Override
71  public void connectComplete(boolean b, String s)
72  {
73  Log.w(TAG, "connectComplete() serverUri = " + s + " connecte = " + mqttAndroidClient.isConnected());
74  Message msg = Message.obtain();
75  Bundle bundle = new Bundle();
76  bundle.putInt("etat", TTN_CONNECTE);
77  msg.setData(bundle);
78  handler.sendMessage(msg);
79  }
80 
81  @Override
82  public void connectionLost(Throwable throwable)
83  {
84  Log.w(TAG, "connectionLost()");
85  Message msg = Message.obtain();
86  Bundle b = new Bundle();
87  b.putInt("etat", TTN_DECONNECTE);
88  msg.setData(b);
89  handler.sendMessage(msg);
90  }
91 
92  @Override
93  public void messageArrived(String topic, MqttMessage mqttMessage) throws Exception
94  {
95  Log.w(TAG, "messageArrived() topic = " + topic + " message = " + mqttMessage.toString());
96  Message msg = Message.obtain();
97  Bundle b = new Bundle();
98  b.putInt("etat", TTN_MESSAGE);
99  b.putString("topic", topic);
100  b.putString("message", mqttMessage.toString());
101  msg.setData(b);
102  handler.sendMessage(msg);
103  }
104 
105  @Override
106  public void deliveryComplete(IMqttDeliveryToken iMqttDeliveryToken)
107  {
108  Log.w(TAG, "deliveryComplete()");
109  }
110  });
111 
112  connecter();
113  }
static String clientId
Application ID.

Documentation des fonctions membres

◆ connecter()

com.lasalle.beehoneyt.CommunicationMQTT.connecter ( )
private

connection au ttn

Définition à la ligne 131 du fichier CommunicationMQTT.java.

Référencé par com.lasalle.beehoneyt.CommunicationMQTT.CommunicationMQTT(), et com.lasalle.beehoneyt.CommunicationMQTT.reconnecter().

132  {
133  MqttConnectOptions mqttConnectOptions = new MqttConnectOptions();
134  mqttConnectOptions.setAutomaticReconnect(true);
135  mqttConnectOptions.setCleanSession(false);
136  mqttConnectOptions.setUserName(username);
137  mqttConnectOptions.setPassword(password.toCharArray());
138 
139  try
140  {
141  Log.d(TAG, "connecter() serverUri = " + serverUri + " clientId = " + clientId);
142  mqttAndroidClient.connect(mqttConnectOptions, null, new IMqttActionListener()
143  {
144  @Override
145  public void onSuccess(IMqttToken asyncActionToken)
146  {
147  DisconnectedBufferOptions disconnectedBufferOptions = new DisconnectedBufferOptions();
148  disconnectedBufferOptions.setBufferEnabled(true);
149  disconnectedBufferOptions.setBufferSize(100);
150  disconnectedBufferOptions.setPersistBuffer(false);
151  disconnectedBufferOptions.setDeleteOldestMessages(false);
152  mqttAndroidClient.setBufferOpts(disconnectedBufferOptions);
153  Log.d(TAG, "onSuccess() serverUri = " + serverUri + " clientId = " + clientId);
154  }
155 
156  @Override
157  public void onFailure(IMqttToken asyncActionToken, Throwable exception)
158  {
159  Log.d(TAG, "onFailure() serverUri = " + serverUri + " clientId = " + clientId + " exception = " + exception.toString());
160  }
161  });
162  }
163  catch (MqttException ex)
164  {
165  ex.printStackTrace();
166  }
167  }
static String clientId
Application ID.
String username
nom d'utilisateur

◆ decoderDonneExterieure()

static void com.lasalle.beehoneyt.CommunicationMQTT.decoderDonneExterieure ( String  payload,
Ruche  ruche 
)
static

decode les donné de l'exterieure de la ruche

Paramètres
payload
ruche

Définition à la ligne 366 du fichier CommunicationMQTT.java.

Références com.lasalle.beehoneyt.RucheActivity.afficherEnsoleillement(), com.lasalle.beehoneyt.RucheActivity.afficherHumiditerExterieure(), com.lasalle.beehoneyt.RucheActivity.afficherPoids(), com.lasalle.beehoneyt.RucheActivity.afficherPression(), com.lasalle.beehoneyt.RucheActivity.afficherTemperatureExterieure(), et com.lasalle.beehoneyt.Ruche.setPoids().

Référencé par com.lasalle.beehoneyt.CommunicationMQTT.decoderPayload().

367  {
368  try {
369  JSONObject json = null;
370  json = new JSONObject(payload);
371 
372  Iterator<String> it = null;
373  it = json.keys();
374  while (it.hasNext()) {
375  String cle = it.next();
376  if (cle.equals("temperature"))
377  {
378  Log.i(TAG, "decoderDonneExterieure() temperature = " + json.getString(cle));
379  RucheActivity.afficherTemperatureExterieure(json.getString(cle));
380  }
381  else if (cle.equals("humidite"))
382  {
383  Log.i(TAG, "decoderDonneExterieure() humidite = " + json.getString(cle));
384  RucheActivity.afficherHumiditerExterieure(json.getString(cle));
385  }
386  else if (cle.equals("ensoleillement"))
387  {
388  Log.i(TAG, "decoderDonneExterieure() ensoleillement = " + json.getString(cle));
389  RucheActivity.afficherEnsoleillement(json.getString(cle));
390  }
391  else if (cle.equals("pression"))
392  {
393  Log.i(TAG, "decoderDonneExterieure() pression = " + json.getString(cle));
394  RucheActivity.afficherPression(json.getString(cle));
395  }
396  else if (cle.equals("poids"))
397  {
398  double poids = json.getDouble(cle);
399  poids = poids * 0.01;
400  Log.i(TAG, "decoderDonneExterieure() poids = " + json.getInt(cle));
401  ruche.setPoids(json.getInt(cle));
402  RucheActivity.afficherPoids(json.getInt(cle));
403  }
404  }
405  }
406  catch (JSONException e)
407  {
408  e.printStackTrace();
409  }
410  }

◆ decoderDonneInterieure()

static void com.lasalle.beehoneyt.CommunicationMQTT.decoderDonneInterieure ( String  payload,
Ruche  ruche 
)
static

decode les donné de l'interieur de la ruche

Paramètres
payload
ruche

Définition à la ligne 331 du fichier CommunicationMQTT.java.

Références com.lasalle.beehoneyt.RucheActivity.afficherHumiditeInterieure(), et com.lasalle.beehoneyt.RucheActivity.afficherTemperatureInterieure().

Référencé par com.lasalle.beehoneyt.CommunicationMQTT.decoderPayload().

332  {
333  try
334  {
335  JSONObject json = null;
336  json = new JSONObject(payload);
337 
338  Iterator<String> it = null;
339  it = json.keys();
340  while (it.hasNext())
341  {
342  String cle = it.next();
343  if (cle.equals("temperature"))
344  {
345  Log.i(TAG, "decoderDonneInterieure() temperature = " + json.getString(cle));
346  RucheActivity.afficherTemperatureInterieure(json.getString(cle));
347  }
348  else if (cle.equals("humidite"))
349  {
350  Log.i(TAG, "decoderDonneInterieure() humidite = " + json.getString(cle));
351  RucheActivity.afficherHumiditeInterieure(json.getString(cle));
352  }
353  }
354  }
355  catch (JSONException e)
356  {
357  e.printStackTrace();
358  }
359  }

◆ decoderMessage()

com.lasalle.beehoneyt.CommunicationMQTT.decoderMessage ( String  message,
Ruche  ruche 
)
static

decode le message recu

Paramètres
messagele message reçu
ruche

Définition à la ligne 276 du fichier CommunicationMQTT.java.

Références com.lasalle.beehoneyt.CommunicationMQTT.decoderPayload().

Référencé par com.lasalle.beehoneyt.RucheActivity.communiquerTTN().

277  {
278  try
279  {
280  JSONObject json = null;
281  Iterator<String> it = null;
282 
283  json = new JSONObject(message);
284  int port = json.getInt("port");
285 
286  it = json.keys();
287  while (it.hasNext())
288  {
289  String cle = it.next();
290  Log.i(TAG, "decoderMessage() clé = " + cle);
291  Log.i(TAG, "decoderMessage() valeur = " + json.getString(cle));
292  //Log.i(TAG, "type = " + json.get(cle).getClass());
293 
294  if (cle.equals("payload_fields"))
295  {
296  decoderPayload(port, json.getString(cle), ruche);
297  }
298  }
299  }
300  catch (JSONException e)
301  {
302  e.printStackTrace();
303  }
304  }
static void decoderPayload(int port, String payload, Ruche ruche)
d&#39;ecode le payload

◆ decoderPayload()

static void com.lasalle.beehoneyt.CommunicationMQTT.decoderPayload ( int  port,
String  payload,
Ruche  ruche 
)
static

d'ecode le payload

Paramètres
port
payload
ruche

Définition à la ligne 312 du fichier CommunicationMQTT.java.

Références com.lasalle.beehoneyt.CommunicationMQTT.decoderDonneExterieure(), et com.lasalle.beehoneyt.CommunicationMQTT.decoderDonneInterieure().

Référencé par com.lasalle.beehoneyt.CommunicationMQTT.decoderMessage().

313  {
314 
315  Log.i(TAG, "decoderPayload() port = " + port );
316  if ( port == 3)
317  {
318  decoderDonneInterieure(payload, ruche);
319  }
320  else
321  {
322  decoderDonneExterieure(payload, ruche);
323  }
324  }
static void decoderDonneExterieure(String payload, Ruche ruche)
decode les donné de l&#39;exterieure de la ruche
static void decoderDonneInterieure(String payload, Ruche ruche)
decode les donné de l&#39;interieur de la ruche

◆ deconnecter()

com.lasalle.beehoneyt.CommunicationMQTT.deconnecter ( )

deconetion du ttn

Définition à la ligne 187 du fichier CommunicationMQTT.java.

Référencé par com.lasalle.beehoneyt.CommunicationMQTT.reconnecter().

188  {
189  Log.d(TAG, "deconnecter() serverUri = " + serverUri + " clientId = " + clientId);
190  try
191  {
192  IMqttToken disconToken = mqttAndroidClient.disconnect();
193  disconToken.setActionCallback(new IMqttActionListener()
194  {
195  @Override
196  public void onSuccess(IMqttToken asyncActionToken)
197  {
198  Log.d(TAG, "onSuccess() serverUri = " + serverUri + " clientId = " + clientId);
199  }
200 
201  @Override
202  public void onFailure(IMqttToken asyncActionToken, Throwable exception)
203  {
204  Log.d(TAG, "onFailure() serverUri = " + serverUri + " clientId = " + clientId + " exception = " + exception.toString());
205  }
206  });
207  }
208  catch (MqttException e)
209  {
210  e.printStackTrace();
211  }
212  }
static String clientId
Application ID.

◆ estConnecte()

com.lasalle.beehoneyt.CommunicationMQTT.estConnecte ( )
static

boolaine retourne si le ttn est connecter

Définition à la ligne 219 du fichier CommunicationMQTT.java.

Référencé par com.lasalle.beehoneyt.CommunicationMQTT.reconnecter().

220  {
221  Log.w(TAG, "estConnecte() " + mqttAndroidClient.isConnected());
222 
223  return mqttAndroidClient.isConnected();
224  }

◆ extraireHorodatage()

static String com.lasalle.beehoneyt.CommunicationMQTT.extraireHorodatage ( String  message)
static

extrait l'horodatage

Paramètres
message

Définition à la ligne 416 du fichier CommunicationMQTT.java.

Référencé par com.lasalle.beehoneyt.RucheActivity.communiquerTTN().

417  {
418  String date = "";
419 
420  try
421  {
422  JSONObject json = null;
423  json = new JSONObject(message);
424 
425  date = json.getJSONObject("metadata").getString("time");
426  date = date.substring(0, 10) + " " + date.substring(11, 19);
427  Log.d(TAG, "extraireHorodatage() time = " + json.getJSONObject("metadata").getString("time"));
428  Log.d(TAG, "extraireHorodatage() horodatage = " + date);
429 
430  }
431  catch (JSONException e)
432  {
433  e.printStackTrace();
434  }
435 
436  return date;
437  }

◆ reconnecter()

com.lasalle.beehoneyt.CommunicationMQTT.reconnecter ( )

reconnection au ttn

Définition à la ligne 174 du fichier CommunicationMQTT.java.

Références com.lasalle.beehoneyt.CommunicationMQTT.connecter(), com.lasalle.beehoneyt.CommunicationMQTT.deconnecter(), et com.lasalle.beehoneyt.CommunicationMQTT.estConnecte().

175  {
176  Log.w(TAG, "reconnecter ()");
177  if (estConnecte())
178  deconnecter();
179  connecter();
180  }
static boolean estConnecte()
boolaine retourne si le ttn est connecter

◆ setCallback()

com.lasalle.beehoneyt.CommunicationMQTT.setCallback ( MqttCallbackExtended  callback)
static
Paramètres
callbackle retour

Définition à la ligne 121 du fichier CommunicationMQTT.java.

Référencé par com.lasalle.beehoneyt.RucheActivity.communiquerTTN(), et com.lasalle.beehoneyt.MainActivity.communiquerTTN().

122  {
123  mqttAndroidClient.setCallback(callback);
124  }

◆ souscrireTopic()

com.lasalle.beehoneyt.CommunicationMQTT.souscrireTopic ( String  topic)
static

S'abone a un device.

Paramètres
topicle topic au quel s'aboner

Définition à la ligne 232 du fichier CommunicationMQTT.java.

Référencé par com.lasalle.beehoneyt.Ruche.souscrireTopic().

233  {
234  if(mqttAndroidClient == null && !mqttAndroidClient.isConnected())
235  {
236  return false;
237  }
238  final String subTopic = clientId + "/devices/" + topic + "/up";
239  Log.w(TAG, "souscrireTopic() topic = " + subTopic);
240  try
241  {
242  final boolean[] retour = {false};
243  mqttAndroidClient.subscribe(subTopic, 0, null, new IMqttActionListener()
244  {
245  @Override
246  public void onSuccess(IMqttToken asyncActionToken)
247  {
248  Log.w(TAG, "onSuccess() topic = " + subTopic);
249  retour[0] = true;
250  }
251 
252  @Override
253  public void onFailure(IMqttToken asyncActionToken, Throwable exception)
254  {
255  Log.w(TAG, "onFailure() topic = " + subTopic);
256  retour[0] = false;
257  }
258  });
259  return retour[0];
260  }
261  catch (MqttException ex)
262  {
263  Log.w(TAG, "Erreur topic = " + subTopic);
264  ex.printStackTrace();
265  return false;
266  }
267  }
static String clientId
Application ID.

Documentation des données membres

◆ clientId

String com.lasalle.beehoneyt.CommunicationMQTT.clientId = "mes_ruches"
static

Application ID.

Définition à la ligne 53 du fichier CommunicationMQTT.java.

◆ handler

Handler com.lasalle.beehoneyt.CommunicationMQTT.handler = null
private

Définition à la ligne 42 du fichier CommunicationMQTT.java.

Référencé par com.lasalle.beehoneyt.CommunicationMQTT.CommunicationMQTT().

◆ mqttAndroidClient

MqttAndroidClient com.lasalle.beehoneyt.CommunicationMQTT.mqttAndroidClient
static

Attributs

Définition à la ligne 41 du fichier CommunicationMQTT.java.

◆ password

String com.lasalle.beehoneyt.CommunicationMQTT.password = "ttn-account-v2.vC-aqMRnLLzGkNjODWgy81kLqzxBPAT8_mE-L7U2C_w"
private

mot de passe TTN

Définition à la ligne 55 du fichier CommunicationMQTT.java.

◆ serverUri

String com.lasalle.beehoneyt.CommunicationMQTT.serverUri = "tcp://eu.thethings.network:1883"
private

lien vers TTN

A faire:
Prévoir autre chose pour configurer/stocker les paramètres de connexion TTN

Définition à la ligne 52 du fichier CommunicationMQTT.java.

◆ TAG

final String com.lasalle.beehoneyt.CommunicationMQTT.TAG = "CommunicationMQTT"
staticprivate

Constantes

Définition à la ligne 37 du fichier CommunicationMQTT.java.

◆ TTN_CONNECTE

final int com.lasalle.beehoneyt.CommunicationMQTT.TTN_CONNECTE = 1
static

Constantes de communication avec l'activité

Définition à la ligne 46 du fichier CommunicationMQTT.java.

◆ TTN_DECONNECTE

final int com.lasalle.beehoneyt.CommunicationMQTT.TTN_DECONNECTE = 2
static

Définition à la ligne 47 du fichier CommunicationMQTT.java.

◆ TTN_MESSAGE

final int com.lasalle.beehoneyt.CommunicationMQTT.TTN_MESSAGE = 3
static

Définition à la ligne 48 du fichier CommunicationMQTT.java.

◆ username

String com.lasalle.beehoneyt.CommunicationMQTT.username = "mes_ruches"
private

nom d'utilisateur

Définition à la ligne 54 du fichier CommunicationMQTT.java.


La documentation de cette classe a été générée à partir du fichier suivant :