i have 30 gps devices that send latitude longitude via MQTT to my server.
then i process data with python which listen mqtt and insert to mysql database
what i need to do is: on my android and ios app i want to display those cordinates
on map (1 marker for each gps device)
so i dont know what is best way to do that.
so what i think is:
API: create a script.php that query database and show a json format on it.
android and ios app can call it every second but will that make lot of load or idk if that is best practice.
i think similar to AJAX but im afraid this is not good idea to call every second
$.ajax({url: "script.php", success: function(result){
//do something with results
}});
maybe to connect app directly to listen a mqtt or tcp ip:port and publish json there.
some suggestion i see in internet are HTTP long-polling or something that app will stay connected and check if something change.
Websockets would be a good way to implement this right? you send a stream of data from one end and the other side receives it in real time.
Related
I am developing android application which allow users to share localization data between them, and showing it on the map.
I've done it, and its working but I am looking for better performance, or just better pattern for app like this.
For now, my app uses https connection between android client and REST servlet on tomcat.
For instance, if user is logged he is sending his gps data every 10 sec to server, and gets other users positions. Everything by HTTP POST.
First thing I want to ask you:
Does anyone knows better solution to sync data with server than android service with timed task every 10 sec? I have background service that is running all the time and every 10 sec runs AsyncTask which asking server about users localizations.
And what do you think about connection method with server?
Maybe it will be better to create connection by sockets?
Thanks in advance for all responses.
You're right. There is no necessity of establishing http connection each 10 seconds. It's absolutely inefficient for clients and your server in terms of CPU usage and data transferring.
There're two solutions which I suppose more appropriate for you task:
Yes, sockets. Socket connection could be fairly easy implemented on Аndroid. Two threads which share socket connection: first one reads data, second one writes data. To receive data when phone is sleep you could use GCM service.
P2P connection. It's quite reasonable because as I understood you don't need to modify or track transferring data by your server. Clients just will communicate with each other.
I'm about to create a GPS-tracking application for pizza-delivery services in my city, so that when someone orders pizza over the phone or Internet, he can see the courier that carries pizza to him on the map.
Assuming that both courier and client use Android- or iOS-based phone for transmitting/receiving current position, how can I organize a reliable connection between them? Should the courier's phone send his coordinates to my server via HTTP every 5 seconds for delivering it to client, or it will be better to set up something like p2p connection?
I don't know where to start, please help. Thank you very much.
There are open source solutions for GPS tracking. You can start from there instead of developing everything from scratch.
Traccar server (back-end for receiving location data from various devices):
https://github.com/tananaev/traccar
There are also apps for Android and iOS, but only for transmitting location data:
https://github.com/tananaev/traccar-client-android
https://github.com/tananaev/traccar-client-ios
I don't think p2p will be a good solution.
Most of the application use web services and make server calls after a definite interval of time like 10 seconds or 15 seconds refresh to get updated data on both side of apps(Client and courier).
If you want to build a real time application like other real time apps then you need to implement sockets on web and on mobile apps.
But I think in your case web services would be good enough solution.
I'm creating app that has to show live position of some vehicles. Their position is obtained by GPS via Rasberry PI, is sent to my server and there it is converted to Json file. Then on android device I am creating app which converts this file and lets user see vehicle position.
I am downloading it via HTTP protocol, and I think it is good way of solving problem. But my boss is insisting that it could be done by streaming (because, as he says, it is not neceserry to download data from server when vehicle is not moving for about 30 minutes), SO.
What is the way of creating a situation in which android device is not downloading data but waiting for server to send data? Is it even possible?
As far as I know, streaming is constantly sending data to target device, and device is constantly receiving this data.
The only way I can think about is to create server on every android device, send server data to my server (IP, port etc.) and from my server connect to every device and send position only when vehicle is moving - but this is costfull and not proper way I think.
Any ideas or help?
The best way to handle your problem is implementing a GCM and dealing with PUSH NOTIFICATIONS.
If connection is not available at the moment, will be sent when connection will be ok.
If the receiver isn't available at the moment, same things will happen.
It consumes less resources than constantly http calls.
See more information at https://developer.android.com/google/gcm/index.html
Does anyone know how to implement communication between 2 android devices over the internet without using App Engine? For example, I have 2 Android devices, and I want to send a stream of data from one to the second one over the internet. I would like to know, if someone could give me an idea, how could I identify the second device (or how to create a communication channel between two devices ), so I could initiate the transfer (this is not possible using IP addresses ?).If i were to have my own server, which is the best way to go to accomplish this? If someone could point me to some useful resources I would be grateful.I have some background on android programming.
One way I was thinking to accomplish this was to write an android application, and when the user enters it, it will start a service. This service will then listen for network events and registers on my own server with the username and the IP address of the device as available.When another device wants to send data, it will connect to the server, search for the target device (by username key), gets the IP address and sends the data. Could this work, or does anybody have other suggestions?
One way I thought about doing this is making
(excuse the spelling mistakes if any)
It would help if we knew what kind of data you were trying to transfer.
For small bits of information, like notifications, events, and the like, I would suggest doing an HTTP POST to a server that has C2DM capabilities, and using the server as an intermediary.
For larger data, the only way I can think of to do it is to set up a SyncAdapter, then upload the information to the server. The delay will be a bit longer, but you'll reliably get the information downloaded from the server to the phone. So less of a communication API and more of a dropbox for phones.
I haven't done much with NFC, but that may be something you want to look into.
I am using an Android phone in my application to read GPS information. The GPS information is sent over Telnet and I want to read it in my application. I will then databind the position of something like a blob to the GPS data and display a user on a map in real time.
How can I read the NMEA GPS response using WCF and consume it into my application with databinding to the position of the blob? What is the way to go about this? Mine is a desktop application and I am using WPF.
I don't think WCF will solve this issue for you. I would look at something like IP*Works which will help you with the telnet connectivity.