I was sent iOS C code to get data from a Bluetooth Low Energy scale and I need to find out how to create similar functions into Android Java code.
The scale I am working with aren't using typical UUIDs and formatting.
I already have a scanner set up with the ability to write and listen to notifications.
What I need to do is figure out how to get the weight data.
I know is that 0XFFF0 is the service UUID, 0XFFF1 is the write characteristic and 0XFFF4 is the notify characteristic.
I'm guessing it writes something, then the scale gives you the data. But I'm not sure what.
Plus I think the scale sends the data with NSUTF8StringEncoding if I'm reading it correctly. How would I implement this on Java?
Here is the code sent to me:
http://www.anj.fyi/BTManagerlib.m (I tried to post the code here, but it's registering as spam for some odd reason)
I really appreciate the help guys.
Many thanks.
"The scale I am working with aren't using typical UUIDs and formatting."
Yes, it uses, except it is written in 16-bit format If you want 128-bit UUID use XXXXYYYY-0000-1000-8000-00805F9B34FB base to create it.
From the example that you have posted:
-(void)writeDataToBlue:(NSNotification *)note
{
id obj = [note object];
_senddata = obj;
[self sendBlueToothData:_senddata showAlert:YES];
}
it is clear that data to be written to the device are not bundled into the source code, but they are received via notification center, from some other class. Ask them for device documentation or full source code, otherwise you won't be able to make any conclusions.
Related
I have a found a free API to get some data I need for my app. The thing is the values that I get are in English.
I wanted to know if there is some way to translate this strings in my language before showing them to the users.
You can translate text but it will require another API call. Not only that, but you will have to create an appropriate request object and parse a response object from your chosen API.
You have various API providers to choose from, the top Google hits being:
Google: https://cloud.google.com/translate/
Yandex: https://tech.yandex.com/translate/
But beware! Machine translation is patchy at best. The likelihood of getting odd sounding or outright wrong results, particularly for anything other than simple text, is very high.
I am working with BluetoothLe on Android (min API : 21+). Currently the procedure of filtering service uuid's works, but not quite as expected. Below is a code segment used for setting up the basic scanner parameters, this is what currently works. Based on areas of other work with Ble, (iOS, Embedded Hardware) it becomes apparent that there are abilities to filter Ble devices based on their 16-bit UUID assignments only. Which brings me to Android... I realized android has had a rather rough start to Ble and its rather segmented ecosystem of devices, but I fail to see how/why android cant follow similar paths with the UUID's like other platforms. As all the UUID's coming from the Bluetooth SIG are 16-bit identifiers only with a mere definition of a UUID_BASE (00000000-0000-1000-8000-00805F9B34FB).
...
// devices UUID service
ParcelUuid parcelUuid = new ParcelUuid(UUID.fromString("1F0E0D0C-0B0A-0909-0807-060504030201"));
// devices UUID service mask
ParcelUuid parcelUuidMask = new ParcelUuid(UUID.fromString("00000D0C-0000-0000-0000-000000000000"));
// Filters and Settings
scanFilter = new ScanFilter.Builder().setServiceUuid(parcelUuid, parcelUuidMask).build();
scanFilterList.add(scanFilter);
scanSettings = new ScanSettings.Builder().setScanMode(ScanSettings.SCAN_MODE_LOW_POWER).build();
// Scanning Started
mBluetoothLeScanner.startScan(scanFilterList, scanSettings, scanCallback);
...
With all that stated above, I have two Embedded Hardware devices broadcasting Two of their own UUID Services that are very similar to one another but different non the less. Below are those UUID's, in all accounts only the MSB(Most Signifigant Byte) is the differentiator amongst them all. Also there Device Names are different.
Device One:
Service 1 - 1F0E0D0C-0B0A-0909-0807-060504030201
Service 2 - 2F0E0D0C-0B0A-0909-0807-060504030201
Device Two:
Service 1 - EF0E0D0C-0B0A-0909-0807-060504030201
Service 2 - FF0E0D0C-0B0A-0909-0807-060504030201
Common Identifier amongst the UUID's:
0x0D0C
From the code segment provided earlier, the ParcelUuid that is used in the setServiceUuid method appears to require an exact match for the scanner to even return a device, despite the matching mask needed. How then, do you make the request to the drivers/hardware to filter only by 16-bit Identifiers instead of the full 128-bit Identifiers?? Because the model I have presented above with the two different devices, each with their own Service UUID's different from the other, isn't capable of scanning and returning all the devices wanted or expected.
I feel like the problem I'm having is two-fold but needs to addressed, because I cant seem to find the answer anywhere. I have searched high and low for all forum post, stack questions/answer that touch on this topic but none of them appear to pop out as what I'm looking for. I'm not sure if my understanding of filtering on android is faulty, if android is missing features, or inability to find such features in the supplied classes of android. I have a few thoughts on how to accomplish this "feature" in software but it will be rather ugly, time consuming, and taxing on the battery. One such example is scanning openly and filtering it manually. But I think there is or should be a feature to support 128-bit AND 16-bit UUID filtering when scanning through devices.
Can anyone help shed light on this????
Also, apologies for the length of this posted question...
The mask i should be opposite - use 1's for bits to include and 0's for those that should be ignored.
filter: 1F0E0D0C-0B0A-0909-0807-060504030201
mask: 0000FFFF-0000-0000-0000-000000000000
Result is that any device which has '0D0C' is included. You'd probably want a "tighter" filter with more similarities in it than this.
I'm not sure exactly what you want to filter on, but if you simply want to apply the filter ????0D0C-????-????-????-????????????, you should have the parcelUuid set to 00000D0C-0000-0000-0000-000000000000 and the parcelUuidMask set to 0000FFFF-0000-0000-0000-000000000000.
You should filter the BLE based on MAC addresses , they filter like a charm and perhaps if you have found the solution for the UUID filtering please do share.
first question here!
I am interested in acquiring raw GPS data on android devices: satellite positions, pseudoranges, and phase information. According to this well-answered question, the best we can do is get everything that GpsSatellite provides.
I'm wondering if the situation has changed in the past five years? I noticed that the Android source now a structure named GpsMeasurement, which sounds like it has everything I want in it, and is used similar to the well-known GpsStatus structure.
However, GpsMeasurement is #SystemApi and thus not accessible via normal app writing. Further, I can't find any information on this beyond source code.
Is there not another way to get this data? Is there a workaround to access GpsMeasurement regardless? There's really nothing in there that should be kept from developers.
So looks like this has changed recently. Here is a link describing how to get the raw GPS data off of modern smartphones: Raw GNSS Measurements
I doubt that you ever will have access to that data on an consumer android handy.
The reason is, that the GPS chip has to specially configured to output these pseudo ranges, this produces overhead that normally nobody uses.
Further GPS chips that are able to output pseudeoranges, are often more expensive.
This is called the "raw-data option".
I wanted to learn more about the Android Services / Broadcasts, so I started a simple project, to create a battery monitoring app. It turned out pretty good, I'm using it for a few days now, but I want to add a new function: to show since when is the phone charging/discharging.
First I thought that I would create two static fields in my BoradcastReciever extension class, where I get and publish the data about the battery, one for the actual state (charging/discharging), and one for the time, when the change in state happened. This way, I could just subtract from the current time the last change, and know exactly since when is the phone charging/discharging.
But there is a problem with this solution: It won't show the correct data at first, when a user starts the app. I wouldn't make a big deal of it, but I saw that Android tracks this data somewhere, because inside my phone settings I found this information, so why take the hard way.
So my question is: is there an easy way to get from the Android system the date/time (no matter what format) of the last charging state change?
I looked at the BatteryManager reference but there are no constants named after what I seek, and which I could use, to get the information from the Intent of my receiver.
The Android OS tracks the connect/disconnect of a power source, but does not make this data accessible to apps. You have to record this all yourself, using intent filters.
The two intent filters to use are android.intent.action.ACTION_POWER_CONNECTED and android.intent.action.ACTION_POWER_DISCONNECTED; with these, you can monitor when the power source is connected and disconnected.
You can find information about this process explained incredibly clearly here. Another blog describing the process can be found here.
I want to write a program that will be able to call into my company's bi-weekly conference calls, and record the call, so it can then be made into a podcast.
I am thinking of using Gizmo's SIP interface (and the fact that it allows you to make toll-free calls for free), but I am having trouble finding any example code (preferably in Java) that will be able to make an audio call, and get hold of the audio stream.
I have seen plenty of SIP programming tutorials that deal with establishing a session, and then they seem to just do some hand waving, and say "here is where you can establish the audio connection" without actually doing it.
I am experienced in Java, so I would prefer to use it, but other language suggestions are welcome as well.
I have never written a VOIP application, so I'm not really sure where to start. Can anyone suggest a good library or other resource that would help me get started?
Thanks!
Look for a VOIP softphone writtin in Java, then modify it to save the final audio stream instead of sending it to be played.
Side note: In many states you would be violating the law unless you do one of several things, varying by state: Notify the participants they're being recorded, insert BEEPs every N seconds, both, etc. Probably you only have to comply with the laws of the state you're calling from. Even worse, you may need to allow the users to decline recording (requires you to be there before recording starts). If you control the conference server, you may be able to get it to play a canned announcement that the call is being recorded.
You could do this with Twilio with almost no programming whatsoever. It will cost you 3ยข per minute, so if your company's weekly call is 45 minutes long, you're looking at $1.35 per week, about as close to free as possible. Here are the steps:
Sign up for Twilio and make note of your Account ID and token
Create a publicly accessible file on your web server that does nothing but output the following XML (see the documentation for explanation of the record parameters):
<Response>
<Record timeout="30" finishOnKey="#" />
</ Response>
When it's time to start the recording, perform a POST to this URL (documented here) with your browser or set up an automated process or script to do it for you:
POST http://api.twilio.com/2008-08-01/Accounts/ACCOUNT SID HERE/Calls
HTTP/1.1
Called=CONFERENCE NUMBER HERE
&Url=WEB PAGE HERE
&Method=GET
&SendDigits=PIN CODE HERE
If you want to get really creative, you can actually write code to handle the result of the recording verb and email the link to the MP3 or WAV file that Twilio hosts for you. But, if this is a one off, you can skip it because you can access all your recordings in the control panel for your account anyway.
try peers with mediaDebug option true in peers.xml. This option records all outgoing and incoming media streams in a media/ folder with a date pattern for file name. Nevertheless this file will probably not be usable as is. It contains raw uncompressed lienar PCM samples. You can use Audacity, sox or ffmpeg to convert it to whatever you want.
https://voip.dev.java.net/
They have some sample code there.