From 0c8c9ad976879f7c90f9915a60845ccb0cdb337d Mon Sep 17 00:00:00 2001 From: manuel Date: Wed, 25 Dec 2013 13:25:16 +0100 Subject: initial commit --- .../src/com/trouch/webiopi/client/PiClient.java | 38 ++++++++++++ .../com/trouch/webiopi/client/PiCoapClient.java | 57 ++++++++++++++++++ .../com/trouch/webiopi/client/PiHttpClient.java | 68 ++++++++++++++++++++++ .../com/trouch/webiopi/client/PiMixedClient.java | 56 ++++++++++++++++++ .../trouch/webiopi/client/PiMulticastClient.java | 27 +++++++++ .../com/trouch/webiopi/client/devices/Device.java | 44 ++++++++++++++ .../trouch/webiopi/client/devices/analog/ADC.java | 34 +++++++++++ .../trouch/webiopi/client/devices/analog/DAC.java | 37 ++++++++++++ .../trouch/webiopi/client/devices/analog/PWM.java | 33 +++++++++++ .../webiopi/client/devices/digital/GPIO.java | 53 +++++++++++++++++ .../webiopi/client/devices/digital/NativeGPIO.java | 26 +++++++++ .../webiopi/client/devices/sensor/Distance.java | 30 ++++++++++ .../webiopi/client/devices/sensor/Luminosity.java | 30 ++++++++++ .../webiopi/client/devices/sensor/Pressure.java | 34 +++++++++++ .../webiopi/client/devices/sensor/Temperature.java | 34 +++++++++++ 15 files changed, 601 insertions(+) create mode 100644 java/client/src/com/trouch/webiopi/client/PiClient.java create mode 100644 java/client/src/com/trouch/webiopi/client/PiCoapClient.java create mode 100644 java/client/src/com/trouch/webiopi/client/PiHttpClient.java create mode 100644 java/client/src/com/trouch/webiopi/client/PiMixedClient.java create mode 100644 java/client/src/com/trouch/webiopi/client/PiMulticastClient.java create mode 100644 java/client/src/com/trouch/webiopi/client/devices/Device.java create mode 100644 java/client/src/com/trouch/webiopi/client/devices/analog/ADC.java create mode 100644 java/client/src/com/trouch/webiopi/client/devices/analog/DAC.java create mode 100644 java/client/src/com/trouch/webiopi/client/devices/analog/PWM.java create mode 100644 java/client/src/com/trouch/webiopi/client/devices/digital/GPIO.java create mode 100644 java/client/src/com/trouch/webiopi/client/devices/digital/NativeGPIO.java create mode 100644 java/client/src/com/trouch/webiopi/client/devices/sensor/Distance.java create mode 100644 java/client/src/com/trouch/webiopi/client/devices/sensor/Luminosity.java create mode 100644 java/client/src/com/trouch/webiopi/client/devices/sensor/Pressure.java create mode 100644 java/client/src/com/trouch/webiopi/client/devices/sensor/Temperature.java (limited to 'java/client/src/com/trouch') diff --git a/java/client/src/com/trouch/webiopi/client/PiClient.java b/java/client/src/com/trouch/webiopi/client/PiClient.java new file mode 100644 index 0000000..96a4f63 --- /dev/null +++ b/java/client/src/com/trouch/webiopi/client/PiClient.java @@ -0,0 +1,38 @@ +/* Copyright 2013 Eric Ptak - trouch.com + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +package com.trouch.webiopi.client; + +import org.apache.commons.codec.binary.Base64; + +public abstract class PiClient { + + protected String urlBase; + protected String auth; + + public static String encodeCredentials(String login, String password) { + return Base64.encodeBase64String((login + ":" + password).getBytes()); + } + + public PiClient(String protocol, String host, int port) { + this.urlBase = protocol + "://" + host + ":" + port; + } + + public void setCredentials(String login, String password) { + this.auth = "Basic " + encodeCredentials(login, password); + } + + public abstract String sendRequest(String method, String path) throws Exception; + +} diff --git a/java/client/src/com/trouch/webiopi/client/PiCoapClient.java b/java/client/src/com/trouch/webiopi/client/PiCoapClient.java new file mode 100644 index 0000000..4a4f2d3 --- /dev/null +++ b/java/client/src/com/trouch/webiopi/client/PiCoapClient.java @@ -0,0 +1,57 @@ +/* Copyright 2013 Eric Ptak - trouch.com + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +package com.trouch.webiopi.client; + +import com.trouch.coap.client.CoapClient; +import com.trouch.coap.messages.CoapRequest; +import com.trouch.coap.messages.CoapResponse; +import com.trouch.coap.methods.CoapGet; +import com.trouch.coap.methods.CoapPost; + + +public class PiCoapClient extends PiClient { + public final static int DEFAULT_PORT = 5683; + private CoapClient client; + + public PiCoapClient(String host) { + super("coap", host, DEFAULT_PORT); + client = new CoapClient(); + } + + public PiCoapClient(String host, int port) { + super("coap", host, port); + client = new CoapClient(); + } + + @Override + public String sendRequest(String method, String path) throws Exception { + CoapRequest request; + if (method == "GET") { + request = new CoapGet(this.urlBase + path); + } + else if (method == "POST") { + request = new CoapPost(this.urlBase + path); + } + else throw new Exception("Method not supported: " + method); + + CoapResponse response = client.sendRequest(request); + if (response != null) { + return response.getPayload(); + } + + return null; + } + +} diff --git a/java/client/src/com/trouch/webiopi/client/PiHttpClient.java b/java/client/src/com/trouch/webiopi/client/PiHttpClient.java new file mode 100644 index 0000000..6562bc7 --- /dev/null +++ b/java/client/src/com/trouch/webiopi/client/PiHttpClient.java @@ -0,0 +1,68 @@ +/* Copyright 2013 Eric Ptak - trouch.com + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +package com.trouch.webiopi.client; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; + +public class PiHttpClient extends PiClient { + public final static int DEFAULT_PORT = 8000; + + public PiHttpClient(String host) { + super("http", host, DEFAULT_PORT); + } + + public PiHttpClient(String host, int port) { + super("http", host, port); + } + + @Override + public String sendRequest(String method, String path) throws Exception { + BufferedReader reader = null; + try { + URL url = new URL(this.urlBase + path); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod(method); + if (this.auth != null) { + connection.setRequestProperty("Authorization", this.auth); + } + + // read the output from the server + reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); + StringBuilder stringBuilder = new StringBuilder(); + + String line = null; + while ((line = reader.readLine()) != null) { + stringBuilder.append(line).append('\n'); + } + return stringBuilder.toString(); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } finally { + if (reader != null) { + try { + reader.close(); + } catch (IOException ioe) { + ioe.printStackTrace(); + } + } + } + } + +} diff --git a/java/client/src/com/trouch/webiopi/client/PiMixedClient.java b/java/client/src/com/trouch/webiopi/client/PiMixedClient.java new file mode 100644 index 0000000..8922f6f --- /dev/null +++ b/java/client/src/com/trouch/webiopi/client/PiMixedClient.java @@ -0,0 +1,56 @@ +/* Copyright 2013 Eric Ptak - trouch.com + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +package com.trouch.webiopi.client; + +public class PiMixedClient extends PiClient { + private PiHttpClient http; + private PiCoapClient coap; + + private int tries = 0; + private int maxTries = 3; + + public PiMixedClient(String host) { + super("", "", 0); + http = new PiHttpClient(host); + coap = new PiCoapClient(host); + } + + public PiMixedClient(String host, int httpPort, int coapPort) { + super("", "", 0); + http = new PiHttpClient(host, httpPort); + coap = new PiCoapClient(host, coapPort); + } + + @Override + public void setCredentials(String login, String password) { + http.setCredentials(login, password); + coap.setCredentials(login, password); + } + + @Override + public String sendRequest(String method, String path) throws Exception { + if (tries < maxTries) { + String response = coap.sendRequest(method, path); + if (response != null) { + tries = 0; + return response; + } + tries++; + } + + return http.sendRequest(method, path); + } + +} diff --git a/java/client/src/com/trouch/webiopi/client/PiMulticastClient.java b/java/client/src/com/trouch/webiopi/client/PiMulticastClient.java new file mode 100644 index 0000000..22b1d9e --- /dev/null +++ b/java/client/src/com/trouch/webiopi/client/PiMulticastClient.java @@ -0,0 +1,27 @@ +/* Copyright 2013 Eric Ptak - trouch.com + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +package com.trouch.webiopi.client; + +public class PiMulticastClient extends PiCoapClient { + + public PiMulticastClient() { + super("224.0.1.123", PiMulticastClient.DEFAULT_PORT); + } + + public PiMulticastClient(int port) { + super("224.0.1.123", port); + } + +} diff --git a/java/client/src/com/trouch/webiopi/client/devices/Device.java b/java/client/src/com/trouch/webiopi/client/devices/Device.java new file mode 100644 index 0000000..b12139d --- /dev/null +++ b/java/client/src/com/trouch/webiopi/client/devices/Device.java @@ -0,0 +1,44 @@ +/* Copyright 2013 Eric Ptak - trouch.com + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +package com.trouch.webiopi.client.devices; + +import com.trouch.webiopi.client.PiClient; + +public class Device { + + private PiClient client; + protected String path; + + public Device(PiClient client, String deviceName, String type) { + this.client = client; + if (type != null) { + this.path = "/devices/" + deviceName + "/" + type; + } + else { + this.path = "/devices/" + deviceName; + } + } + + public String sendRequest(String method, String subPath) { + try { + return this.client.sendRequest(method, this.path + subPath); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + return null; + } + } + +} diff --git a/java/client/src/com/trouch/webiopi/client/devices/analog/ADC.java b/java/client/src/com/trouch/webiopi/client/devices/analog/ADC.java new file mode 100644 index 0000000..f8c349e --- /dev/null +++ b/java/client/src/com/trouch/webiopi/client/devices/analog/ADC.java @@ -0,0 +1,34 @@ +/* Copyright 2013 Eric Ptak - trouch.com + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +package com.trouch.webiopi.client.devices.analog; + +import com.trouch.webiopi.client.PiClient; +import com.trouch.webiopi.client.devices.Device; + +public class ADC extends Device { + + public ADC(PiClient client, String deviceName) { + super(client, deviceName, "analog"); + } + + public ADC(PiClient client, String deviceName, String type) { + super(client, deviceName, type); + } + + public float readFloat(int channel) { + return Float.parseFloat(this.sendRequest("GET", "/" + channel + "/float")); + } + +} diff --git a/java/client/src/com/trouch/webiopi/client/devices/analog/DAC.java b/java/client/src/com/trouch/webiopi/client/devices/analog/DAC.java new file mode 100644 index 0000000..901d9c4 --- /dev/null +++ b/java/client/src/com/trouch/webiopi/client/devices/analog/DAC.java @@ -0,0 +1,37 @@ +/* Copyright 2013 Eric Ptak - trouch.com + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +package com.trouch.webiopi.client.devices.analog; + +import com.trouch.webiopi.client.PiClient; + +public class DAC extends ADC { + + public DAC(PiClient client, String deviceName) { + super(client, deviceName); + } + + public DAC(PiClient client, String deviceName, String type) { + super(client, deviceName, type); + } + + public float writeFloat(int channel, float value) { + return Float.parseFloat(this.sendRequest("POST", "/" + channel + "/float/" + value)); + } + + public float writeVolt(int channel, float value) { + return Float.parseFloat(this.sendRequest("POST", "/" + channel + "/volt/" + value)); + } + +} diff --git a/java/client/src/com/trouch/webiopi/client/devices/analog/PWM.java b/java/client/src/com/trouch/webiopi/client/devices/analog/PWM.java new file mode 100644 index 0000000..fdc4674 --- /dev/null +++ b/java/client/src/com/trouch/webiopi/client/devices/analog/PWM.java @@ -0,0 +1,33 @@ +/* Copyright 2013 Eric Ptak - trouch.com + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +package com.trouch.webiopi.client.devices.analog; + +import com.trouch.webiopi.client.PiClient; + +public class PWM extends DAC { + + public PWM(PiClient client, String deviceName) { + super(client, deviceName, "pwm"); + } + + public float readAngle(int channel) { + return Float.parseFloat(this.sendRequest("GET", "/" + channel + "/angle")); + } + + public float writeAngle(int channel, float angle) { + return Float.parseFloat(this.sendRequest("POST", "/" + channel + "/angle/" + angle)); + } + +} diff --git a/java/client/src/com/trouch/webiopi/client/devices/digital/GPIO.java b/java/client/src/com/trouch/webiopi/client/devices/digital/GPIO.java new file mode 100644 index 0000000..c08dff5 --- /dev/null +++ b/java/client/src/com/trouch/webiopi/client/devices/digital/GPIO.java @@ -0,0 +1,53 @@ +/* Copyright 2013 Eric Ptak - trouch.com + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +package com.trouch.webiopi.client.devices.digital; + +import com.trouch.webiopi.client.PiClient; +import com.trouch.webiopi.client.devices.Device; + +public class GPIO extends Device { + + public final static String OUT = "OUT"; + public final static String IN = "IN"; + + public GPIO(PiClient client, String deviceName) { + super(client, deviceName, null); + } + + public String getFunction(int channel) { + return this.sendRequest("GET", "/" + channel + "/function"); + } + + public String setFunction(int channel, String function) { + return this.sendRequest("POST", "/" + channel + "/function/" + function); + } + + public boolean digitalRead(int channel) { + String res = this.sendRequest("GET", "/" + channel + "/value"); + if (res.equals("1")) { + return true; + } + return false; + } + + public boolean digitalWrite(int channel, boolean value) { + String res = this.sendRequest("POST", "/" + channel + "/value/" + (value ? "1" : "0")); + if (res.equals("1")) { + return true; + } + return false; + } + +} diff --git a/java/client/src/com/trouch/webiopi/client/devices/digital/NativeGPIO.java b/java/client/src/com/trouch/webiopi/client/devices/digital/NativeGPIO.java new file mode 100644 index 0000000..a5bc05b --- /dev/null +++ b/java/client/src/com/trouch/webiopi/client/devices/digital/NativeGPIO.java @@ -0,0 +1,26 @@ +/* Copyright 2013 Eric Ptak - trouch.com + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +package com.trouch.webiopi.client.devices.digital; + +import com.trouch.webiopi.client.PiClient; + +public class NativeGPIO extends GPIO { + + public NativeGPIO(PiClient client) { + super(client, ""); + this.path = "/GPIO"; + } + +} diff --git a/java/client/src/com/trouch/webiopi/client/devices/sensor/Distance.java b/java/client/src/com/trouch/webiopi/client/devices/sensor/Distance.java new file mode 100644 index 0000000..63ac485 --- /dev/null +++ b/java/client/src/com/trouch/webiopi/client/devices/sensor/Distance.java @@ -0,0 +1,30 @@ +/* Copyright 2013 Eric Ptak - trouch.com + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +package com.trouch.webiopi.client.devices.sensor; + +import com.trouch.webiopi.client.PiClient; +import com.trouch.webiopi.client.devices.Device; + +public class Distance extends Device { + + public Distance(PiClient client, String deviceName) { + super(client, deviceName, "sensor"); + } + + public float getMillimeter() { + return Float.parseFloat(this.sendRequest("GET", "/distance/mm")); + } + +} diff --git a/java/client/src/com/trouch/webiopi/client/devices/sensor/Luminosity.java b/java/client/src/com/trouch/webiopi/client/devices/sensor/Luminosity.java new file mode 100644 index 0000000..29eda32 --- /dev/null +++ b/java/client/src/com/trouch/webiopi/client/devices/sensor/Luminosity.java @@ -0,0 +1,30 @@ +/* Copyright 2013 Eric Ptak - trouch.com + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +package com.trouch.webiopi.client.devices.sensor; + +import com.trouch.webiopi.client.PiClient; +import com.trouch.webiopi.client.devices.Device; + +public class Luminosity extends Device { + + public Luminosity(PiClient client, String deviceName) { + super(client, deviceName, "sensor"); + } + + public float getLux() { + return Float.parseFloat(this.sendRequest("GET", "/luminosity/lx")); + } + +} diff --git a/java/client/src/com/trouch/webiopi/client/devices/sensor/Pressure.java b/java/client/src/com/trouch/webiopi/client/devices/sensor/Pressure.java new file mode 100644 index 0000000..1f766a9 --- /dev/null +++ b/java/client/src/com/trouch/webiopi/client/devices/sensor/Pressure.java @@ -0,0 +1,34 @@ +/* Copyright 2013 Eric Ptak - trouch.com + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +package com.trouch.webiopi.client.devices.sensor; + +import com.trouch.webiopi.client.PiClient; +import com.trouch.webiopi.client.devices.Device; + +public class Pressure extends Device { + + public Pressure(PiClient client, String deviceName) { + super(client, deviceName, "sensor"); + } + + public float getHectoPascal() { + return Float.parseFloat(this.sendRequest("GET", "/pressure/hpa")); + } + + public float getPascal() { + return Float.parseFloat(this.sendRequest("GET", "/pressure/pa")); + } + +} diff --git a/java/client/src/com/trouch/webiopi/client/devices/sensor/Temperature.java b/java/client/src/com/trouch/webiopi/client/devices/sensor/Temperature.java new file mode 100644 index 0000000..160e32f --- /dev/null +++ b/java/client/src/com/trouch/webiopi/client/devices/sensor/Temperature.java @@ -0,0 +1,34 @@ +/* Copyright 2013 Eric Ptak - trouch.com + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +package com.trouch.webiopi.client.devices.sensor; + +import com.trouch.webiopi.client.PiClient; +import com.trouch.webiopi.client.devices.Device; + +public class Temperature extends Device { + + public Temperature(PiClient client, String deviceName) { + super(client, deviceName, "sensor"); + } + + public float getCelsius() { + return Float.parseFloat(this.sendRequest("GET", "/temperature/c")); + } + + public float getFahrenheit() { + return Float.parseFloat(this.sendRequest("GET", "/temperature/f")); + } + +} -- cgit v1.2.3