문제

Hi Im trying to develop an application through which one can control raspberry pi over the Internet using an android device. My Raspberry pi runs Java ME. My question is how do I make the android device and Raspberry pi talk to each other? Will HTTP request/response work? Please give me some ideas.

도움이 되었습니까?

해결책

I did something similar to this recently - I had an Android app talking to a Windows PC (C# app). I used Websockets myself, I would recommend looking down this avenue - far more efficient/faster for bi-directional communication than HTTP.

If you chose this approach look for a Java Websocket implementation (perhaps this) and have the Raspberry Pi running a server that the Android app can connect and send messages to.

다른 팁

A very easy way to build the communication between Android phone and Raspberry Pi :

  1. Install LAMPP ( https://www.youtube.com/watch?v=CEji-qN-TEE) on Raspberry Pi
  2. Write your own php script that will receive the request and will do the actions.
  3. You can create a customize Tungsten Android-app to put your own url against a button click. (https://play.google.com/store/apps/details?id=com.stochastictechnologies.tungsten&hl=en)

Enjoy !!

A colleague worked on a similar project, where he wanted to control the lights connected to a Raspberry Pi from an Android phone. If you do not want to get into the complexities of using websockets, you can try using PubNub. The pi will run the Python PubNub SDK, and the phone will use the Android PubNub SDK. The complete tutorial for Triggering Raspberry Pi Hue LEDs from Android UI is here.

Basically, PubNub opens sockets under the hood, but provides only easy to use APIs like publish and subscribe for the end user (developer). PubNub provides a set of realtime “building blocks”; services that take advantage of an open socket connection.

You can connect your raspberry pi to your Android device with VNC's easily. You just need to allow the raspberry pi to be connected via VNC then with any VNC app (I use bVNC) you can control your raspberry pi! You don't even need a monitor for this, check out the official tutorial: https://www.raspberrypi.org/documentation/remote-access/vnc/

Another possible approach, depending on your conditions: For a project at work we just run successfully Java-written Agents on an Android devices and on RPis using the JADE-Framework. Creating Agents is pretty streight forward, only coding actions and reactions more or less. Since it's Java on the Pi(s) it shall be possible to access the hardware of the Pi quite easily through the pi's agent(s) (e.g. Pi4J Library for GPIO Access). But might be critical/impossible via the internet, so if not all agents are in the same network.

Another approach, but nothing new to the above post: I also did something similar by an PHP API on the Pi which I call from an Android App.

Probably you could try using Android Things to install another app and communicate with the devices. If you're already an android developer it won't be an issue to set up the Pi on Android things and might benefit you by reducing the development time

I used sockets over a LAN, worked fine for me. Back and forth commmunication over http would possibly require a sql db, to store and retrieve results, especially in real time.

Have the pi poll using http the central db, and turn on the db switch using the android device.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top