-
This commit is contained in:
parent
cae17bff96
commit
fbd2e4d19b
@ -17,26 +17,9 @@ import com.jens.rhasspy.visualtool.lib.JSONObject;
|
|||||||
|
|
||||||
public class MQTT implements MqttCallbackExtended
|
public class MQTT implements MqttCallbackExtended
|
||||||
{
|
{
|
||||||
/*
|
final static String clientId = "RhasspyVisualConversationTool-" + Settings.siteId + "-" + String.valueOf(Calendar.getInstance().getTimeInMillis());
|
||||||
* Connect to server
|
|
||||||
*
|
|
||||||
* raspberrypi1:1883
|
|
||||||
*
|
|
||||||
* Subscribe to topic
|
|
||||||
*
|
|
||||||
* Topic: zigbee2mqtt/0x00158d0002d72e58
|
|
||||||
* Payload: {"contact":true,"linkquality":84}
|
|
||||||
*
|
|
||||||
* Configuration file:
|
|
||||||
* /opt/zigbee2mqtt/data/configuration.yaml
|
|
||||||
*/
|
|
||||||
|
|
||||||
final static String clientId = "RhasspyVisualConversationTool";
|
|
||||||
final static int maximumReconnectionAttempts = -1;
|
final static int maximumReconnectionAttempts = -1;
|
||||||
final static long timeout = 10000;
|
final static boolean forceReconnection = false;
|
||||||
|
|
||||||
protected static boolean forceReconnection = false;
|
|
||||||
|
|
||||||
|
|
||||||
Timer timeoutTimer = null;
|
Timer timeoutTimer = null;
|
||||||
|
|
||||||
@ -210,20 +193,22 @@ public class MQTT implements MqttCallbackExtended
|
|||||||
if(message != null && message.length() > 0)
|
if(message != null && message.length() > 0)
|
||||||
{
|
{
|
||||||
JSONObject jo = new JSONObject(message);
|
JSONObject jo = new JSONObject(message);
|
||||||
if(jo.has(Settings.jsonObjectStringSiteId))
|
if(jo.has(Settings.jsonObjectStringSiteId) && jo.getString(Settings.jsonObjectStringSiteId).equalsIgnoreCase(Settings.siteId))
|
||||||
{
|
{
|
||||||
for(String ignoredSite : Settings.ignoredSatellites.split(";"))
|
GUI.getInstance().handleNewMessage(object);
|
||||||
{
|
// for(String ignoredSite : Settings.ignoredSatellites.split(";"))
|
||||||
if(ignoredSite.equalsIgnoreCase(jo.getString(Settings.jsonObjectStringSiteId)))
|
// {
|
||||||
{
|
// if(ignoredSite.equalsIgnoreCase(jo.getString(Settings.jsonObjectStringSiteId)))
|
||||||
Miscellaneous.logEvent("Ignoring message as it's targeted to " + ignoredSite, 3);
|
// {
|
||||||
return;
|
// Miscellaneous.logEvent("Ignoring message as it's targeted to " + ignoredSite, 3);
|
||||||
}
|
// return;
|
||||||
}
|
// }
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
Miscellaneous.logEvent("Message not for me.", 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
GUI.getInstance().handleNewMessage(object);
|
|
||||||
}
|
}
|
||||||
catch(Exception e)
|
catch(Exception e)
|
||||||
{
|
{
|
||||||
@ -283,7 +268,7 @@ public class MQTT implements MqttCallbackExtended
|
|||||||
// else
|
// else
|
||||||
// timeoutTimer.cancel();
|
// timeoutTimer.cancel();
|
||||||
|
|
||||||
timeoutTimer.schedule(timerTask, timeout);
|
timeoutTimer.schedule(timerTask, Settings.sessionTimeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
void unscheduleTimeout()
|
void unscheduleTimeout()
|
||||||
|
@ -21,6 +21,7 @@ public class Settings
|
|||||||
public final static String settingsTtsSoundFileVariable = "<soundFilePath>";
|
public final static String settingsTtsSoundFileVariable = "<soundFilePath>";
|
||||||
public final static long notificationWaitPeriod = 60*60*24;
|
public final static long notificationWaitPeriod = 60*60*24;
|
||||||
public final static int programVersion = 1;
|
public final static int programVersion = 1;
|
||||||
|
public final static long sessionTimeout = 120000;
|
||||||
|
|
||||||
public final static String jsonObjectStringSiteId = "siteId";
|
public final static String jsonObjectStringSiteId = "siteId";
|
||||||
public final static String jsonObjectStringSessionId = "sessionId";
|
public final static String jsonObjectStringSessionId = "sessionId";
|
||||||
@ -102,7 +103,7 @@ public class Settings
|
|||||||
public static String mqttClientUsername;
|
public static String mqttClientUsername;
|
||||||
public static String mqttClientPassword;
|
public static String mqttClientPassword;
|
||||||
|
|
||||||
public static String ignoredSatellites;
|
// public static String ignoredSatellites;
|
||||||
|
|
||||||
public static String siteId;
|
public static String siteId;
|
||||||
|
|
||||||
@ -146,7 +147,7 @@ public class Settings
|
|||||||
mqttClientUseAuthentication = Boolean.parseBoolean(prop.getProperty("mqttClientUseAuthentication", String.valueOf(default_mqttClientUseAuthentication)));
|
mqttClientUseAuthentication = Boolean.parseBoolean(prop.getProperty("mqttClientUseAuthentication", String.valueOf(default_mqttClientUseAuthentication)));
|
||||||
mqttClientUsername = prop.getProperty("mqttClientUsername", default_mqttClientUsername);
|
mqttClientUsername = prop.getProperty("mqttClientUsername", default_mqttClientUsername);
|
||||||
mqttClientPassword = prop.getProperty("mqttClientPassword", default_mqttClientPassword);
|
mqttClientPassword = prop.getProperty("mqttClientPassword", default_mqttClientPassword);
|
||||||
ignoredSatellites = prop.getProperty("ignoredSatellites", default_ignoredSatellites);
|
// ignoredSatellites = prop.getProperty("ignoredSatellites", default_ignoredSatellites);
|
||||||
|
|
||||||
siteId = prop.getProperty("siteId", default_siteId);
|
siteId = prop.getProperty("siteId", default_siteId);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user