Hey there. I have programmed my ESP32 for networking, sensing, among other functions. Everything is working but connection to WiFi network is HARD-CODED. That's when I found @kolban 's BootWiFi snippet and successfully ported in a new project. It's been really hard for me because I don't know annything about c++ coding, so I started adding C source files to the new project and adding functions to their headers for compatibility with c++. Most functions work as expected and the program is compiled and sent to the device, but ble_gap_api callback functions cause panic halt cpu and the device crashes.
Tried the inverse by putting the bootWifi source file and header in the C program (following forums for porting c++ sources and classes to c) but I don't know how to call these.
BootWiFi* boot;
(in main)
boot = new BootWiFi();
boot->boot();
All help is appreciated.
thanks
Integrate BootWiFi snippet in IDF C project
-
- Posts: 7
- Joined: Wed Feb 21, 2018 8:45 pm
Re: Integrate BootWiFi snippet in IDF C project
From a C program, there is no way to create a C++ class and call it. If you want your "main" app to be pure C, then you would create another C++ source file and expose a function that can be called from C and call it such that it calls C++. For example.
That all said ... C++ should be a super set of C and you should be able to work just fine in C++ as well as C. If we are finding problems with your C-like logic in a C++ environment that works in a C environment, I'd be very interested to hear about that.
Code: Select all
File: mycpp.cpp
extern "C" {
void doit();
};
void doit() {
BootWifi boot = new BootWiFi();
boot->boot();
}
In you C program you can now code:
extern void doit();
....
doit();
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32
-
- Posts: 7
- Joined: Wed Feb 21, 2018 8:45 pm
Re: Integrate BootWiFi snippet in IDF C project
Thanks, Worked right away. This is a step up in my project. In the future, what would you suggest me? go full c++ with your working snippets community? or stay and bring my code to c? (or something super crazy like micropython ).
By the way, this is the tutorial I followed for ble advertising that works successfully in C, but crashes when ported to C++ environment.
http://www.lucadentella.it/en/2018/03/2 ... vertising/
By the way, this is the tutorial I followed for ble advertising that works successfully in C, but crashes when ported to C++ environment.
http://www.lucadentella.it/en/2018/03/2 ... vertising/
Re: Integrate BootWiFi snippet in IDF C project
Howdy,
Its a good question but asking for a recommendation is hard. Whether one works in C or C++ is a function of whether one knows C++ and whether you are a hobbyist or professional in the software business. C++ is supposed to be a superset of C and I find that 98% true and then you get the additional functions (classes etc) that make C++ distinct from C. The benefits of C++ also start appearing when one writes larger and larger applications. One can then "encapsulate" function in a Class and then "forget" how the class works and just use it.
As for why your application crashed when written in C++ but works in C ... that is indeed a puzzle ... but one that could likely be solved. Your description of what failed asked more questions than answers (opinion). You might want to try and recreate that puzzle and document it in super-great detail to allow the community to assist in the diagnosis.
Its a good question but asking for a recommendation is hard. Whether one works in C or C++ is a function of whether one knows C++ and whether you are a hobbyist or professional in the software business. C++ is supposed to be a superset of C and I find that 98% true and then you get the additional functions (classes etc) that make C++ distinct from C. The benefits of C++ also start appearing when one writes larger and larger applications. One can then "encapsulate" function in a Class and then "forget" how the class works and just use it.
As for why your application crashed when written in C++ but works in C ... that is indeed a puzzle ... but one that could likely be solved. Your description of what failed asked more questions than answers (opinion). You might want to try and recreate that puzzle and document it in super-great detail to allow the community to assist in the diagnosis.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32
Who is online
Users browsing this forum: Majestic-12 [Bot], Marcosss and 108 guests