1

I'm trying to write an android app that will send information to my Pi that is on a different WiFi network. I looked into making it a web server which I'm not opposed to but I don't want to have to mess with firewalls or have to plug the pi into a router. I've also thought about making a server in the cloud that acts as a middle-man between the Pi and the Phone but I'm unsure if that would be a viable option.

I do have the most recent Raspberry Pi 3.

So what is the best option for communicating data from an android app to a raspberry pi? I'm not looking for a step by step guide just the best strategy for doing this. Any help is appreciated, thanks!

2
  • If your device is running android there's a really good chance it has Blutooth. You could use that or an adhoc wifi network.
    – Jacobm001
    Commented May 14, 2017 at 1:30
  • have a webserver in the middle facilitate the comms. Two ways to do this. 1)Pi and android both interact only with a known server (Call it method DD). Here the server needs to store the info until the other one picks it up or only accept info if both are connected at once 2) Use method DD to exchange information that can then be used to attempt a more direct connection, usually falling back to method DD for all comms if it fails. (Call it method Punch). Which are you interested in?
    – Abel
    Commented Nov 20, 2021 at 11:24

2 Answers 2

0

You could have a node.js application running on your Raspberry Pi that will receive data from a backend database.

An example of this is using Google's Firebase solution. Firebase supports Node.JS and Android applications with lots of documentation.

Your app would push data to the database and your Node.JS app could listen for updates on the database and will parse it accordingly when it recieves one. This would work on any network that has Internet access.

https://firebase.google.com/

0

Like with any TCP/IP solution, you'll need to make sure that the two machines can see each other. If they can't, you'll need to make them do so. The answer to this depends very much on your network and what is allowed.

Depending on the type of data you are transmitting, you might want to use different protocols. For small chunks of data, I'd use the MQTT protocol. I have a mosquitto server (sudo apt install mosquitto) on one of my Pi's and I use it to send data back and forth from a robot. The nice thing about MQTT is that it is easy and OTS.

The complete API looks complex, but there are only a couple of functions you need.

connect() connects you to the server. I tend to keep the connection alive for a while rather than connecting every time I need to send data. It works with ip names or addresses.

publish() is the function to send data. All publishing is done to a topic, which allows the messages to go to their subscribers.

subscribe() is the function to receive data. There can be many subscribers for a given publisher. Subscribe() works by passing a function pointer that is called whenever a new message arrives.

unsubscribe is used before you quit.

disconnect() finishes the connection.

That's it.

Most other protocols for data transmission are a bit more complex, but if just used for simple transmission of data can usually be restricted to a few core functions.

That's all that's necessary. You can get fancier, but those are the core functions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.