BlueCove cannot connect do Device "Permission Denied [13]" - java

I am trying to connect to a bluetooth device, which i can pair to when setting the target device in pair mode, but trying to reconnect with the following method causes errors.
The Code that causes it:
StreamConnection streamConnection = null;
try {
streamConnection = (StreamConnection)Connector.open("btspp://A0E6F8FECB26:1;authenticate=false;encrypt=false;master=false");
callback.onSocketCreated(streamConnection);
callback.onConnectionSucceed();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
The Exception That occurs
java.io.IOException: Failed to connect. [13] Permission denied
at com.intel.bluetooth.BluetoothStackBlueZ.connectionRfOpenClientConnectionImpl(Native Method)
at com.intel.bluetooth.BluetoothStackBlueZ.connectionRfOpenClientConnection(BluetoothStackBlueZ.java:574)
at com.intel.bluetooth.BluetoothRFCommClientConnection.<init>(BluetoothRFCommClientConnection.java:37)
at com.intel.bluetooth.MicroeditionConnector.openImpl(MicroeditionConnector.java:379)
at com.intel.bluetooth.MicroeditionConnector.open(MicroeditionConnector.java:162)
at javax.microedition.io.Connector.open(Connector.java:83)
at insight.utils.ConnectionEstablisher.run(ConnectionEstablisher.java:170)
I have to use Java and this is the only Library I found (That somewhat works) for this purpose:
BlueCove version 2.1.1-SNAPSHOT on bluez
I am on Arch Linux with the newest bluez Version and I have already tried This Fix to no avail.
Any help is appreciated

So essentially, the issue was the entire Bluetooth Stack / how it propagates "pairing requests" to the Bluetooth Stack.
As a sidenote I was using BlueZ (5.56) on Arch Linux and the bluecove library for Java.
I was looking into alternative Bluetooth Stacks and thought about trying the same code on Windows 10, which doesnt use the BlueZ Stack.
Windows then popped up a window where it asked if i wanted to pair to this device.
This was the main difference between Windows and Linux.
Windows / its bluetooth stack or whatever is responsible for it, actually registered the device as "paired".
This then allowed me to re-connect to the device without any "Permission Denied" issues.
Hope this helps anyone that has to deal with this library or has similar issues.

Related

android things MQTT broker [duplicate]

Does anyone know of an MQTT broker that runs on an Android smartphone? I tried to Google and found nothing, and on the app store there seems to be only one app with just 10 downloads, so I'm not sure how well it works.
Add these dependencies to the gradle
dependencies{
compile 'io.moquette:moquette-netty-parser:0.8.1'
compile 'io.moquette:moquette-broker:0.8.1'
compile 'io.moquette:moquette-parser-commons:0.8.1'
}
And use
io.moquette.server.Server server = new io.moquette.server.Server();
server.startServer();
to start broker server. the default URI is tcp://localhost:1883
For me server.startServer(); gave me exception as it is unable to create a file BrokerConstants.DEFAULT_MOQUETTE_STORE_MAP_DB_FILENAME.
So, I changed the destination of the BrokerConstants.DEFAULT_MOQUETTE_STORE_MAP_DB_FILENAME
using this code below code and it worked for me.
try {
MemoryConfig memoryConfig = new MemoryConfig(new Properties());
memoryConfig.setProperty(BrokerConstants.PERSISTENT_STORE_PROPERTY_NAME, Environment.getExternalStorageDirectory().getAbsolutePath()+ File.separator + BrokerConstants.DEFAULT_MOQUETTE_STORE_MAP_DB_FILENAME);
server.startServer(memoryConfig);
// server.startServer();//is not working due to DEFAULT_MOQUETTE_STORE_MAP_DB_FILENAME;
Log.d(TAG,"Server Started");
}
catch (IOException e) { e.printStackTrace(); }
catch (Exception e){ e.printStackTrace(); }
And Use Paho libraries for android
compile 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.1.0'
compile 'org.eclipse.paho:org.eclipse.paho.android.service:1.1.1'
To create a client and connect to tcp://localhost:1883 and subscribe for a topic and start publishing and receiving messages.
moquette library for android.
I have developed an App specifically for this , please download here -
It has inbuilt broker and client too..all for free , connect your
devices to android phone via hotspot or wifi.
https://play.google.com/store/apps/details?id=server.com.mqtt
You can run the mosquitto mqtt broker within the Termux terminal.
Install Termux using e.g. F-Droid
Open/run the Termux Terminal emulator
Install mosquitto
pkg install mosquitto
Start mosquitto within the terminal
mosquitto
That's it. The server will listen on the default port 1883.
Configuration see at mosquitto.
Here is an MQTT broker library I have adapted to Android: https://github.com/interaktionsbyran/moquette
You'll have to make your own Android app though, it is just a library.

Error Win XP setting serial port state

I have the following code fragment to show a HELLO WORLD by a USB Device (Display Posiflex PD-2800 for POS).
I use the GiovynetDrive library to manage a virtual COM port.
The code runs perfectly (assuming the COM3 is available).
SerialPort = new SerialPort();
Parameters settings = new Parameters();
settings.setPort("COM3");
settings.setBaudRate(Baud._19200);
Port = new Com(settings); //<<--Seting crash when restart
Port.sendString("HELLO WORLD");
Port.close();
My problem is that when I turn off the computer, it doesn't turn off the device (USB power). This cause that the next startup, the code throws the Exception:
java.lang.Exception: Error setting serial port COM3 state.
at giovynet.nativelink.SerialPort.openPortC(Native Method)
at giovynet.serial.Com.<init>(Com.java:48)
.........
This forces me to unplug and plug the USB device and then it works well again.
I think this behavior of the S.O. is configurable, but I don't know as.
UPDATE:
When the USB device is in the restart pending state, I can make a print test without problems using a text only printer (generic driver of the S.O.). Then I can see the print test by my viewer but from my java code still not working until I unplug it.
The S.O. is Windows XP and the USB root HUB (of the device management) have unabled the option "Allow the computer turn off the device to save energy".

Error overflow reading serial number of USB device

I'm trying to read the serial number of a device using javax usb library,
and I'm getting this error :
[javax.usb.UsbPlatformException: USB error 8: Unable to get string descriptor languages: Overflow]
The line is simply :
device.getUsbStringDescriptor(descript.iManufacturer());
Someone already had this error ?
Thanks,
I had this error because I hadn't the right driver on a CDC device.
With the Zadig application http://zadig.akeo.ie/
I could install the WINUSB driver on my device.
And this worked fine on a Microchip Demo Board.
Yet the exception remained on my own prototype board. The VUSB connection was not correct.This works fine correctly now in the power-off mode (i.e. the power is not provided by the USB)

Receiving native messages from Chrome in Java

I am trying to get native messaging between a chrome extension and a Java program to work.
After some struggling I now can open my Java program with:
var port = chrome.extension.connectNative('fbehost');
port.postMessage({ text: "Hello, my_application" });
But I don't know how I can read the message send from my extension. I created a program which opens a simple JFrame with a textarea. As it says in the documentation that native messaging communicates with stdin and stdout, I tried to get the message with:
while(true) {
try {
input=br.readLine();
tf.setAreaText(input);
} catch(Exception e) {
}
}
Also tried it with:
System.in.read()
The jar gets executed but the textarea stays empty. I can't find any information on the internet how to get the data in Java. Can you help me?
I haven't been able to get any native messaging to work in Google Chrome recently. I remember reading somewhere that a semi-recent update appeared to prevent compatibility between Java and Chrome for native messaging. Best of luck.

FTP site works but I'm unable to connect from Java program. I get java.net.UnknownHostException

Greetings folks.
I have this weird problem. In the project I'm working on now, I need to upload a file to a FTP site. I have written many programs that do this before and they have worked just fine. But this particular site is giving me trouble. When I try to upload the file from the program, I get this to be specific:
java.net.UnknownHostException: ftp://site.com
However when I try to connect to the same site from within a browser (Chrome, IE) or from windows explorer, I'm able to find the site and login just fine. I tired posting a picture, but I was prevented from doing so as I'm a newbie.
So I'm stumped now. If I could not connect from windows, then I can assume it is a FTP server issue. This happens to me only from the Java program. And I also know that my code works as I have used in numerous occasions before. Here is the code I use:
public void uploadFile(String fileName) throws Exception {
FileTransferClient ftpClient = null;
try {
ftpClient = new FileTransferClient();
ftpClient.setRemoteHost(gv.ftpHost);
ftpClient.setRemotePort(21);
ftpClient.setUserName(gv.ftpUserName);
ftpClient.setPassword(gv.ftpPassword);
ftpClient.getAdvancedFTPSettings().setConnectMode(FTPConnectMode.PASV);
ftpClient.connect();
ftpClient.uploadFile(gv.irp + fileName, fileName, WriteMode.OVERWRITE);
}
catch (Exception e) {
throw new Exception("Error occured in uploadFile()\n" + e);
}
finally {
if (ftpClient != null) {
if (ftpClient.isConnected()) {
ftpClient.disconnect();
}
ftpClient = null;
}
}
}
I use the edtFTPj library. My environment is Eclipse Helios (32 bit) on Java 1.6 (32 bit) running from a Windows 7 64 bit machine.
Any insight on resolving this will be greatly appreciated. Thanks for your time.
The message
java.net.UnknownHostException: ftp://site.com
suggests quite strongly that you're trying to open a connection to a host named "ftp://site.com", which is unfortunately a url rather than a host name and is thus not found.
Try changing your code so that it connects to "site.com".
The UnknownHostException means that the Java networking library is unable to convert the host name supplied into an IP address, via doing a DNS lookup.
Do you have some kind of proxy server configured for your browsers? All I can think of is that you must have some alternative networking configuration set up, if some applications (browsers) can resolve the hostname and others (Java) cannot.
See How do I configure proxy settings for Java? if you do need to set up a proxy for your Java process.

Categories

Resources