Hi, i am rizal.
i got problem about controll relay from android. i want every time user click button relay on .
i have ubidots account, if i press widget button from things.ubidots.com relay connected perfectly. but my problem if i control via android.i search in this forum and i try every code but nothing. please help.
i use android studio. for get value from ubidots to android , i already done.
my code for send data to ubidots :
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pemupukan);
ImageButton siram_pupuk = findViewById(R.id.buttonpemupukan);
mPupukLevel = (TextView) findViewById(R.id.jarak_pupuk);
status_pupuk = (TextView) findViewById(R.id.textView4);
siram_pupuk.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
Toast.makeText(getApplicationContext(), "ON", Toast.LENGTH_SHORT).show();
SendApiUbidots sendApi = new SendApiUbidots();
sendApi.execute();
}
});
new ApiUbidots().execute(5);
//return null;
}
public class SendApiUbidots extends AsyncTask<Integer, Void, Void>{
private final String API_KEY = "YOUR API-KEY";
private final String VARIABLE_ID_2 = "YOUR VARIABLE";
@Override
protected Void doInBackground(Integer... params) {
ApiClient apiClient = new ApiClient(API_KEY);
Variable switchVariable = apiClient.getVariable(VARIABLE_ID_2);
switchVariable.saveValue(params[0]);
return null;
}}
}