Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add 2 exemples for communication between to esp32 #16

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

techno94
Copy link

Hello,
i've add 2 exemples for client and server to send and receive data to each other.
tested and working well

@wuzipu123
Copy link

Hello @techno94 thank you for sharing your example. I am using it for a project and it is working pretty fine.
There is only one problem, when the Client loses connection to the Server the Client-ESP32 just reboots because it tries to read from the Server. Following error message appears:

[E][BLERemoteCharacteristic.cpp:438] readValue(): Disconnected
abort() was called at PC 0x401867fb on core 1
Backtrace: 0x400910a0:0x3ffd60f0 0x400912a3:0x3ffd6110 0x401867fb:0x3ffd6130 0x40186842:0x3ffd6150 0x401742db:0x3ffd6170 0x400d7609:0x3ffd6190 0x400d41f6:0x3ffd61d0 0x4018f3fc:0x3ffd6230
Rebooting...

So I was wondering if it is possible that the Client can check if it is still connected to the server before it tries to read a value from it?

@chegewara
Copy link
Collaborator

@wuzipu123 You can do it in your code.

@wuzipu123
Copy link

@chegewara Thank you could you please tell me how?

@techno94
Copy link
Author

techno94 commented Jan 3, 2019

may be change the : if (deviceConnected) {

by : if (doConnect == true) {
line 107 and 120

or put the code of the : readValue
in the : if (connectToServer(*pServerAddress)) {

when you find solution show me the soluion you find actualy i don't have the time to try.

@wuzipu123
Copy link

I made it work by adding following lines to the void loop()

    if(deviceConnected && !pClient->isConnected())
    {
        deviceConnected=false;    
        Serial.println("We disconnected from our device!");
    } 

therefore BLEDevice* pClient needs to be initialized outside the bool ConnectToServer(....) function

It's not perfect because reconnecting doesn't always work but it's something

@wuzipu123
Copy link

Alright so the reconnecting problem is solved by adding

pClient->disconnect();

after realizing that you are not connected to the server anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants