Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
Robobin
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
plw1g21
Robobin
Commits
d5a636f0
Commit
d5a636f0
authored
5 months ago
by
Paul-Winpenny
Browse files
Options
Downloads
Patches
Plain Diff
Read and write values of the characteristics are now gotten.
parent
6bf364f0
No related branches found
Branches containing commit
No related tags found
1 merge request
!1
App now has a basic structure and BLE support
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
App/RobobinApp/ViewModels/ConnectionPageViewModel.cs
+48
-24
48 additions, 24 deletions
App/RobobinApp/ViewModels/ConnectionPageViewModel.cs
with
48 additions
and
24 deletions
App/RobobinApp/ViewModels/ConnectionPageViewModel.cs
+
48
−
24
View file @
d5a636f0
...
...
@@ -15,6 +15,9 @@ using System.Collections.Generic;
using
Windows.Networking.Connectivity
;
using
Windows.Devices.WiFi
;
using
System.Reflection.PortableExecutable
;
using
Plugin.BLE.Windows
;
using
System.Text
;
namespace
RobobinApp.ViewModels
{
...
...
@@ -33,6 +36,9 @@ namespace RobobinApp.ViewModels
private
string
ssid
;
private
string
password
;
public
bool
IsBluetoothDeviceSelectionVisible
=>
!
IsWifiNetworkSelectionVisible
;
public
const
string
SendReceiveServiceUUID
=
"00000001-710e-4a5b-8d75-3e5b444bc3cf"
;
public
const
string
rxUUID
=
"00000002-710e-4a5b-8d75-3e5b444bc3cf"
;
public
const
string
wxUUID
=
"00000003-710e-4a5b-8d75-3e5b444bc3cf"
;
public
bool
IsConnected
{
...
...
@@ -98,7 +104,7 @@ namespace RobobinApp.ViewModels
Debug
.
WriteLine
(
"Checking and requesting Bluetooth permissions."
);
CheckAndRequestBluetoothPermissions
();
ScanForWifiNetworks
();
//
ScanForWifiNetworks();
}
private
async
void
ScanForWifiNetworks
()
{
...
...
@@ -130,7 +136,7 @@ namespace RobobinApp.ViewModels
SignalStrength
=
network
.
NetworkRssiInDecibelMilliwatts
};
Device
.
BeginInvokeOnMainThread
(()
=>
WifiNetworks
.
Add
(
wifiNetwork
));
Microsoft
.
Maui
.
Controls
.
Device
.
BeginInvokeOnMainThread
(()
=>
WifiNetworks
.
Add
(
wifiNetwork
));
Debug
.
WriteLine
(
$"Found Wi-Fi network:
{
wifiNetwork
.
SSID
}
, Signal Strength:
{
wifiNetwork
.
SignalStrength
}
dBm"
);
}
}
...
...
@@ -172,7 +178,7 @@ namespace RobobinApp.ViewModels
}
var
characteristics
=
await
uartService
.
GetCharacteristicsAsync
();
var
rxCharacteristic
=
characteristics
.
FirstOrDefault
(
c
=>
c
.
Id
==
Guid
.
Parse
(
"6e400002-b5a3-f393-e0a9-e50e24dcca9e"
));
var
rxCharacteristic
=
characteristics
.
FirstOrDefault
(
c
=>
c
.
Id
==
Guid
.
Parse
(
rxUUID
));
if
(
rxCharacteristic
==
null
)
{
...
...
@@ -296,7 +302,7 @@ namespace RobobinApp.ViewModels
if
(!
BluetoothDevices
.
Any
(
d
=>
d
.
MacAddress
==
bluetoothDevice
.
MacAddress
))
{
Device
.
BeginInvokeOnMainThread
(()
=>
BluetoothDevices
.
Add
(
bluetoothDevice
));
Microsoft
.
Maui
.
Controls
.
Device
.
BeginInvokeOnMainThread
(()
=>
BluetoothDevices
.
Add
(
bluetoothDevice
));
}
}
...
...
@@ -353,30 +359,48 @@ namespace RobobinApp.ViewModels
{
Debug
.
WriteLine
(
$"Service: ID=
{
service
.
Id
}
, Name=
{
service
.
Name
}
"
);
// Check if this is the Generic Access service
if
(
service
.
Id
==
Guid
.
Parse
(
"00001800-0000-1000-8000-00805f9b34fb"
))
}
var
transmitService
=
services
.
FirstOrDefault
(
s
=>
s
.
Id
==
Guid
.
Parse
(
SendReceiveServiceUUID
));
Debug
.
WriteLine
(
"Transmit service was accessed"
);
Debug
.
WriteLine
(
$"
{
transmitService
.
Name
}
:
{
transmitService
.
Id
}
"
);
if
(
transmitService
==
null
)
{
Debug
.
WriteLine
(
"Transmit service wasn't found"
);
}
var
characteristics
=
await
transmitService
.
GetCharacteristicsAsync
();
foreach
(
var
characteristic
in
characteristics
)
{
Debug
.
WriteLine
(
$"
{
characteristic
.
Uuid
}
|
{
characteristic
.
Name
}
"
);
if
(
characteristic
.
Uuid
.
Equals
(
rxUUID
))
{
Debug
.
WriteLine
(
"Found Generic Access service!"
);
// Get the characteristic for the device name
var
deviceNameCharacteristic
=
service
.
GetCharacteristicAsync
(
Guid
.
Parse
(
"00002a00-0000-1000-8000-00805f9b34fb"
));
if
(
deviceNameCharacteristic
!=
null
)
{
// Read the device name characteristic
Debug
.
WriteLine
(
$"Device Name:
{
deviceNameCharacteristic
}
"
);
await
Application
.
Current
.
MainPage
.
DisplayAlert
(
"Device Name"
,
$"Device Name: Paul"
,
"OK"
);
}
else
{
Debug
.
WriteLine
(
"Device name characteristic not found."
);
}
Debug
.
WriteLine
(
"Found Read"
);
// Read the value from the characteristic
var
temperatureData
=
await
characteristic
.
ReadAsync
();
// Convert the byte array to a string
var
temperatureValue
=
System
.
Text
.
Encoding
.
UTF8
.
GetString
(
temperatureData
.
data
);
Debug
.
WriteLine
(
$"Temperature Value:
{
temperatureValue
}
"
);
}
else
if
(
characteristic
.
Uuid
.
Equals
(
wxUUID
))
{
Debug
.
WriteLine
(
"Found Write"
);
// Read the current value (if needed)
var
writeValueData
=
await
characteristic
.
ReadAsync
();
var
writeValue
=
System
.
Text
.
Encoding
.
UTF8
.
GetString
(
writeValueData
.
data
);
Debug
.
WriteLine
(
$"Current Write Value:
{
writeValue
}
"
);
}
}
// Optional: Handle other services or characteristics if needed
}
}
catch
(
DeviceConnectionException
ex
)
{
Debug
.
WriteLine
(
$"Connection error:
{
ex
.
Message
}
"
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment