BMP280 ServiceSpecificException: I/O error (code 5) - java

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

Related

No peers provided by network with hyperledger app on android

With the Commercial paper tutorial, I continue to try to implement the java application to an Android emulator.
On Issue.java, when call Network network = gateway.getNetwork("mychannel"); an error occur : IllegalArgumentException: No peers provided.
Because of network argument by getChaincodeQueryPeersForOrganization(DefaultQueryHandlers.java:50), he don't give me a collection of peers and cause error on SingleQueryHandler.java:29.
I think about connection-org2.yaml file, but don't see what's wrong.
(Default Java app not work correctly)
How can I give the right network, with correct peers ?
Complete error:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: iti.paper.ch.paper_test, PID: 9568
java.lang.IllegalArgumentException: No peers provided
at org.hyperledger.fabric.gateway.impl.query.SingleQueryHandler.<init>(SingleQueryHandler.java:29)
at org.hyperledger.fabric.gateway.DefaultQueryHandlers.lambda$static$0(DefaultQueryHandlers.java:30)
at org.hyperledger.fabric.gateway.-$$Lambda$DefaultQueryHandlers$A9xv6yy6Ls07YnjWxZKkScD7PTQ.create(Unknown Source:0)
at org.hyperledger.fabric.gateway.DefaultQueryHandlers.create(DefaultQueryHandlers.java:73)
at org.hyperledger.fabric.gateway.impl.NetworkImpl.<init>(NetworkImpl.java:54)
at org.hyperledger.fabric.gateway.impl.GatewayImpl.getNetwork(GatewayImpl.java:252)
at iti.paper.ch.paper_test.Issue.main(Issue.java:56)
at iti.paper.ch.paper_test.MainActivity$1.onClick(MainActivity.java:29)
Your SDK uses the connection-org2.yaml to populate the a view of the network to a large degree on the client side. The rest is taken care of by service discovery, should there be any changes subsequently.
Having said that, you should add your channel details in your connection profile (connection-org2.yaml) and specify the roles of the peers. The error that you are seeing is related to the fact that there are no peers defined with chaincode querying roles. You do that by modiying the connection profile and including details similar to this..
channels: //name if the channel
mychannel:
peers:
peer0.org2.example.com:
endorsingPeer: false //this is a role
chaincodeQuery: true //this is a role
discover: true // this is a role
peer1.org2.example.com:
endorsingPeer: false
chaincodeQuery: true
discover: true
Try this and restart your network. Bear in mind that the default scripts will also regenate any connection profles using the template.

stop recv socket bluetooth data

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:

How to know if app user is offline android app?

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.

Bluetooth android server client with a headset

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.

Get an unique id for a connected network device

I am connected to a WLAN, where a special hardware device is connected to as well. I communicate to that device via a socket, since I know its IP.
Is there a was to identify that hardware device in the network by an id? I found out in Java it is not possible to obtain the MAC-address of a connected device. Is there any other alternative?
Thanks,
best regards
Mac addresses should be unique. Maybe you can get needed information from the ARP table.
Command "arp -a" works on Windows and Linux.
But there is a problems:
This is not portable way
The ARP table is quite variable
If the device is behind a router, then this does not work.
In Java you can call NetworkInterface.getHardwareAddress() that will return hardware MAC address
Enumeration<NetworkInterface> enumNicList = NetworkInterface.getNetworkInterfaces();
while(enumNicList.hasMoreElements())
{
NetworkInterface oNic = enumNicList.nextElement();
byte[] baMacAddress = oNic.getHardwareAddress();
String sMacAddress = new BigInteger(1, baMacAddress).toString(16);
System.out.println(sMacAddress);
}
If you don't have any control of the responses of the device, and the device doesn't contain any identifying API calls and such, then just use the IP address and make that IP statically assigned to that device via your router. Then you can either create your own table of IP <-> device list, or even scrape the IP table off your router.
Come to think of it, you could probably get the MAC address the same way - scrape the DHCP table off your router's configuration screen.

Categories

Resources