https://toitlang.org/ logo
Join Discord
Powered by
# general
  • b

    bmentink

    12/04/2025, 9:21 PM
    Can ESPnow co-exist with "normal" WiFi
  • f

    floitsch

    12/04/2025, 9:22 PM
    Not implemented yet.
  • b

    bmentink

    12/04/2025, 9:24 PM
    Ok, any idea what timeframe?
  • f

    floitsch

    12/04/2025, 9:31 PM
    It's currently not very high on the TODO list. There are some limitations when using WiFi and espnow at the same time, which makes it less usable than it sounds. Basically, the wifi "fixes" the frequency, and espnow is then not able to send on the one it would want to.
  • b

    bmentink

    12/04/2025, 9:31 PM
    So WiFi cannot use one channel and ESPNow another?
  • f

    floitsch

    12/04/2025, 9:32 PM
    no. the esp32 doesn't support that.
  • f

    floitsch

    12/04/2025, 9:32 PM
    (unless they changed something in newer SDK releases)
  • b

    bmentink

    12/04/2025, 9:32 PM
    ok, so some sort of inter-leaving would have to happen ..
  • f

    floitsch

    12/04/2025, 9:33 PM
    If you need different frequencies. Yes. and then you don't need to support both at the same time... (which explains the lowish priority)
  • b

    bmentink

    12/04/2025, 9:34 PM
    ok, thanks
  • b

    bmentink

    12/04/2025, 9:36 PM
    Having them both exist (WiFi and ESPNow) means that I could create a new product 🙂
  • f

    floitsch

    12/04/2025, 9:36 PM
    I will try to increase the priority of it.
  • f

    floitsch

    12/04/2025, 9:37 PM
    With a bit of luck it won't be too hard.
  • f

    floitsch

    12/08/2025, 10:36 AM
    slightly late weekly update: - UART needed some bug-fixing backports but is now ready. There are no known issues anymore. The first PRs have been sent out for review. - also implemented a fix for the RMT peripheral (and uploaded a PR to Espressif to improve their documentation).
  • m

    MichaelK

    12/08/2025, 11:40 AM
    Below are Dart code snippets that retrieve the battery from a BLE device. The flutter_reactive_ble package is used. A subscription to receive data on demand is created: ble.subscribeToCharacteristic(...), and then requests for a specific parameter are sent: _ble.writeCharacteristicWithoutResponse. In this case, the data being sent and received is a vector of bytes: a Uint8List of size 16. How would this snippet look in Toit if using the ble library? How can I implement a similar approach in Toit? How do I create a listener to receive notifications?
    Copy code
    final Uuid serviceUuid =   Uuid.parse('6e40fff0-b5a3-f393-e0a9-e50e24dcca9e');
    final Uuid writeCharUuid = Uuid.parse('6e400002-b5a3-f393-e0a9-e50e24dcca9e');
    final Uuid readCharUuid =  Uuid.parse('6e400003-b5a3-f393-e0a9-e50e24dcca9e');
    
    final FlutterReactiveBle _ble = FlutterReactiveBle();
    
      void _initializeNotifications() {
        final QualifiedCharacteristic readChar = QualifiedCharacteristic(
          serviceId: serviceUuid,
          characteristicId: readCharUuid,
          deviceId: _deviceId!,
        );
    
        _notifySub = _ble
            .subscribeToCharacteristic(readChar)
            .listen(
              (data) {
                final Uint8List bytes = Uint8List.fromList(data);
                _handleIncomingData(bytes);
              },
              onError: (Object error) {
                print('Notification error: $error');
              },
            );
      requestBatteryLevel();
      }
    
      Future<void> requestBatteryLevel() async {
        sendRequest('Battery Level', [cmdBattery]);
      }
  • f

    floitsch

    12/08/2025, 11:49 AM
    Use this tutorial as a starting point: https://docs.toit.io/tutorials/ble/client When you are connected, get the characteristics you are interested in. (the UUIDs of
    writeCharUuid
    and
    readCharUuid
    ). You can then
    write-characteristic.write data
    (where
    data
    is your 16-byte? message). For reading:
    Copy code
    task::
      read-characteristic.subscribe
      while true:
        incoming-data := read-characteristic.wait-for-notification
        // Use the data.
  • m

    MichaelK

    12/08/2025, 12:57 PM
    You're right. I'm receiving data. But I've one question: how do I properly close Task::?
  • f

    floitsch

    12/08/2025, 12:58 PM
    When you are done just
    read-characteristic.unsubscribe
    and then
    break
    to get out of the loop. Or, if you only need one notification, don't even write the loop.
    Copy code
    read-characteristic.subscribe
    incoming-data := read-characteristic.wait-for-notification
    read-characteristic.unsubscribe
    If it's an RPC and you only do one RPC call, you can probably even avoid the task:
    Copy code
    read-characteristic.subscribe
    write-characteristic.write #[some-message]
    incoming := read-characteristic.wait-for-notification
    read-characteristic.unsubscribe
  • k

    kasperl

    12/08/2025, 12:58 PM
    When do you want to close it?
  • m

    MichaelK

    12/08/2025, 1:02 PM
    For example, upon completion of the application, before closing the remote-device.
  • f

    floitsch

    12/08/2025, 1:06 PM
    Keep track of the task, and then use a
    finally
    to unsubscribe:
    Copy code
    reader-task := task::
      ch.subscribe
      try:
        while true:
          incoming := ch.wait-for-notification
      finally:
        ch.unsubscribe
    ...
    // Cleanup.
    reader-task.cancel
  • k

    kasperl

    12/08/2025, 1:07 PM
    Maybe run the separate things in a
    Task.group
    ? You can set it up so that if one task completes, the other is stopped.
  • m

    MichaelK

    12/08/2025, 1:08 PM
    I get the idea, but what if I send a command and receive a series of receivings? For example, if it's a measurement command?
  • f

    floitsch

    12/08/2025, 1:09 PM
    Whenever you are "ready" you just unsubscribe. That's application specific.
  • m

    MichaelK

    12/08/2025, 1:10 PM
    Anyway, thanks for the ideas. I'll try to use them.
  • o

    ow-peter

    12/09/2025, 2:45 PM
    Good afternoon all - just before I start cracking away at it myself; Toit's BLE driver is currently hardcoded to use calls from BLE4.2? There isn't any 5.0 functionality that I can see at the moment, and from what I understand the ble lib is based off c calls for 4.2
  • f

    floitsch

    12/09/2025, 2:50 PM
    Good question. I haven't worked on the BLE library for quite some time. If expressif released here APIs, then they are likely not supported. We are using nimble as stack. If it supports BLE 5, then changing the code might not be too hard; depending on what is needed.
  • o

    ow-peter

    12/09/2025, 2:53 PM
    Sweet, thanks very much! I'll have a go and do a pull request if I get it working ok
  • f

    floitsch

    12/09/2025, 2:54 PM
    That would be great. Don't hesitate to ask questions, or request feedback for incomplete PRs.
  • a

    addshore

    12/11/2025, 1:31 PM
    I dont appear to be able to add anyone as a reviewer on https://github.com/toitlang/action-setup/pull/9 but would be great if someone could take a look