#flutter
#flutterreactiveble
#blenoscan
#hm19
#hm19blemodule
#micropython
#pico
#raspberrypipico
replace _GT_ with greater than symbol
replace _LT_ with less than symbol
youtube dont like angle brackets
ble no scan get nrf connect in google store to find your ble id
#filename:uart_test.py
#uses hm19 ble module - amazon item #8541588324
#pico pin4 - hm-19 rxd
#pico pin5 - hm-19 txd
#pico pin40 - hm-19 vcc
from machine import UART,ADC
import time
t=ADC(4)
uart=UART(1,9600)
while 1:
time.sleep_ms(500)
uart.write(str(t.read_u16()))
////////////////filename: main.dart
//change in build.gradle - minSdkVersion 21
//give this app location permission and turn on bluetooth on your phone/tablet
//add plugins - flutter_reactive_ble and get
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import './blecontroller.dart';
void main() {
runApp(MyApp());}
class MyApp extends StatelessWidget {
@override Widget build(BuildContext context) {
return GetMaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,),
home: MyHomePage());}}
class MyHomePage extends StatelessWidget {
TextStyle myStyle = TextStyle(fontSize: 30);
final BleController c = Get.put(BleController());
MyHomePage();
@override Widget build(BuildContext context){
return Scaffold(
appBar: AppBar(title: Text('ble test')),
body: Column(children: _LT_Widget_GT_[
SizedBox(height:50),
Obx(() =_GT_ Text('${c.status}',
style:myStyle)),
SizedBox(height:50),
Obx(() =_GT_ Text('pico adc(4) value: ${c.temperature}',
style:myStyle)),
SizedBox(height:50),
Obx(() =_GT_ Container(
child: c.status != 'connected!'
? ElevatedButton(onPressed: c.connect,
child: Text('connect',
style:myStyle))
: null))]));}}
//////////////////// filename: blecontroller.dart
// ble no scan get nrf connect in google play store to get ble id
import 'package:flutter/material.dart';
import 'package:flutter_reactive_ble/flutter_reactive_ble.dart';
import 'dart:async';
import 'package:get/get.dart';
class BleController {
final frb = FlutterReactiveBle();
late StreamSubscription_LT_ConnectionStateUpdate_GT_ connection;
late QualifiedCharacteristic rx;
RxString status = 'not connected'.obs;
RxString temperature = ' '.obs;
void connect() async {
status.value = 'connecting...';
connection = frb.connectToDevice(id: 'A4:DA:32:55:06:1E').listen((state){
if (state.connectionState == DeviceConnectionState.connected){
status.value = 'connected!';
// get rx
rx = QualifiedCharacteristic(
serviceId: Uuid.parse("0000ffe0-0000-1000-8000-00805f9b34fb"),
characteristicId: Uuid.parse("0000ffe1-0000-1000-8000-00805f9b34fb"),
deviceId:'A4:DA:32:55:06:1E' );
// subscribe to rx
frb.subscribeToCharacteristic(rx).listen((data){
temperature.value = String.fromCharCodes(data);
});}});}}
#flutterreactiveble
#blenoscan
#hm19
#hm19blemodule
#micropython
#pico
#raspberrypipico
replace _GT_ with greater than symbol
replace _LT_ with less than symbol
youtube dont like angle brackets
ble no scan get nrf connect in google store to find your ble id
#filename:uart_test.py
#uses hm19 ble module - amazon item #8541588324
#pico pin4 - hm-19 rxd
#pico pin5 - hm-19 txd
#pico pin40 - hm-19 vcc
from machine import UART,ADC
import time
t=ADC(4)
uart=UART(1,9600)
while 1:
time.sleep_ms(500)
uart.write(str(t.read_u16()))
////////////////filename: main.dart
//change in build.gradle - minSdkVersion 21
//give this app location permission and turn on bluetooth on your phone/tablet
//add plugins - flutter_reactive_ble and get
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import './blecontroller.dart';
void main() {
runApp(MyApp());}
class MyApp extends StatelessWidget {
@override Widget build(BuildContext context) {
return GetMaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,),
home: MyHomePage());}}
class MyHomePage extends StatelessWidget {
TextStyle myStyle = TextStyle(fontSize: 30);
final BleController c = Get.put(BleController());
MyHomePage();
@override Widget build(BuildContext context){
return Scaffold(
appBar: AppBar(title: Text('ble test')),
body: Column(children: _LT_Widget_GT_[
SizedBox(height:50),
Obx(() =_GT_ Text('${c.status}',
style:myStyle)),
SizedBox(height:50),
Obx(() =_GT_ Text('pico adc(4) value: ${c.temperature}',
style:myStyle)),
SizedBox(height:50),
Obx(() =_GT_ Container(
child: c.status != 'connected!'
? ElevatedButton(onPressed: c.connect,
child: Text('connect',
style:myStyle))
: null))]));}}
//////////////////// filename: blecontroller.dart
// ble no scan get nrf connect in google play store to get ble id
import 'package:flutter/material.dart';
import 'package:flutter_reactive_ble/flutter_reactive_ble.dart';
import 'dart:async';
import 'package:get/get.dart';
class BleController {
final frb = FlutterReactiveBle();
late StreamSubscription_LT_ConnectionStateUpdate_GT_ connection;
late QualifiedCharacteristic rx;
RxString status = 'not connected'.obs;
RxString temperature = ' '.obs;
void connect() async {
status.value = 'connecting...';
connection = frb.connectToDevice(id: 'A4:DA:32:55:06:1E').listen((state){
if (state.connectionState == DeviceConnectionState.connected){
status.value = 'connected!';
// get rx
rx = QualifiedCharacteristic(
serviceId: Uuid.parse("0000ffe0-0000-1000-8000-00805f9b34fb"),
characteristicId: Uuid.parse("0000ffe1-0000-1000-8000-00805f9b34fb"),
deviceId:'A4:DA:32:55:06:1E' );
// subscribe to rx
frb.subscribeToCharacteristic(rx).listen((data){
temperature.value = String.fromCharCodes(data);
});}});}}
- Категория
- Язык программирования Dart
Комментариев нет.