Giter Club home page Giter Club logo

Comments (9)

Aurical avatar Aurical commented on August 20, 2024

Can you provide more specifics?
from what I can see, I am guessing that it is occuring in the WifiLoop function, it might be caused by not ending the previous mode before switching between Central and Peripheral

from ambd_arduino.

BelikovVictor avatar BelikovVictor commented on August 20, 2024

I call BLE.end() before switching.
I attach the whole sketch.
log of this code:

#calibration_ok:[2:19:11]` 

interface 0 is initialized

interface 1 is initialized

Initializing WIFI ...

WIFI initialized

[BLE Device] Local BT addr: 70:1d:08:0c:06:0c

[BLE Device] GAP scan start

WiFi disconnected_
[BLE Device] GAP scan stop

Begin per...
```
[RL8722DMBridgeTest.zip](https://github.com/ambiot/ambd_arduino/files/5695752/RL8722DMBridgeTest.zip)

from ambd_arduino.

Aurical avatar Aurical commented on August 20, 2024

fix.zip

you are right, there was something blocking the peripheral mode.
attached are some new files that should fix the issue, make a copy of the old files, and replace with the fixed files in the libraries folder.

a few points I noticed regarding the rest of the code:

  1. advertising data will be lost after calling BLE.end(), so you will need to reconfigure advertising data after switching to peripheral mode
  2. after connecting the board to wifi, the smartphone app used for WiFi config will remain connected until the user accepts the settings or quit the app, so it is not possible for the board to switch back to central mode immediately after connecting to wifi. Another criteria should be used to determine when to stop peripheral mode and switch to central mode, perhaps check if the board is still connected to a device before calling BLE.end and switching modes.

from ambd_arduino.

BelikovVictor avatar BelikovVictor commented on August 20, 2024

Thank you for cooperation. I also want to note that the BLE.end() needs internal blocking and synchronization. Now we have to add delays when switching from scan mode to peripheral:
BLE.configScan()->stopScan();
delay(5000);
BLE.end();

from ambd_arduino.

Aurical avatar Aurical commented on August 20, 2024

can you clarify on the internal blocking and synchronization?
do you mean BLE.end() should stop scans when called?

from ambd_arduino.

BelikovVictor avatar BelikovVictor commented on August 20, 2024

I meant that BLE.end () should wait for the completion of the stop scan operation, or stopScan () should do it. Anyway, without delay (5000) this code does not work, this is not the correct behavior

from ambd_arduino.

Aurical avatar Aurical commented on August 20, 2024

I have done some testing and could not replicate the behavior. From what I can see, the code still works without the delay(5000).

Here is the code snippet:

  if (WiFi.status() != WL_CONNECTED)
  {
    Serial.println("WiFi disconnected");
    connecting_flag = 1;
    Serial.println("Stop scan");
    BLE.configScan()->stopScan();
    BLE.end();
    Serial.println("BLE end");
    Serial.println("Begin peripheral");
    BLE.beginPeripheral();
    Serial.println("Start adv");
    BLE.configAdvert()->startAdv();
  }

and here is the log output:

15:45:47.136 -> [BLE Device] GAP scan start
15:45:47.136 -> Scan Data 1
15:45:47.136 -> Scan Data 2
15:45:47.136 -> Scan Data 3
15:45:47.182 -> Scan Data 4
15:45:47.228 -> WiFi disconnected
15:45:47.228 -> Stop scan
15:45:47.228 -> BLE end
15:45:47.228 -> Begin peripheral
15:45:47.228 -> Adv update
15:45:47.228 -> GAP cb reg
15:45:47.228 -> Task create
15:45:47.228 -> Coex init
15:45:47.228 -> BT stack start
15:45:47.228 -> gapMsgHandlerDefault: subtype 1
15:45:47.228 -> devStateEvtHandlerPeriphDefault: init state 1, adv state 0, cause 0x0
15:45:47.228 -> Coex on
15:45:47.321 -> Start adv

from ambd_arduino.

BelikovVictor avatar BelikovVictor commented on August 20, 2024

Indeed, apparently I ran the code before the fix.
Yes, everything works without delay.

from ambd_arduino.

Aurical avatar Aurical commented on August 20, 2024

That is good to hear, thanks for the your feedback

from ambd_arduino.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.