80 lines
2.4 KiB
Java
80 lines
2.4 KiB
Java
package de.ctdo.crashtest;
|
|
|
|
import org.apache.http.HttpResponse;
|
|
import org.apache.http.client.ClientProtocolException;
|
|
import org.apache.http.client.HttpClient;
|
|
import org.apache.http.client.methods.HttpPost;
|
|
import org.apache.http.entity.StringEntity;
|
|
import org.apache.http.impl.client.DefaultHttpClient;
|
|
|
|
import java.io.IOException;
|
|
import java.io.UnsupportedEncodingException;
|
|
|
|
/**
|
|
* User: lpless
|
|
* Date: 10.05.12
|
|
* Time: 11:03
|
|
*/
|
|
public class BuntiClient {
|
|
String baseAddress;
|
|
HttpClient client = new DefaultHttpClient();
|
|
|
|
public BuntiClient(String server, int port) {
|
|
baseAddress = "http://" + server + ":" + port + "/";
|
|
}
|
|
|
|
public void setPar56(int id, int red, int green, int blue) {
|
|
try {
|
|
HttpPost post = new HttpPost(baseAddress + "/control/devices");
|
|
post.addHeader("Content-Type", "application/json");
|
|
|
|
StringEntity entity = new StringEntity(
|
|
"{ \"timeStamp\": 0, \"updates\": [ {\"deviceId\": "+id+", \"options\": { \"red\": "+
|
|
red+", \"green\": "+green+", \"blue\": "+blue+" } } ] }" ,
|
|
"UTF-8");
|
|
|
|
post.setEntity(entity);
|
|
|
|
HttpResponse response = client.execute(post);
|
|
System.out.println(response);
|
|
|
|
post.abort();
|
|
|
|
} catch (UnsupportedEncodingException e) {
|
|
e.printStackTrace();
|
|
} catch (ClientProtocolException e) {
|
|
e.printStackTrace();
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
}
|
|
|
|
}
|
|
|
|
public void setLampel(boolean red, boolean yellow, boolean green) {
|
|
try {
|
|
HttpPost post = new HttpPost(baseAddress + "/control/devices");
|
|
post.addHeader("Content-Type", "application/json");
|
|
|
|
StringEntity entity = new StringEntity(
|
|
"{ \"timeStamp\": 0, \"updates\": [ {\"deviceId\": 4, \"options\": { \"red\": "+
|
|
red+", \"green\": "+green+", \"yellow\": "+yellow+" } } ] }" ,
|
|
"UTF-8");
|
|
|
|
post.setEntity(entity);
|
|
|
|
HttpResponse response = client.execute(post);
|
|
System.out.println(response);
|
|
|
|
post.abort();
|
|
|
|
} catch (UnsupportedEncodingException e) {
|
|
e.printStackTrace();
|
|
} catch (ClientProtocolException e) {
|
|
e.printStackTrace();
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
|
|
}
|