|
|
@@ -1,14 +1,21 @@ |
|
|
|
package com.example.greenwatch.repositories; |
|
|
|
|
|
|
|
|
|
|
|
import android.util.Log; |
|
|
|
|
|
|
|
import androidx.lifecycle.MutableLiveData; |
|
|
|
|
|
|
|
import com.example.greenwatch.models.Device; |
|
|
|
import com.example.greenwatch.communication.WiFiCommunication; |
|
|
|
|
|
|
|
import java.net.Inet4Address; |
|
|
|
import java.net.InetAddress; |
|
|
|
import java.net.NetworkInterface; |
|
|
|
import java.net.SocketException; |
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.Enumeration; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.UUID; |
|
|
@@ -106,7 +113,8 @@ public class DeviceRepository { |
|
|
|
.append(delimiter) |
|
|
|
.append("Gruppe3") |
|
|
|
.append(delimiter) |
|
|
|
.append(device.getDeviceID()) |
|
|
|
//.append(device.getDeviceID()) |
|
|
|
.append(getLocalIpAddress(deviceID)) |
|
|
|
.append(delimiter) |
|
|
|
.append(device.getSensorStatus()) |
|
|
|
.append(delimiter) |
|
|
@@ -329,4 +337,25 @@ public class DeviceRepository { |
|
|
|
} |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
public String getLocalIpAddress(String deviceID) { |
|
|
|
String checkedDeviceID = checkDeviceID(deviceID); |
|
|
|
Device device = connectedDevicesList.get(checkedDeviceID); |
|
|
|
if(device != null){ |
|
|
|
try { |
|
|
|
for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) { |
|
|
|
NetworkInterface networkInterface = (NetworkInterface) ((Enumeration<?>) en).nextElement(); |
|
|
|
for (Enumeration<InetAddress> addresses = networkInterface.getInetAddresses(); addresses.hasMoreElements();) { |
|
|
|
InetAddress inetAddress = addresses.nextElement(); |
|
|
|
if (!inetAddress.isLoopbackAddress() && inetAddress instanceof Inet4Address) { |
|
|
|
return inetAddress.getHostAddress(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (SocketException ex) { |
|
|
|
ex.printStackTrace(); |
|
|
|
} |
|
|
|
} |
|
|
|
return ""; |
|
|
|
} |
|
|
|
} |