Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private fun update()
- {
- // Get status of SW1 and LED1
- val Sprinkle_status = if (switchSprinkle.isChecked) 1 else 0
- val Photo_status = if (switchPhoto.isChecked) 1 else 0
- val url = "https://unlimitedphelotelia.000webhostapp.com/scripts/sync_data.php"
- val jsonObject = JSONObject()
- jsonObject.put("username", "ben")
- jsonObject.put("password", "benpass")
- jsonObject.put("SW1", Sprinkle_status)
- jsonObject.put("SW2", Photo_status)
- jsonObject.put("sender", "ANDROID")
- Toast.makeText(this, jsonObject.toString(), Toast.LENGTH_LONG).show()
- val jsonObjectRequest = JsonObjectRequest(Request.Method.POST, url,
- jsonObject,
- Response.Listener<JSONObject> {response ->
- if (response["success"] == 1) {
- switchRain.text = response.toString()
- // Set the statuses to the ones received
- //refreshSwitch = false
- //switchRain.isChecked = (response.get("rain") == 1)
- //switchMotion.isChecked = (response.get("motion") == 1)
- //refreshSwitch = true
- //Toast.makeText(this, "It succeeded!",
- // Toast.LENGTH_LONG).show()
- }
- else
- {
- Toast.makeText(this, "It failed...",
- Toast.LENGTH_LONG).show()
- }
- },
- Response.ErrorListener {
- Toast.makeText(this, it.toString(), Toast.LENGTH_LONG).show()
- })
- Volley.newRequestQueue(this).add(jsonObjectRequest)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement