I would like to get data from my sdr USB plug on my RPI3 directly on my smartphone. With the function samples=sdr.read_samples(256*1024), I can easily get samples in my loop (while (1)). Now my job is to change the center frequency by bluetooth with an android application. The problem is actually: I can't receive new data from my key, I have no problem to change value with the structure : try...
But impossible to get new value with my function samples=sdr.read_samples(256*1024) because the function data=client_sock.recv(1024) block my loop if she don't have data. But this is not what I want. I want to get data from my sdr.read_samples and if she detect new data from my phone then she is running.
from pylab import*
from rtlsdr import*
from bluetooth import*
import sys
#configure device
sdr= RtlSdr()
sdr.sample_rate=double(sys.argv[3])
sdr.gain=double(sys.argv[2])
sdr.center_freq=double(sys.argv[1])
NFFT=33
#Bluetooth connection
server_sock=BluetoothSocket(RFCOMM)
server_sock.bind(("",PORT_ANY))
server_sock.listen(1)
port=server_sock.getsockname()[1]
uuid="94f39d29-7d6d-437d-973b-fba39e49d4ee"
client_sock,client_info=server_sock.accept()
while(1):
samples=sdr.read_samples(256*1024)
result=psd(samples,NFFT, Fs=sdr.sample_rate/1e6, Fc=sdr.center_freq*1e6/1e6)
tab_freq=(result[1]/1e6)
value_freq=str(tab_freq)[1:-1]
value_list=[format(float(v), ".10f") for v in value_freq.split()]
value_freq2= "\n".join(value_list)
tab_pxx=result[0]
value_pxx=str(tab_pxx)[1:-1]
client_sock.send(value_freq2+'\n'+'\n'.join(value_pxx.split()))
try:
data=client_sock.recv(1024)
if len(data)==0: break
data2=float(data)
a=data2
except IOError:
pass
How can I solve this ?
Thanks for your help.
I solved this with : except Bluetooth:
Related
I try to use AndroidThings to measure temperature with Raspberry Pi 3 and BMP280.
3,3V i have choosed because of specification of BMP280:
To power the board, give it the same power as the logic level of your microcontroller
Then i want to initialize sensor
mTemperatureSensorDriver = new Bmx280SensorDriver("I2C1");
And by execution i receive following exeption
Error configuring sensor
com.google.android.things.pio.PioException: android.os.ServiceSpecificException: I/O error (code 5)
at com.google.android.things.pio.I2cDeviceImpl.readRegByte(I2cDeviceImpl.java:81)
at com.google.android.things.contrib.driver.bmx280.Bmx280.connect(Bmx280.java:215)
at com.google.android.things.contrib.driver.bmx280.Bmx280.<init>(Bmx280.java:193)
at com.google.android.things.contrib.driver.bmx280.Bmx280.<init>(Bmx280.java:180)
at com.google.android.things.contrib.driver.bmx280.Bmx280SensorDriver.<init>(Bmx280SensorDriver.java:55)
Also by 5V Power i receive the same exception.
I have found this. But i have no idea how to check, if the BMP280 is realy connected to Raspberry with adb.
By own testing the connectivity i receive by device.readRegByte(0xD0) the same exeption.
Does it mean, that BMP280 is not correctly connected?
If yes, how to correctly connect BMP280 with Raspberry?
Is some resistor needed by connection?
UPDATE
solved by soldering BMP280 with header strip.
Also to work with sensor is permission requiered that could be granded only in command line. ref
adb shell pm grant app.package com.google.android.things.permission.MANAGE_SENSOR_DRIVERS
Looking at your fritzing diagram you had SDO connected to BCM3?
From the datasheet the SDO pin is what determins the address of your sensor.
Connecting SDO to GND results in slave
address 1110110 (0x76); connection it to VDDIO results in slave address 1110111 (0x77)
Most importantly:
The SDO pin cannot be left floating; if left floating, the
I²C address will be undefined.
com.google.android.things.pio.PioException: android.os.ServiceSpecificException: I/O error (code 5)
Therefore your problem is likely an undefined i2c address.
Looking at the code you are using for the Bmx280SensorDriver, it uses the address 0x77
https://github.com/androidthings/contrib-drivers/blob/master/bmx280/src/main/java/com/google/android/things/contrib/driver/bmx280/Bmx280.java#L48
Therefore you should ensure your SDO line is connected to 5V on your raspberry pi. This will ensure your sensor has the correct address.
Or alternatively connect SDO to Ground and use this constructor:
mTemperatureSensorDriver = new Bmx280SensorDriver("I2C1", 0x76);
If you want to understand what the sensor driver is doing "under the hood" there is a great blog post and repo to see that:
http://blog.blundellapps.co.uk/tut-android-things-temperature-sensor-i2c-on-the-rainbow-hat/
https://github.com/blundell/androidthings-i2c-input/blob/master/app/src/main/java/com/blundell/tut/MainActivity.java
;-)
Thanks for informations, for right connection
bmx280 = new Bmx280("I2C1",0x76); and SDO to gnd.
But read values is strange.
myweatherstation D/statie: temp: 186.83298 pres: -296.47287
Is possible to be sensor damaged?
TNX
Cris
To read data from IoT Device, the contact should be fixed without any loose connection.
This could be only reached with soldering of BMP280 with header strip
Only then the connection could be etablished
Currently i am developing a cab booking app.
Now i am working on driver app.
Now my task is, i want to make him offline and online when ever internet get disconnected orconnected .
In my database i have a column is_online which value goes to 1 when he online and 0 when he is offline.
well now i know how to make him online but how to make him offline? if internet got disconnected ! how can i update value in db . it remain 1
never goes to 0;
Current i am using Broadcast Receiver that notify me when internet get disconnected or connected.
<?PHP
require_once 'include/DB_Settings_Functions.php';
$db = new DB_Functions();
// json response array
$response = array("error" => FALSE);
if(isset($_POST['driver_id'])&&isset($_POST['status']))
{
$driver_id= $_POST['driver_id'];
$status= $_POST['status'];
$user = $db->makeOnline($driver_id,$status);
}
?>
I heard that it can be solved by using mqtt any working example ? can anyone help me? i am using local host wamp server.
Edit:
In simple words i want to send value in server before connection goes down any idea how it can be done using mqtt ?
You can fire a request on every minutes from mobile app and stored it's date and time into data base. if user is online that means last access time will update every minutes in database and if user is offline then it's time last access time will not update in data base so you just need to fire a sql query for get offline user that have last access time is grater then 2 minus.
MQTT has a function called the Last Will and Testament (LWT), this is a messages that is published by the broker when the client connection times out.
This means that the client can publish a retained message to a unique topic when it comes online (e.g. publish 1 to /status). It can then set up a LWT to publish 0 to the same topic if the connection drops. It should also manually publish 0 before manually closing the connection as LWT only fires if the connection drop unexpectantly.
You can adjust the time out value to suit your needs.
I am working on app running on two tablets, which have two type of logins. Customer and Shopkeeper, it will run on two tabs at same time. I am getting tabs device id and saving it. because it can't be run on any other tablet without registered tablets.The issue is that after login when I go on main screen, when i enter number from any tablets, the next screen must be changed on both tablets. I am not getting the idea how to operate two tabs from any one of them.Can you help me to get this idea. any help will be appreciated.
I have 2 separate options here :
A. Use CouchDB.
Couch DB has this functionality to sync data between client and server.
Steps :
Tablet1 enter a value
Value saved in tablet1 CouchDB. (You can use something like couchbase-android)
Data synced from client COUCHDB to Server CouchDB ( you can use Cloudant here )
Data synced from Server CouchDB to client CouchDB in the Tablet1
Tablet2 use a listener to listen to record change in the database
Tablet2 change its state based on the record change.
B. Use Notification Server
Tablet1 enter a value
Tablet1 send message to Notification Server, indicating the changes
Notification Server send notification to Tablet2
Tablet2 use Notification Listener to listen to all notification
Tablet2 change it state based on data contained in the notification message.
I'm trying to create a server on android that will listen on incoming connections ,such as a specific headset i have.
I've read many tutorials, posts in StackOverflow and the one from Android|Developer , and i don't seem to understand a few things .
1) UUID , is it a specific address for each Bluetooth device ? or is it a shared key that need to be in the server and the client in order to create a connection ? my guess is the latter cause there the MAC address as well ...
2) When i pair my Headset with my phone , does the headset saves the MAC\UUID of the last paired device ?
3) Does the Bluetooth chips even works in that way ? The phone connects immediately to a paired device as it turned on, So my guess is that it opens a Socket for each paired device and waits for it to turn on , is that true ?
4) Is it possible to accomplish what im trying ? Meaning creating a BluetoothServerSocket that will accept a connection from the head set ?
code example for the server side:
//This may b needs to be the UUID of the headset ? or special one ? or what ?
UUID myUUID = UUID.fromString("0000111e-0000-1000-8000-00805f9b34fb");
private final BluetoothServerSocket mServerSocket;
private BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
tmp = mBluetoothAdapter.listenUsingRfcommWithServiceRecord(Activity.APP_NAME, myUUID);
mServerScooket = tmp;
//Im hoping that this will block until the specific headset will be turned on
socket = mServerSocket.accept();
Thanks in advance.
1) UUID ,is a specific ID for Bluetooth communication. When you create your bluetooth socket in Android, listenUsingRfcommWithServiceRecord(Activity.APP_NAME, myUUID); ask Android to redirect bluetooth connection which match with the UUID to your app.
2) I'm not sure. It depends on the type of connection the headset can make. When you want to use it, do you need to select it in Android, or you can just put it and it works ?
3) I don't know. But you can have a look to Android source code ;)
4) If the bluetooth headset can create a connect socket, yes, it is possible
Hope this helps ;)
1) yes UUID is specific to each device and in order to connect to a device you need to have its UUID.
as shown in the Bluetooth chat example by Android SDK
2) depends on the hardware for example
chip sets like the HC-06 does saves the last paired device UUID
while the HC-05 dose not ...
3) The headsets that Ive tested (Samsung made) Acts as a server.
so by initiating a BluetoothSocket with the UUID of the headphone u can connect to it.
4) Yes it is possible to connect to a Bluetooth head set answered in the post : Using the Android RecognizerIntent with a bluetooth headset
Special notes :
Best way to listen to oncoming connections without any wakelocks that I found is by registering the BluetoothDevice.ACTION_ACL_CONNECTED Broadcast and check the name\mac\UUID of each incomming connection.
Thanks to Hoan Nagayu for the help.
I have the following problem with the libusb-java and some self-made devices.
It could happen that such a device disconnects from the USB Port because it drains to much power (as an example: i have a USB-LED Light which needs sometimes more than 500mA).
In this case the USB Controller will reset the device and the device will startup normaly again.
Now i cant really detect such a problem except for trying to reinit the device on every Exception. But thats not working...
On Every Exception i call my init Method again, which looks like this:
private void initDevice() {
USB.init();
this.dev = USB.getDevice(idVendor, idProduct);
}
The Problem with that is, this runs without any problem, but the i get this error message when i want to send new data:
LibusbJava.controlMsg: error sending control message: Protocol error
How do i can reinit the device? Do i have to reset the bus or something?
You will need to call open() on the device - it is new for the system.