I'm trying to use BLE and WiFi on ESP32. As I've seen they can't be used at the same time, so I'm trying to figure out a way to stop receiving data from a BLE server. This are the methods to stop BLE that I have tried so far:
btStop();
esp_bt_controller_disable();
esp_bluedroid_disable();
However, none seem to work. The ESP32 supposedly connects to WiFi (using WiFiManager), but when I try to connect to Firebase or Twilio the connection is refused. Before trying to connect to Firebase I have 35000 free heap and twilio 80000. So, is there a way to check whether the BLE scan/connection has been stopped? Are there any other commands to turn it off? Could it be that I am running out of heap and I can't connect to Firebase because of that?
You're currently missing a couple of deinit calls
esp_bluedroid_disable();
esp_bluedroid_deinit(); //**
esp_bt_controller_disable();
esp_bt_controller_deinit(); //**
You might also have to ensure Wi-Fi hasn't been started while BLE was enabled, you can init, but starting might cause issues where it starts trying to use the radio immediately
If you're using the BLEDevice Library try this:
BLEDevice::deinit(true);
Related
I am attempting to use HM10 as central to read data from a sensor. The HM10 has been flashed with the latest firmware V710 to use the self learn functionality.
Here is the list of messages I am sending and receiving from the HM10
First I configure the HM10 as central and turn on some notifications. Then I connect to the MAC address of the sensor. I use the AT+FINDSERVICES? command to get the list of services, then find all the characteristics in the range of that uuid. The characteristics I am interested in is 0021.
But here is when the problems start. If I try to read that characteristic I get OK+DATA-ER, which the datasheet the characteristic does not have a read property. Same thing with notify.
But from the AT+CHAR command we can see handle 0021 has both read and notify. I have also tired reading from 001E handle and I get the same error. I am able to read data like the device name from another handle so I am able to get some data off the sensor.
I am wondering if the OK+DATA-ER response can mean something else? Or if the characteristic handle isn't correct somehow. If that were the case how would I find the correct handle?
I have tried connecting to the sensor on my iphone using the LightBlue app and I am able to both read and subscribe to the notification. I have also tried cloning the sensor as a virtual device on LightBlue and I am able to read and subscribe from the HM10 to the phone. So the issue seem to be between the HM10 and the sensor specifically and not with either device individually.
LightBlue UUID
LightBlue read data
I figured it out. Turned out to be a security issue. The sensor would allow connection but no data would be accessible unless the connection was encrypted.
The BLE sensor required pairing when it first connect to a phone and does not subsequently so I missed that fact when I was trying to connect to it via the HM-10.
I don't believe the HM-10 supports pairing connection. I tried setting AT+TYPE to other than 0 but it would no longer connect to the sensor. I would get OK+CO11A but it wouldn't finish connecting.
I switched to an ESP32 board and used
BLEDevice::setEncryptionLevel(ESP_BLE_SEC_ENCRYPT);
This allowed me to read and subscribe to the characteristic.
I'm a little bit new to ESP32 and Arduino ID. I've been working on a project in which I want to switch the wifi network from one to another at any given time. But whenever I'm trying to close the existing connection (network) and reconnect to the new one, ESP32 crashes and gets rebooted. A bit peculiar behaviour I would say. Additionally, I even tried to use the EEPROM for the storage purpose, so, even when my ESP32 gets rebooted, it will take the updated values from the storage. Unfortunately, sometimes ESP32 crashes even when I update the variable which was being passed earlier to WiFi.begin(). Lastly, In my application, I'll be providing the new SSID and Password through the serial (COM) port. Can anyone help in achieving this task?
I tried a similar task with persisting values in memory. The ESP32 lacks an eeprom so you need to use some nvs (non volatile storage) functions as they are called for ESP32. See https://github.com/rpolitex/ArduinoNvs for example.
I am developing a UWP project to run on Raspberry Pi 3b that will advertise a Gatt Server. I based my program on the 3rd scenario in the windows IoT samples provided by Microsoft. I am using unpaired communication. Initially using the on-board BLE of the raspberry pi I get BSOD/restarts.
I narrowed the problem and suspected that it happens when:
client is not disconnected properly, i.e. android device is not disconnected properly
i try to notify using IAsyncOperation<IReadOnlyList> NotifyValueAsync(IBuffer value) on all devices even on devices not properly disconnected.
I did find on Microsoft documentation that it only supports low bandwidth devices so I limited my mtu/packet size, and added intervals on notification.
To fix the crash issue, I added a check for session status before sending notification to each individual subscribers. This seem to solve my issue on the crash. it hasn't happened again on my recent test. I am using 10.0.17763.1397 so maybe they also have some fix.
foreach (var client in characteristic.SubscribedClients)
{
try{
if (client.Session.SessionStatus == GattSessionStatus.Active)
{
GattClientNotificationResult result = await characteristic.NotifyValueAsync(data.AsBuffer(), client);
}
}
catch(Exception ex)
{
//if client is not disconnected properly, like
// bluetooth in client is turned off or becomes out of
//range it throws and error that on client.Session.SessionStatus
}
}
I also restart the GATT server every 60 seconds, like stopping the advertising and creating/restarting it again every 60 seconds if no client is subscribed/connected.
Now my problem is if I try to cycle scanning-connecting-reading, after some tries (6-20 tries) my client stops detecting the device. Only rebooting the device could solve the issue as I already tried restarting radio from my app and from powershell (using devcon). It didn't solve the issue.
Since I needed a perfect stable solution. I am opting to use BLE dongle with peripheral mode. I did see suggested BLE dongles from (I couldn't reply because it was already archived).
https://social.msdn.microsoft.com/Forums/SECURITY/en-US/344fc709-7e13-499a-94ee-3c935ad503bb/ble-gatt-server?forum=WindowsIoT
but I was hoping for some proof of concept before I buy them. (I did buy a bunch of CSR BLE dongles from hardware compatibility list of microsoft but none of them work)
If anyone have already tested:
BLE-USB-CR (RoHS)
BT900-US Laird
Please let me know your thoughts and how you made it work. I also saw the Bluefruit LE Friend from Adafruit but I'm not sure if it is compatible with Windows IOT.
Suggestions on my current imperfect solution are also most welcome.
I have been trying to set the limit of pairing the Bluetooth device HC-05(interface by Arduino controller) with my smartphone.
I have tried making this solution work with AT command
AT+INQM=<Param>,<Param2>,<Param3>
Example: AT+INQM=1,9,48\r\n
But instead of converting AT commands using serial.h with embedded C, I am looking for any dedicated library which helps to work this kind solution in using Arduino.
Basically, with the help of Bluetooth device connect to Arduino Nano, I want to send the altimeter sensor data to my smartphone.
During the connection, HC-05 should be responding any one device at a time, if another smartphone tries to pair then the error will be shown.
Please share your advice on this.
Yes there are some libraries in arduino but these are only meant for connection and pairing and low energy connections. We don't have any dedicated library from where we can control the mode of operation of HC05 or any bluetooth module. like bypassing or accessing GAP and GATT services of bluetooth. However there is a way to flash HC-05. But we can only use it for updating the firmware of this device. This github repo is dedicated for this purpose . Hope it helps you
I'm really having trouble connecting to my ESP8266. I was working with this setup for long time now and I didn't have to flash my boards. Now after having to use a different wifi i needed to flash the board. After doing the following
Updating to the newest ConfigurableFirmata
Using FirmataBuilder to download fitting firmata
Uploading the Firmata to the ESP8266
I can't connect via Johnny-Five anymore (getting the usual timeout error). I couldn't narrow down what it exaclty is (and I have been trying all day) but these are things that I have noticed (Using ConfigurableFirmata directly as well as using firmatabuilder and StandardWifiFirmata, all with the same behaviour)
an open Hotspot gets created even though I'm in Client Mode
when scanning for ports I do find the Module connected to my Wifi (Serial Monitor in Debug tells me the same too) but no open port is found, even though it's specified in the firmata.
I just can't narrow down the reason. I hope you guys can.
OK,
this was a simple user mistake. But since I lost a whole day searching for the error and I think others might too, I'll share my mistake here.
As I pointed out I created the Firmata as Client (thinking its a client to my Hotspot). But you will have to create it as a server (as you want to connect to the board)
It's as simple as that. If you are on http://firmatabuilder.com/ make sure you choose TCP Server if you want to connect to your board.