How can I send data to STM32 CARD using flutter?

Issue

This Content is from Stack Overflow. Question asked by syrine

actually I want to send data via bluetooth to an STM 32 card. I could connect with it But now I have no idea about sending data to this card. I created a simple form to write text at first time but I don’t have solution for sending the data(text, float,…).
My question is finding some way to send any data to the STM32 card.
This is the code that connect and showing some informations about the card :

 setBleConnectionState(BluetoothDeviceState.disconnected);
    }).then((data) async {
      bluetoothService.clear();
      if (returnValue == null) {
       
        debugPrint('connection successful');
        print('start discover service');
        List<BluetoothService> bleServices =
            await widget.device.discoverServices();
        setState(() {
          bluetoothService = bleServices;
        });
      
        for (BluetoothService service in bleServices) {
          print('============================================');
          print('Service UUID: ${service.uuid}');
          for (BluetoothCharacteristic c in service.characteristics) {
            print('tcharacteristic UUID: ${c.uuid.toString()}');
            print('ttwrite: ${c.properties.write}');
            print('ttread: ${c.properties.read}');
            print('ttnotify: ${c.properties.notify}');
            print('ttisNotifying: ${c.isNotifying}');
            print(
                'ttwriteWithoutResponse: ${c.properties.writeWithoutResponse}');
            print('ttindicate: ${c.properties.indicate}');


            if (c.properties.notify && c.descriptors.isNotEmpty) {
              
              for (BluetoothDescriptor d in c.descriptors) {
                print('BluetoothDescriptor uuid ${d.uuid}');
                if (d.uuid == BluetoothDescriptor.cccd) {
                  print('d.lastValue: ${d.lastValue}');
                }
              }

              
              if (!c.isNotifying) {
                try {
                  await c.setNotifyValue(true);
                 
                  notifyDatas[c.uuid.toString()] = List.empty();
                  c.value.listen((value) {
                    
                    print('${c.uuid}: $value');
                    setState(() {
                      
                      notifyDatas[c.uuid.toString()] = value;
                    });
                  });

                
                  await Future.delayed(const Duration(milliseconds: 500));
                } catch (e) {
                  print('error ${c.uuid} $e');
                }
              }
            }
          }
        }
        returnValue = Future.value(true);
      }
    });

    return returnValue ?? Future.value(false);
  }

  
  void disconnect() {
    try {
      setState(() {
        stateText = 'Disconnecting';
      });
      widget.device.disconnect();
    } catch (e) {}
  }

I know that I have to send data using the uuid of the card but I don’t know how to create the code.
I would be very thankful if you can help me by giving me some ideas.



Solution

This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?