Connect Samsung Bluetooth Smart Remote (2016) to RaspberryPi Bluetooth (Zero W) - bluetooth-lowenergy

I am trying to connect my Samsung Bluetooth Smart Remote (2016) (no mouse function) to a RaspberryPi Zero W which then should send actions through IR or IP when a button on the remote is pressed.
Sofar I've managed to connect the bluetooth remote to the raspberry pi zero with gatttool:
sudo gatttool -I -b XX:XX:XX:XX:XX:XX
where XX:XX:XX:XX:XX:XX stands for the mac of the remote. Typing connect in the interactive mode then connects to the remote, when the remote is in pairing mode (press back and play for 3s).
The connection sofar seems to be established successfully, the mac adress font is now colored blue and also bluetoothctl shows that it is connected to 'Smart Remote 2016' in blue letters.
But from now on, I don't get anything further. The next step I'd expect to establish a connection to the HID service of the remote and getting new devices listed in /dev/input and therefore be able to receive commands when buttons are pressed on the remote. If I right now press a button, nothing happens on my raspberry.
In the gatttool (type primary) I discovered, that the device has 10 services, listed as follows:
attr handle: 0x0001, end grp handle: 0x0007 uuid: 00001800-0000-1000-8000-00805f9b34fb, Generic Access
attr handle: 0x0010, end grp handle: 0x0013 uuid: 00001801-0000-1000-8000-00805f9b34fb, Generic Attribute
attr handle: 0x0030, end grp handle: 0x0040 uuid: 0000180a-0000-1000-8000-00805f9b34fb, Device Information
attr handle: 0x0050, end grp handle: 0x0052 uuid: 00001803-0000-1000-8000-00805f9b34fb, Link Loss
attr handle: 0x0053, end grp handle: 0x0055 uuid: 00001802-0000-1000-8000-00805f9b34fb, Immediate Alert
attr handle: 0x0056, end grp handle: 0x0058 uuid: 00001804-0000-1000-8000-00805f9b34fb, Tx Power
attr handle: 0x0060, end grp handle: 0x0063 uuid: 0000180f-0000-1000-8000-00805f9b34fb, Battery Service
attr handle: 0x0070, end grp handle: 0x00a7 uuid: 00001812-0000-1000-8000-00805f9b34fb, Human Interface Device
attr handle: 0x5000, end grp handle: 0x5005 uuid: 0d916f56-8570-4d50-a34f-20574da51001, Unknown Service
attr handle: 0xff00, end grp handle: 0xff05 uuid: 9e5d1e47-5c13-43a0-8635-82ad38a1386f, Unknown Service
Did anyone ever try this before or does know how to enable the Human Interface Device?
I'd really appreciate any help in this topic! Thanks.

Related

AttributeError: 'NoneType' object has no attribute 'scan'

`I am trying to scan for devices advertising the UART service using Micropython on esp32. but I get AttributeError: 'NoneType' object has no attribute 'scan'
below is my code:
# Initialize and enable the BLE radio.
ble = ubluetooth.BLE()
ble.active(True)
# Create a BLE scanner object.
scanner = ble.gap_scan(10, 30000, 30000)
# Scan for devices advertising the UART service.
print('Scanning for devices advertising the UART service...')
devices = scanner.scan(10)
# Connect to the first device with the matching UART service UUID.
for device in devices:
for advertised_service in device.services:
if advertised_service.uuid == UART_SERVICE_UUID:
# Connect to the device.
print(f'Connecting to device {device.name}...')
connection = ble.connect(device)
# Wait for the connection to be established.
while not connection.is_connected:
pass
print('Connection established!')
# Stop scanning.
scanner.stop()
break
if connection.is_connected:
break
`
Your code reads:
# Create a BLE scanner object.
scanner = ble.gap_scan(10, 30000, 30000)
# Scan for devices advertising the UART service.
print('Scanning for devices advertising the UART service...')
devices = scanner.scan(10)
You're using the gap_scan() method incorrectly. According to the documentation, when the scanner detects a device it calls the callback function. You're getting an error because gap_scan() doesn't return anything, which is consistent with the documentation.
You need to register an event handler in order to see the results of a scan. So:
def ble_callback_handler(event, data):
if event == _IRQ_SCAN_RESULT:
# A single scan result. Do whatever you need with this
addr_type, addr, adv_type, rssi, adv_data = data
elif event == _IRQ_SCAN_DONE:
# Scan duration finished or manually stopped.
# register a callback handler
ble.irq(ble_callback_handler)
# start scanning
ble.gap_scan(10, 30000, 30000)

How to enable notification and indications on Arduino nano 33 IOT BLE descriptor?

I am making BLE echo system between Arduino and Android.
I have finished to make read and write function. But I want Android can automatically detect value when BluetoothGattCharacteristic value change. So I made set notification on Android.
When I tried to check the fucntion is working properly or not, It was not working properly. And I use nRFConnect App to check what is the problem. the problem is the status of descriptor on Arduino is Notification and indications disabled. And I googled how to enable notification and indication on Arduino. But on the Arduino's document, I cannot find the function which can make enable descriptor's notification and indication. this is the document link. So is it possible to enable notification and indication on Arduino BLE??
Code of Arduino nano 33 IOT.
#include <ArduinoBLE.h>
BLEService echoService("00000000-0000-1000-8000-00805f9b34fb");
BLEStringCharacteristic charac ("741c12b9-e13c-4992-8a5e-fce46dec0bff", BLERead | BLEWrite | BLENotify,40);
BLEDescriptor Descriptor("beca6057-955c-4f8a-e1e3-56a1633f04b1","Descriptor");
String var = "";
void setup(){
Serial.begin(9600);
while(!Serial);
if(!BLE.begin()){
Serial.println("starting BLE failed.");
while(1);
}
BLE.setLocalName("Arduino BLE Echo");
BLE.setAdvertisedService(echoService);
charac.addDescriptor(Descriptor);
echoService.addCharacteristic(charac);
BLE.addService(echoService);
BLE.advertise();
Serial.println("Bluetooth device active, waiting for connections...");
Serial.println(" ");
}
void loop(){
BLEDevice central = BLE.central();
if(central){
Serial.println("* Connected to central device!");
Serial.print("Connected to central : ");
Serial.println(central.address());
Serial.println(" ");
while(central.connected()){
if(charac.written()){
var = charac.value();
Serial.println(String(var));
delay(500);
charac.writeValue(var);
Serial.println("write stringCharacteristic");
}
}
Serial.print("Disconnected from central: ");
Serial.println(central.address());
}
}
picture of nRFConnection APP.
You need to enable the notifications from the Android side in order to receive the BLE notifications. This is because according to the BLE specification, BLE notifications are disabled by default. If you want BLE notifications to remain enabled after the first time you enable them, you can bond with the Arduino device. This way, the status of the notification will persist across power cycles and disconnection/reconnection, and as soon as you reconnect to the Arduino device, notifications will be enabled by default (but again, you still have to enable them the first time).
This can be seen in the paragraph below (Bluetooth Specification v5.3, Vol 3, Part G, Section 3.3.3.3 - Clinet Characteristic Configuration - Page 1489):-
"The Client Characteristic Configuration declaration is an optional
characteristic descriptor that defines how the characteristic may be
configured by a specific client. The Client Characteristic
Configuration descriptor value shall be persistent across connections
for bonded devices. The Client Characteristic Configuration descriptor
value shall be set to the default value at each connection with
non-bonded devices.The characteristic descriptor value is a bit
field. When a bit is set, that action shall be enabled, otherwise it
will not be used. The Client Characteristic Configuration descriptor
may occur in any position within the characteristic definition after
the Characteristic Value. Only one Client Characteristic Configuration
declaration shall exist in a characteristic definition.
The default value for the Client Characteristic Configuration descriptor value shall be 0x0000."
Note that the Client Characteristic Descriptor (CCCD) is the attribute in the characteristic that handles notification/indications. You can read more about this here:-
Bluetooth Low Energy: A Primer
Bluetooth GATT
Bluetooth Low Energy Characteristics Tutorial

LE Set Data Length returns Unsupported Feature or Parameter Value

I setup a gatt-server on samsung platform (using bluez 5.47), upon client connect I want to configure the data length (this sets the link layer packet length)
which will return Unsupported Feature or Parameter Value.
the same command works when I setup a client that connects to a remote gatt-server.
* according to bluetooth core spec 4.2 I should be able to do that
"Both the master and slave can initiate this procedure at any time after entering the Connection State".
* I tried to enter some default values of tx octet 27, tx time 328, this does not work. (probably means this isn't parameter value issue).
anyone know why is that not working?
* just to be noted, I would like this to be set in order to increase throughput. currently set MTU and connection params only.
< HCI Command: LE Set Data Length (0x08|0x0022) plen 6 #31973 [hci0] 5281.478803
Handle: 1894
TX octets: 251
TX time: 2120
HCI Event: Command Complete (0x0e) plen 6 #31974 [hci0] 5281.479176
LE Set Data Length (0x08|0x0022) ncmd 1
Status: Unsupported Feature or Parameter Value (0x11)
Handle: 1894
turnes out I connected to Ipone 6s which does not support bluetooth 4.2 (it supports bluetooth 4.1). That was the reason for "Unsupported Feature"
Meaning both master and slave must support bluetooth 4.2 (since data length extension is feature of bluetooth 4.2)

Intel Edison WiFi connection refused via browser

I'm using Arduino IDE with Intel Edison and upload sketch from IDE examples: Examples -> WiFI (Edison) -> SimpleWebServerWiFi. Just updated with password and network name. I can add code from sketch here but here is nothing special. And it seems that connection works fine:
Attempting to connect to Network named: L&N
SSID: L&N
IP Address: 192.168.1.102
signal strength (RSSI):-39 dBm
To see this page in action, open a browser to http://192.168.1.102
But when I try to open http://192.168.1.102/ in browser, result always is the same (no matter which is wifi network or which device):
This site can’t be reached
192.168.1.102 refused to connect.
Any ideas how to solve this?
The avoid this issue use any other port instead of 80. Update line in code in the sketch WiFiServer server(80); with WiFiServer server(81);.
After running the sketch, url address also could be updated with the port number for web browser. For example if your IP address is 123.234.23.12 - add the :81 at the end: http://123.234.23.12:81.

Arduino WiFi shield rarely connects to network, any tips?

// attempt to connect to Wifi network:
while (status != WL_CONNECTED){
listNetworks();
Serial.print("Attempting to connect to SSID: ");
Serial.println(ssid);
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
status = WiFi.begin(ssid, pass);
Serial.print("Status: ");
Serial.println(status);
// wait 3 seconds for connection:
delay(3000);
}
The above code repeatedly attempts to connect to a WPA2 network. The serial output this produces looks like this:
** Scan Networks **
number of available networks:2
0) SKY0C026 Signal: -48 dBm Encryption: WPA2
1) WAP-HOME Signal: -84 dBm Encryption: WPA
Status:4
This repeats over and over again as the connection fails (status 4). What I don't understand is that once in a while it is able to connect, sometimes on the second try. I've tried extending the delay time between connections but no luck. Is there anything I'm missing?
So I believe as an anti brute force attack mechanism routers don't like it when devices repeatedly try to connect in too short a time span, sometimes even 10 seconds is too short! I guess the MAC address gets blacklisted and that's why the connection fails. The solution was to reset my router and up delay between reconnects.

Resources