Skip to content

Commit

Permalink
remove UUID generation
Browse files Browse the repository at this point in the history
  • Loading branch information
hajoha committed Jan 28, 2025
1 parent 1026b14 commit cee64ce
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,7 @@ public Map<String, String> getTagsMap() {
tags_map_modifiable.put("android_version", di.getAndroidRelease());
tags_map_modifiable.put("security_patch", di.getSecurityPatchLevel());
String device = spg.getSharedPreference(SPType.default_sp).getString("device_name", "null").strip();
if(device.equals("null")) device = UUID.randomUUID().toString();
//if(device.equals("null")); TODO handle this
tags_map.put("device", device);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
tags_map_modifiable.put("soc_model", di.getSOCModel());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public class MQTTService extends Service {
private Handler notificationHandler;
private Mqtt5AsyncClient client;
private SharedPreferencesGrouper spg;
private String deviceName;

@Nullable
@Override
Expand Down Expand Up @@ -174,7 +175,7 @@ public void connectClient(){
CompletableFuture<Mqtt5ConnAck> connAck = client.connectWith()
.keepAlive(10)
.willPublish()
.topic("device/OMNT3/status")
.topic(String.format("device/%s/status", deviceName))
.qos(MqttQos.EXACTLY_ONCE)
.payload("offline".getBytes())
.retain(true)
Expand Down Expand Up @@ -351,7 +352,7 @@ public void run() {

private void subscribeToAllTopics(){
// TODO fix hardcoded deviceID
subsribetoTopic("device/OMNT3/#");
subsribetoTopic(String.format("device/%s/#", deviceName));
}


Expand All @@ -361,6 +362,7 @@ public int onStartCommand(Intent intent, int flags, int startId) {
Log.d(TAG, "onStartCommand: Start MQTT service");
context = getApplicationContext();
mqttSP = SharedPreferencesGrouper.getInstance(context).getSharedPreference(SPType.mqtt_sp);
deviceName = SharedPreferencesGrouper.getInstance(context).getSharedPreference(SPType.default_sp).getString("device_name", "null").strip();
startForeground(3, builder.build());
setupSharedPreferences();
createClient();
Expand Down

0 comments on commit cee64ce

Please sign in to comment.