I am a beginner to android and Arduino. I am working on a smart home project where i need to control lights from a smartphone application. I want an example on how to create http post request to communicate with my Arduino from the mobile application and vice versa. I have also learnt that the post request must be performed in an async class as it consumes time. I also need examples where to write the post request.
Asked
Active
Viewed 453 times
1 Answers
0
You can do this only if Web Server which can process POST
requests with commands from your Android app and translate it to commands Arduino device (or if You have Web Server directly on Arduino device). On Android side there is no features for it: You can use any POST-request examples, for example this.

Community
- 1
- 1

Andrii Omelchenko
- 13,183
- 12
- 43
- 79
-
i need more explanations concerning the post request in terms of why putting it in an async class. The Android and Arduino communicates via JSON request. I need an example comprising on some codes in terms of whole structure of MainActivity of an android app together with the post request and JSON request – Adarsh Ramlackhan Nov 04 '16 at 16:38
-
"of why putting it in an async class" because do it in UI thread prohibited see, for example [this](http://stackoverflow.com/questions/6343166/how-to-fix-android-os-networkonmainthreadexception). For beginning You can implement [this](https://www.studytutorial.in/android-httpurlconnection-post-and-get-request-tutorial) example. – Andrii Omelchenko Nov 04 '16 at 16:57
-
i looked at the example...From what i have understood is that an async method does not execute in the main thread of the application..is that it? Another question, i have to constantly open connection to listen to request from my Arduino. How can i implement this functionality? With what logic? – Adarsh Ramlackhan Nov 04 '16 at 18:04
-
"constantly open connection" absolutely same way as You do that for Arduino<->Web Server interconnection. "constantly open connection" You can create for example with streams via Sockets ([Official Documentation](https://developer.android.com/reference/java/net/Socket.html) and [example](http://android-er.blogspot.com/2014/02/android-sercerclient-example-client.html)). Actually example may be not best - You can "google" much understandable for You. – Andrii Omelchenko Nov 04 '16 at 18:12