@Override public void setCharge(View v) { JSONObject message = new JSONObject(); try { message.put(Constants.JSON_NAME, name); message.put(Constants.JSON_MESSAGE, "Charge value change"); message.put(Constants.JSON_CHARGE_VALUE, charge); message.put(Constants.JSON_SPHERO_NUMBER, position); } catch (JSONException e) { Log.e(Constants.LOG_TAG, "Error writing JSON", e); } communicationThread.write(message.toString()); }