i wrote python script to read "Temperature/Humidity" data from sensor and it works fine and return result "23.0/38.0".
i need to put 23.0 in object member variable "temperature" and 38.0 in "Humidity" member variable then return the sensor object.
my problem is , the created web service return temperature and Humidity variable empty.
package raspberryws;
import java.io.IOException;
import java.io.InputStream;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
@Path("DHTService")
public class DHTService {
public DHTService() {
super();
}
@GET
@Produces(value = { "application/json" })
@Path("/readDHT")
public DHTSensor readDHT11() throws IOException {
DHTSensor sensor = new DHTSensor();
int ch;
char y;
String temp="" ;
String humidity="" ;
try {
Process p =
Runtime.getRuntime().exec("sudo python /projects/Adafruit_Python_DHT/examples/AdafruitDHT.py 11 4 ");
// get an InputStream for the python stdout
InputStream inStream = p.getInputStream();
// read all stdout data one char at a time.
while ((ch = inStream.read()) != -1) {
System.out.println(ch + " ch");
if ((int) ch == 47) {
sensor.setTempreture(temp);
humidity="";
} else {
if ((int) ch == 10) {
continue;
}
y = (char) ch;
temp=temp+y;
humidity=humidity+y;
sensor.setHumidity(humidity);
}
}
} catch (IOException e) {
e.printStackTrace();
}
// System.out.println(x);
return sensor;
}
}