[Video]: Bluetooth BLE and C++ classes
-
- Posts: 2
- Joined: Tue Jul 11, 2017 5:14 am
Re: [Video]: Bleutooth BLE and C++ classes
Hi Sir! Do you have an example of esp32 receiving and sending data to android phone via BLE? even just a 1 and 0 data sir.
Re: [Video]: Bleutooth BLE and C++ classes
Howdy,
You betcha ... and both to you and others ... if you can meet me half way (bring your own skills which start at C or C++ programming and the ability to build hello world ESP-IDF applications), I'll work with you to get your BLE going using these C++ classes.
Unfortunately, I haven't done any BLE programming on native Android ... however, there are excellent pre-build applications that run on Android that are BLE testing apps. What I mean by that is that they can be either BLE clients or servers and then demonstrate that they can interact with YOUR application running on the ESP32 (remember, communication programming is a game of two halves). So while developing an ESP32 <-> Android BLE APP, my go-to tool is "nRF Connect for Mobile" ... see:
https://play.google.com/store/apps/deta ... .mcp&hl=en
Install that on your Android device and then write your ESP32 app and you can test that Android can send and receive. Once you have demonstrated that your ESP32 app can work with this tool, then you can put aside your ESP32 app and learn Android to program to its side of the house.
See also the video in the first post of this thread to see it in action. If what you are after is coding assistance on BLE on Android then I suspect the ESP32 forums aren't what you need and you'll want to see out assistance in Android programming forums.
You betcha ... and both to you and others ... if you can meet me half way (bring your own skills which start at C or C++ programming and the ability to build hello world ESP-IDF applications), I'll work with you to get your BLE going using these C++ classes.
Unfortunately, I haven't done any BLE programming on native Android ... however, there are excellent pre-build applications that run on Android that are BLE testing apps. What I mean by that is that they can be either BLE clients or servers and then demonstrate that they can interact with YOUR application running on the ESP32 (remember, communication programming is a game of two halves). So while developing an ESP32 <-> Android BLE APP, my go-to tool is "nRF Connect for Mobile" ... see:
https://play.google.com/store/apps/deta ... .mcp&hl=en
Install that on your Android device and then write your ESP32 app and you can test that Android can send and receive. Once you have demonstrated that your ESP32 app can work with this tool, then you can put aside your ESP32 app and learn Android to program to its side of the house.
See also the video in the first post of this thread to see it in action. If what you are after is coding assistance on BLE on Android then I suspect the ESP32 forums aren't what you need and you'll want to see out assistance in Android programming forums.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32
-
- Posts: 2
- Joined: Tue Jul 11, 2017 5:14 am
Re: [Video]: Bleutooth BLE and C++ classes
I have tried it yesterday Sir and I used the gatt_server example and it worked. I was able to send data to esp32 using the android and a ble app. But the gatt_server code seems a really blurry for me because it does not have comments in its functions. I am a newbie at this I am very sorry for my inconvenience.
Re: [Video]: Bleutooth BLE and C++ classes
Howdy,
If you are talking about the BLE samples that can be found here:
https://github.com/espressif/esp-idf/tr ... /bluetooth
Then this is probably the wrong thread. This thread talks about C++ classes that encapsulate BLE functions which is a whole different story. You might want to create a new thread for your puzzle and the community can take a look at that specifically.
If you are talking about the BLE samples that can be found here:
https://github.com/espressif/esp-idf/tr ... /bluetooth
Then this is probably the wrong thread. This thread talks about C++ classes that encapsulate BLE functions which is a whole different story. You might want to create a new thread for your puzzle and the community can take a look at that specifically.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32
-
- Posts: 20
- Joined: Wed Jun 28, 2017 1:22 pm
Re: [Video]: Bluetooth BLE and C++ classes
I was able to connect to and control the esp32 through the nRF Toolbox, but for some reason it only worked on Android v >5. When I tried it on my co-worker's Samsung Galaxy S5 ( v4.4 ) it spammed a "Error on discovering services ( 129 )" message on the app itself and the ESP32 never got to the confirmation stage it's been getting to with the other phones. Any idea what went wrong?
Re: [Video]: Bluetooth BLE and C++ classes
A couple of initial thoughts ... I wondered what version of Android BLE support started ... apparently the answer is Android 4.3 API 18.
See: https://developer.android.com/guide/top ... th-le.html
So that doesn't appear to be the issue.
The next thing is to validate that we are talking about the same testing apps. The ones I use are:
nRF Connect for Mobile - https://play.google.com/store/apps/deta ... .mcp&hl=en
which claims support for 4.3 and above (good).
I also recommend:
nRF Logger - https://play.google.com/store/apps/deta ... .log&hl=en
which allows us to log the low-level BLE messages and see what actually happened.
Next I suggest Vysor for your Chrome browser or Windows desktop. This allows you to connect to your phone through a browser or desktop application and use your PC as the "Interface" to your phone. Not only is this a productivity tool, it lets you capture screen shots of your phone to share errors.
So ... with these in mind, capture a recipe you followed on the phone and the corresponding ESP32 app that ran on the ESP32 and then we can both attempt to recreate and, using the nRF Logger, examine a working trace vs a failing trace.
See: https://developer.android.com/guide/top ... th-le.html
So that doesn't appear to be the issue.
The next thing is to validate that we are talking about the same testing apps. The ones I use are:
nRF Connect for Mobile - https://play.google.com/store/apps/deta ... .mcp&hl=en
which claims support for 4.3 and above (good).
I also recommend:
nRF Logger - https://play.google.com/store/apps/deta ... .log&hl=en
which allows us to log the low-level BLE messages and see what actually happened.
Next I suggest Vysor for your Chrome browser or Windows desktop. This allows you to connect to your phone through a browser or desktop application and use your PC as the "Interface" to your phone. Not only is this a productivity tool, it lets you capture screen shots of your phone to share errors.
So ... with these in mind, capture a recipe you followed on the phone and the corresponding ESP32 app that ran on the ESP32 and then we can both attempt to recreate and, using the nRF Logger, examine a working trace vs a failing trace.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32
-
- Posts: 20
- Joined: Wed Jun 28, 2017 1:22 pm
Re: [Video]: Bluetooth BLE and C++ classes
Righto, so here's what I did:
1) Downloaded this BLE UART example: https://github.com/pcbreflux/espressif/ ... 2_ble_UART
2) Open up the mingw32 terminal, setup IDF_PATH
3) Navigate to BLE UART folder, set up config ( made sure bluetooth was enabled too )
4) make erase_flash flash monitor
5) Wait for it to finish the process
6) Monitor now prints out that everything initialized properly
Sreenshot of monitor output:
http://imgur.com/NliNNmT
On the android phone:
1) Open up nRF Connect
2) Wait for scanner to find the ESP32 device
3) Press connect on the scanner
4) The CLIENT tab is blank, the SERVER tab has Generic Attribute and Generic Access
Screenshot of Logger:
http://imgur.com/J0clfLL
The monitor does not say that the connection was established. I had done this through nRF ToolKit and it says there was request:
But usually there is more text after if it works
1) Downloaded this BLE UART example: https://github.com/pcbreflux/espressif/ ... 2_ble_UART
2) Open up the mingw32 terminal, setup IDF_PATH
3) Navigate to BLE UART folder, set up config ( made sure bluetooth was enabled too )
4) make erase_flash flash monitor
5) Wait for it to finish the process
6) Monitor now prints out that everything initialized properly
Sreenshot of monitor output:
http://imgur.com/NliNNmT
On the android phone:
1) Open up nRF Connect
2) Wait for scanner to find the ESP32 device
3) Press connect on the scanner
4) The CLIENT tab is blank, the SERVER tab has Generic Attribute and Generic Access
Screenshot of Logger:
http://imgur.com/J0clfLL
The monitor does not say that the connection was established. I had done this through nRF ToolKit and it says there was request:
Code: Select all
I (9426) GATTS: SERVICE_START_EVT, conn_id 0, remote e4:12:1d:a3:f2:2f:, is_conn 1
Re: [Video]: Bluetooth BLE and C++ classes
Ahhh ... with you now. This appears not to be a question related to the C++ BLE classes that this thread is about but rather generic BLE using the underlying ESP-IDF BLE lower level APIs. I'm afraid I don't have much of anything to offer in that regard. You are most likely going to get the support with a specific thread on that more general topic.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32
-
- Posts: 20
- Joined: Wed Jun 28, 2017 1:22 pm
Re: [Video]: Bluetooth BLE and C++ classes
Ah, sorry.kolban wrote:Ahhh ... with you now. This appears not to be a question related to the C++ BLE classes that this thread is about but rather generic BLE using the underlying ESP-IDF BLE lower level APIs. I'm afraid I don't have much of anything to offer in that regard. You are most likely going to get the support with a specific thread on that more general topic.
I'll try your higher level API then and see if I have the same issue.
If I would want to use this with the mingw32 terminal, how would I install this? Or is eclipse required? I was very interested in your JSON Parser so that would be the next thing if we got the BLE to work with my android
When I try to compile with the instructions you had on the github, I get this error:
Code: Select all
Z:/projects/test/build/esp32\libesp32.a(cpu_start.o):(.literal.main_task+0xc): undefined reference to `app_main'
Z:/projects/test/build/esp32\libesp32.a(cpu_start.o): In function `main_task':
Z:/Libraries/esp-idf/components/esp32/cpu_start.c:338: undefined reference to `app_main'
collect2.exe: error: ld returned 1 exit status
https://github.com/nkolban/esp32-snippe ... LE%20Tests
Re: [Video]: Bluetooth BLE and C++ classes
Good stuff ... I was writing that up the other day ... here's the story and solution.
When writing an ESP-IDF application, the rules of the game say that you (the programmer) are responsible for providing a function called app_main() with the signature:
void app_main()
This function (that you provide) is the entry point into your application logic and is called as the last thing that the ESP32 loader does to give your code control.
In a C program, you simply code:
void app_main() {
// my code runs here
}
simple enough. However, C++ programming adds a slight wrinkle. The idea is that you might have multiple C functions all with the same name but belonging to different classes. So if I create:
ClassA:foo()
and
ClassB:foo()
we need to be able to distinguish a call to foo() to the correct class.
This is solved through a concept called C++ "name manging" where a function name is prefixed with the class name in which it is defined. If a function is NOT defined in a class, that is still a concept because then we are "implicitly" saying this is a C++ global.
What this means is that if you declare:
void app_main()
the linker does NOT see "app_main()" but instead sees something like "C++_GLOBAL_app_main()" which is not the same as "app_main()" being sought.
The solution is simple. In your C++ code, and before your definition of app_main(), code the following:
extern "C" {
void app_main();
};
and then code:
void app_main() {
// your code ...
}
This informs the compiler that "Yes, I am coding an application in C++ and I am exposing a global function that is in fact written in C++ but I know what I'm doing and give it C linkage so it shows up as app_main()"
When writing an ESP-IDF application, the rules of the game say that you (the programmer) are responsible for providing a function called app_main() with the signature:
void app_main()
This function (that you provide) is the entry point into your application logic and is called as the last thing that the ESP32 loader does to give your code control.
In a C program, you simply code:
void app_main() {
// my code runs here
}
simple enough. However, C++ programming adds a slight wrinkle. The idea is that you might have multiple C functions all with the same name but belonging to different classes. So if I create:
ClassA:foo()
and
ClassB:foo()
we need to be able to distinguish a call to foo() to the correct class.
This is solved through a concept called C++ "name manging" where a function name is prefixed with the class name in which it is defined. If a function is NOT defined in a class, that is still a concept because then we are "implicitly" saying this is a C++ global.
What this means is that if you declare:
void app_main()
the linker does NOT see "app_main()" but instead sees something like "C++_GLOBAL_app_main()" which is not the same as "app_main()" being sought.
The solution is simple. In your C++ code, and before your definition of app_main(), code the following:
extern "C" {
void app_main();
};
and then code:
void app_main() {
// your code ...
}
This informs the compiler that "Yes, I am coding an application in C++ and I am exposing a global function that is in fact written in C++ but I know what I'm doing and give it C linkage so it shows up as app_main()"
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32
Who is online
Users browsing this forum: Baidu [Spider], Gaston1980 and 89 guests