I am fairly new to BLE, recently I have done an experiment where I have made an iOS app which is central, it scan for a particular peripheral and connect to it and finally it writes something to the characteristics to do an action. Link: Swift-BLE . Now I have got a new project where the central would be the iOS app and the peripheral would be a raspberry pi 3 B+ running on Linux. It should have an on off switch for activating BLE link. Once On is should start scanning for ble peripheral devices. When getting a connection request from the Linux peripheral it should display the passcode and connect to it. Next it should sent it a long JSON string and read back a JSON string from the gatt profile.
I don't know how a peripheral request for a connection with the central, and how the central handle it. Any suggestion would be really helpful.
Again, my question is not how to discover, connect peripheral, my question is how can a peripheral send request to central for a connection & how the central process it. Is it possible ?
Related
How to connect BLE multiple devices at the same time in Swift
I'm working on iOS application project using BLE to transfer some data between them. The concept is one device is the main device that broadcast the data to other devices, then device that get data from bluetooth send data back to the main device.
How to connect multiple devices at the same time using core bluetooth? (1-to-many topology)
Is that possible to send and receive data in the same time?
There are two different roles: peripheral and central.
A peripheral typically has data that is needed by other devices. A central typically uses the information served up by a peripheral to accomplish some task.
The central can discover and connect to multiple peripherals.
See Core Bluetooth Programming Guide for details. Even it is archived, it has the good overview of the feature.
I've been tasked with figuring out how to get a mobile app to communicate with an MCU then in turn control a stepper motor. Right now I'm trying to get the WiFi module (ESP8266-01) and MCU (NUCLEO-F030R8) to play nice with each other. The catch is I have little to no experience and no education in this field. The closest experience I have is simple Arduino sketches from years ago (IE photo-resistor values driving a stepper motor) and making desktop applications with C#. I am using STM32CubeIDE but if there's a better option I can switch to that.
What I would very much like help on is send and receive simple data between a smartphone and the MCU via the WiFi module. I've read through documentation and other questions but still don't exactly know where to start.
I understand this is probably a large topic in its own right and a short blurb on the internet won't do it (and undoubtedly its multiple subcategories) justice. But I might as well ask.
Sorry if this is too much and thank you in advance.
This project would involve making the following connections.
The UART connection between STM32 and ESP8266.
The WiFi connection between ESP8266 and the mobile.
The application layer protocol between ESP8266 and the application running on the mobile.
For 1, you can actually program the ESP8266 using Arduino IDE and simply connect the UART TX/RX pins of ESP8266 with RX/TX pins of STM32 respectively. You can create a test project in which ESP8266 sends data to STM32 over UART to verify this connection.
For 2, you need to consider the wifi network mode i.e identify whether the wifi connection is going to be ad-hoc (mobile connects to ESP8266 directly) or in infrastructure mode (mobile and ESP8266 connected via a shared access point). You can configure the ESP8266 in both modes. You just have to program the SSID and password of the Wifi network in the ESP8266 (in case of ad-hoc, it is the SSID of the network advertised by ESP8266 and in the infrastructure mode, it is the SSID of the common AP). This wifi functionality is also easily programmable in Arduino IDE for ESP8266.
Finally, once the physical connection has been established between the ESP8266 and mobile device, you need an application-level protocol to connect the application running on the mobile with the ESP8266. You can either use socket connection between ESP8266 and mobile application or use a higher-level communication protocol for IoT devices like MQTT, which is also available in the Arduino IDE.
Final connection diagram could be something like this:
application -> mqtt msgs -> wifi packets -> esp8266 recv pkts -> parse mqtt msgs -> forward data to STM32 over UART
The system i'm working with uses the following scenario:
Connecting to bluetooth LE device
Discover Services & Characteristics
Write command to TX characteristic and receive response
Above works fine 90% of time. Now and then the system gets into a state where 3rd step constantly fails (there is no response from device whatsoever even though step 1 and 2 succeeded. Restarting the app / phone / BLE device DOES not remedy this. Block is constant. What does resolve the problem is manually unpairing the device from iOS system settings. Looking at BLE diagnostic logs i get this:
"pon. mar 7 21:27:30 Preferences[380]: [CoreBluetooth] API MISUSE: can only accept commands while in the connected state"
However prior to sending the commands i've debugged the app and i'm 100% the connection is established and services&characteristics have been discovered. Any Idea? Anybody facing similiar problems?
Did you implement centralManager:didDisconnectPeripheral:error: in your central manager delegate?
It will notify you when a peripheral disconnects. Could be that the peripheral disconnected or there was a connection error. You should always make sure to only do read/write operations while in the connected state.
Maybe also have a look at this method: centralManager:didFailToConnectPeripheral:error:
I have a BLE dongle named Bluegiga (BLED112).
Bluegiga USB dongle
By using the BLEGUI I can see my bluetooth GATT profile Service UUID and characteristic UUID.
While press the connect button it shows connected but, I am sending data from iPhone It is not received in BLEUI. The central (Bluegiga) is running in a windows PC.
If anyone used the Bluegiga dongle, please help me to correct the same for a data transfer from iPhone to the target.
I want to build some kind of two-way bluetooth connection on Raspberry-pi which actually works as beacon. Based on RadiusNetworks tutorial (How to Make an iBeacon Out of a Raspberry Pi http://developer.radiusnetworks.com/2013/10/09/how-to-make-an-ibeacon-out-of-a-raspberry-pi.html) I've built beacon on my Raspberry-pi, but it's working in "advertise and not-connectable" mode (which is connected with problem described here: Raspberry Pi iBeacon connection timing out).
What I want to achieve is beacon device, which works in advertise mode and also allows to receive some events from other device (i.e. iPhone). When iPhone discovers Raspberry-pi beacon I want it to send some data to Raspberry-pi to trigger some action. I know that in the simplest way my iPhone should send data via network to raspberry while it enters to the beacon region, but unfortunatelly my solution has to work in offline mode, so I'm looking for some kind of direct (and possibly fast) connection. I think that PayPal beacon is a good example of my needs (as it is decribed here: https://devblog.paypal.com/how-does-paypal-beacon-work/ their device works as gate for communication user smartphone with PayPal services).
I'm complete beginner in BLE topics, so I would be grateful for any hints where I can start exploration or how to properly ask Google for any good answers in this topic.
For complex interaction, you need to learn how to build a connectable Bluetooth service with BlueZ, which is the Linux open source Bluetooth stack. Once you have this service, you can write iOS code using CoreBluetooth to connect to this service when the beacon is nearby.
Unfortunately, I do not know of a good tutorial for building services on BlueZ. The BlueZ code is open source at least, so the code is a good place to start looking:
http://www.bluez.org/development/