Standardizing Java Sample to WindSpeed
This commit is contained in:
Родитель
622923282b
Коммит
441679f39b
|
@ -5,10 +5,9 @@ package samples.com.microsoft.azure.iothub;
|
|||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
public class ContosoThermostat505 {
|
||||
public int temperature;
|
||||
public int humidity;
|
||||
public boolean LowTemperatureAlarm;
|
||||
public class ContosoAnemometer {
|
||||
public String deviceId;
|
||||
public double windSpeed;
|
||||
|
||||
public boolean TurnFanOn() {
|
||||
System.out.println("Turning fan on.");
|
||||
|
@ -20,9 +19,8 @@ public class ContosoThermostat505 {
|
|||
return true;
|
||||
}
|
||||
|
||||
public boolean SetTemperature(int desiredTemperature) {
|
||||
System.out.printf("Setting home temperature to %d degrees.\r\n", desiredTemperature);
|
||||
this.temperature = desiredTemperature;
|
||||
public boolean SetAirResistance(int position) {
|
||||
System.out.printf("Setting Air Resistance Position to %d.\r\n", position);
|
||||
return true;
|
||||
}
|
||||
|
|
@ -18,15 +18,15 @@ import javax.naming.SizeLimitExceededException;
|
|||
public class SendSerializedEvent {
|
||||
private static class ParsedArguments {
|
||||
// Data
|
||||
private static final int DEFAULT_TEMPERATURE = 65;
|
||||
private static final int DEFAULT_HUMIDITY = 72;
|
||||
private static final String DEFAULT_DEVICEID = "myFirstDevice";
|
||||
private static final double DEFAULT_WINDSPEED = 10; // m/s
|
||||
|
||||
public String[] rawArguments;
|
||||
public boolean parsedSuccessfully;
|
||||
public String connectionString;
|
||||
public IotHubClientProtocol protocol;
|
||||
public int temperature;
|
||||
public int humidity;
|
||||
public String deviceId;
|
||||
public double windSpeed;
|
||||
|
||||
// Constructors
|
||||
public ParsedArguments(String[] args) {
|
||||
|
@ -55,15 +55,15 @@ public class SendSerializedEvent {
|
|||
}
|
||||
|
||||
if(rawArguments.length >= 3) {
|
||||
temperature = Integer.parseInt(rawArguments[2]);
|
||||
deviceId = rawArguments[2];
|
||||
} else {
|
||||
temperature = DEFAULT_TEMPERATURE;
|
||||
deviceId = DEFAULT_DEVICEID;
|
||||
}
|
||||
|
||||
if(rawArguments.length >= 4) {
|
||||
humidity = Integer.parseInt(rawArguments[3]);
|
||||
windSpeed = Double.parseDouble(rawArguments[3]);
|
||||
} else {
|
||||
humidity = DEFAULT_HUMIDITY;
|
||||
windSpeed = DEFAULT_WINDSPEED;
|
||||
}
|
||||
|
||||
this.parsedSuccessfully = true;
|
||||
|
@ -92,7 +92,7 @@ public class SendSerializedEvent {
|
|||
|
||||
private static void printUsage(){
|
||||
System.out.println("Expected arguments:");
|
||||
System.out.println("[IoT Hub connection string] [https | amqps] [temperature] [humidity]");
|
||||
System.out.println("[IoT Hub connection string] [https | amqps] [deviceId] [windSpeed]");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -126,9 +126,9 @@ public class SendSerializedEvent {
|
|||
|
||||
System.out.println("Opened connection to IoT Hub.");
|
||||
|
||||
ContosoThermostat505 data = new ContosoThermostat505();
|
||||
data.temperature = arguments.temperature;
|
||||
data.humidity = arguments.humidity;
|
||||
ContosoAnemometer data = new ContosoAnemometer();
|
||||
data.deviceId = arguments.deviceId;
|
||||
data.windSpeed = arguments.windSpeed;
|
||||
|
||||
String msgStr = data.serialize();
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче