I create a monitoring application who :
if there is a network connection available : she sends periodically
measurement data to the server using json
if there is no network available, she stores the data in the sd card and sends it when the network connection is back.
Actually I use a circular buffer in memory that I empty when data are sent
Is there already something usefull in the framework or I have to write that completly ?
Thanks
I would check tape library from square. I've never tried it but looks what you are looking for.
Related
I have an Arduino and an Android app which are communicating to each other via ethernet. The arduino shows a very simple webpage with only some values and an ID as seen below.
$1$201 //Value 1 ($1$): Temperature 20.1 degrees
$2$66 //Value 1 ($2$): Humidity 66%
$2$1 //Value 2 ($2$): Heating relay is on (1)
etc. up to 50 values
The Android app will read the data from this webpage as a string using a HTTP get request, filters the data and shows the values on a custom made screen. It is also possible to send some data to the arduino to change some settings or switch a relay or something. You can see is as some kind of thermostat. So far so good.
The "problem" is that I need to manualy update the data using a button. The question is: How can I update my values automatically?
I was thinking to just send a httpRequest every few seconds (polling), but I'm not sure if this is the way to go because it seems to use of lot of data.
Who can advise me what would be a good solution?
Regards,
Bas
The 'best' choice here will depend on your goals. Polling is easy to implement on the client (android) side. You could experiment with the optimal polling time depending on how 'fresh' your data needs to be compared to how much data you want your app to use. Alternatively, you could find or implement an http socket server such as ArduinoWebsocketServer, keeping in mind that the processor in your Arduino may or may not have the power needed to run this.
I implement this library on my project https://github.com/firebase/FirebaseUI-Android.
How to check if result from data it's from local or network?
I need identify if result it's from network to set animate on textView.
There is no way to know whether a value comes from the local cache (either in memory or disk) or from the server. You should instead write your app to treat the values as the best guess at the current value.
If you want to know if your app is currently connected to the Firebase Database server, you can detect the connection state by listening for the .info/connected value.
I have to do a webservice in node.js (server web with express). This service is used from an Android application. My question is how can I count the packet (IP datagram) that Android application send to webservice?
Thank you.
You can try counting the data events in your http server code. Express is probably handling this for you using some body parser middleware, but you can use a custom written one that counts the data events. It's won't be an exact number since node may split headers and body into two events when they were a single packet on the wire. Also you'll only get the view from the server, but you already said that's ok.
Another option for more control is to use the node-pcap bindings at https://github.com/mranney/node_pcap. They allow for low-level wireshark-style monitoring of a network interface. You'll just have to filter and process that data in your JavaScript code. The process doing the actually capturing will likely need to run as root unless you set up your system to not require it.
I am developing an application that read data from biometric devices using Bluetooth when I send request to biometric device for sending data, biometric device show response with updating its display screen but when I call function for read input stream for getting response the function in_stream.available() return 0. I am not able to trace out the root of problem. I have test same biometric device with some other app it work fine.
Help me if any one have idea about this issue.
Thanks in advance.
Do no use available() method. It is broken in most implementations. You should be constantly reading with read() or read(byte []). If the protocol lets you know the size of the expected data (i.e. some first bytes telling how much data is coming afterwards) you can just read that amount of data.
If the amount of data is unknown or you expect asynchronous data comming then you should manage the writing/reading to/from the streams in a separate thread. This does not only applies to Bluetooth but also to any basic stream handling (network, files, etc.)
I have an application that communicates to server. I want my application to READ ONLY the socket's inputstream when NEW DATA is available for fetching.
Currently, I create a timer that scheduled for the reading of socket's inputstream every 20ms(polling) using SocketChannel class of java.nio.channels. This is not that good because it will end up of reading the socket even if there's no available data. And it drains the battery fast.
Is there an API for Android that will tell or send a flag to the connected client whenever a new data is available so that it is the only time I will read the inputstream?
See this, but the short answer is no, there is no API for this. BTW, SocketChannel/Selector won't actually read the socket if not data is available, just check it's status.
For push notifications, you might check the Android Cloud to Device Messaging Framework.
AFIAK, it's implemented in a similar fashion: they keep a socket open, and send notifications
when available. It is most probably already tuned for low battery usage, and is part of the OS, so might be worth a try (2.2 and above).