I want to check on start of App if RGB diodes are lighting on ESP8266. So, I'm sending to smartphone from ESP data via UDP like this:
srvUDP:send("RED="..Fulfillment1.. ";GREEN="..Fulfillment2..";BLUE=".. Fulfillment3);
and receiving on Android App like this:
(... Bla Bla Bla... DatagramSocket and DatagramSocket...)
protected void onPostExecute(Boolean result){
if (result){
receive = false; }
else {
if(receive=true) {
if(reveivedData!=null) {
colors.clear();
TextView textViewOdebrane = (TextView) findViewById(R.id.textViewReveivedData);
textViewReveivedData.setText(" " + reveivedData);
receive = false;
String color = null;
String value = null;
StringTokenizer stringTokenizer = new StringTokenizer(odebrane, "=;");
StringBuilder string123 = null;
while (stringTokenizer.hasMoreTokens()) {
color = stringTokenizer.nextToken();
value = stringTokenizer.nextToken();
colors.add(new color_value(Color, Value));
}
string123 = new StringBuilder();
int sizeOfList= colors.size(); //colors is List<>
for (int i = 0; i < sizeOfList; ++i){
string123.append("\n Fulfillment of " + colors.get(i).getColor() + " = " + colors.get(i).getValue() + "%");
}
TextView textviewOdebrane = (TextView) findViewById(R.id.textViewOdebraneDane);
textviewOdebrane.setText(string123);
if (sizeOfList == 3) {
ToggleButton toggleButtonRed = (ToggleButton) findViewById(R.id.toggleButtonRED);
ToggleButton toggleButtonGreen = (ToggleButton) findViewById(R.id.toggleButtonGREEN);
ToggleButton toggleButtonBlue = (ToggleButton) findViewById(R.id.toggleButtonBLUE);
if (!(colors.get(0).getValue().toString().equals("0"))){
toggleButtonRed.setChecked(true);
}
else { toggleButtonRed.setChecked(false);}
if (!(colors.get(1).getValue().toString().equals("0"))){
toggleButtonGreen.setChecked(true);
}
else { toggleButtonGreen.setChecked(false);}
if (!(colors.get(2).getValue().toString().equals("0"))){
toggleButtonBlue.setChecked(true);
}
else { toggleButtonBlue.setChecked(false);}
}
and I've got problem at the last if statement. if's for get(0) and get(1) works fine, but if statement for get(2) always gives me toggleButtonBlue.setChecked(true)
Can somebody tell me what is wrong here? How can I fix it?
Aucun commentaire:
Enregistrer un commentaire