Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added Design/BTBasics-CharacteristicList.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Design/BTBasics-PostWrite.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Design/BTBasics-PreWrite.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Design/BTBasics-WriteCharacteristicValue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Design/BTNotify-CharacteristicProperties.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Design/BTNotify-Devices.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Design/BTNotify-NotificationCharacteristic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ private void LoadSplashLayout()
logo.Height,
logo)
{
BackColor = backgroundColor,
BackgroundColor = backgroundColor,
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ private void LoadSplashLayout()
var image = Image.LoadFromResource("ProjectLab_AzureIoTHub.Resources.img_meadow.bmp");
var displayImage = new Picture(0, 0, displayScreen.Width, displayScreen.Height, image)
{
BackColor = Color.FromHex("F39E6C"),
BackgroundColor = Color.FromHex("F39E6C"),
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center,
};
Expand Down
19 changes: 15 additions & 4 deletions Source/Meadow F7/Bluetooth/Bluetooth_Basics/MeadowApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,28 @@

namespace Bluetooth_Basics;

// public class MeadowApp : App<F7FeatherV1>
//public class MeadowApp : App<F7CoreComputeV2>
public class MeadowApp : App<F7FeatherV2>
{
Definition bleTreeDefinition;
CharacteristicBool onOffCharacteristic;
private Definition bleTreeDefinition;
private CharacteristicBool onOffCharacteristic;

public override Task Initialize()
{
Resolver.Log.Info("Initialize hardware...");

// initialize the bluetooth defnition tree
// initialize the bluetooth definition tree
Resolver.Log.Info("Starting the BLE server.");
bleTreeDefinition = GetDefinition();

Device.BluetoothAdapter.ServerStarting += (s, e) => { Resolver.Log.Info("Server starting..."); };
Device.BluetoothAdapter.ServerStarted += (s, e) => { Resolver.Log.Info("Server started"); };
Device.BluetoothAdapter.ServerStopping += (s, e) => { Resolver.Log.Info("Server stopping..."); };
Device.BluetoothAdapter.ServerStopped += (s, e) => { Resolver.Log.Info("Server stopped"); };
Device.BluetoothAdapter.ClientConnected += (s, e) => { Resolver.Log.Info("Client connected"); };
Device.BluetoothAdapter.ClientDisconnected += (s, e) => { Resolver.Log.Info("Client disconnected"); };

Device.BluetoothAdapter.StartBluetoothServer(bleTreeDefinition);

// wire up some notifications on set
Expand All @@ -26,6 +36,7 @@ public override Task Initialize()
characteristic.ValueSet += (c, d) =>
{
Resolver.Log.Info($"HEY, I JUST GOT THIS BLE DATA for Characteristic '{c.Name}' of type {d.GetType().Name}: {d}");
c.SetValue(d);
};
}

Expand Down Expand Up @@ -76,6 +87,6 @@ protected Definition GetDefinition()
)
);

return new Definition("MY MEADOW F7", service);
return new Definition(Device.Information.DeviceName, service);
}
}
35 changes: 35 additions & 0 deletions Source/Meadow F7/Bluetooth/Bluetooth_Basics/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Bluetooth Basics Example

This example demonstrates how to use a range of characteristics:

* Integer
* Boolean
* Binary Data

as well as showing how to use read only values.

## Description

This application will set up a service with four characteristics with various properties.

## Connecting to Meadow

The application behaviour can be examined using a Bluetooth client application such as LightBlue. When LightBlue first starts it will display a list of devices detected:

![Bluetooth Devices](../../../../Design/BTNotify-Devices.png)

Clicking on the _MeadowF7_ will bring up the list of available characteristics:

![Bluetooth Characteristics](../../../../Design/BTBasics-CharacteristicList.png)

Clicking on any of the _Read, Write_ characteristics allows the value to be changed, for example:

![Bluetooth Characteristic Before Update](../../../../Design/BTBasics-PreWrite.png)

Clicking on any of the _Read, Write_ characteristics allows the value to be changed, for example:

![Bluetooth Write Characteristic Value](../../../../Design/BTBasics-WriteCharacteristicValue.png)

Once the value has been written, LightBlue will read the value back and show the value:

![Bluetooth Characteristic Following Update](../../../../Design/BTBasics-PostWrite.png)
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Meadow.Sdk/1.1.0">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<OutputType>Library</OutputType>
<AssemblyName>App</AssemblyName>
<LangVersion>10.0</LangVersion>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\..\..\Meadow.Core\source\Meadow.Core\Meadow.Core.csproj" />
<ProjectReference Include="..\..\..\..\..\Meadow.Contracts\Source\Meadow.Contracts\Meadow.Contracts.csproj" />
<ProjectReference Include="..\..\..\..\..\Meadow.Core\source\implementations\f7\Meadow.F7\Meadow.F7.csproj" />
<ProjectReference Include="..\..\..\..\..\Meadow.ProjectLab\Source\Meadow.ProjectLab\Meadow.ProjectLab.csproj" />
<ProjectReference Include="..\..\..\..\..\Meadow.Foundation\Source\Meadow.Foundation.Libraries_and_Frameworks\Graphics.MicroLayout\Driver\Graphics.MicroLayout.csproj" />
<ProjectReference Include="..\..\..\..\..\Meadow.Foundation\Source\Meadow.Foundation.Peripherals\Displays.TftSpi\Driver\Displays.TftSpi.csproj" />
</ItemGroup>
</Project>
25 changes: 25 additions & 0 deletions Source/Meadow F7/Bluetooth/Bluetooth_Notify/Bluetooth_Notify.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.002.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bluetooth_Notify", "Bluetooth_Notify.csproj", "{67081EA1-826E-454D-BCEF-0B1466B50E38}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{67081EA1-826E-454D-BCEF-0B1466B50E38}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{67081EA1-826E-454D-BCEF-0B1466B50E38}.Debug|Any CPU.Build.0 = Debug|Any CPU
{67081EA1-826E-454D-BCEF-0B1466B50E38}.Release|Any CPU.ActiveCfg = Release|Any CPU
{67081EA1-826E-454D-BCEF-0B1466B50E38}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {63F68F0C-3784-42B0-9B3A-175D501EC826}
EndGlobalSection
EndGlobal
77 changes: 77 additions & 0 deletions Source/Meadow F7/Bluetooth/Bluetooth_Notify/MeadowApp.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
using Meadow;
using Meadow.Devices;
using Meadow.Gateways.Bluetooth;
using System;
using System.Threading.Tasks;
using System.Threading;

namespace Bluetooth_Notify;

// public class MeadowApp : App<F7FeatherV1>
// public class MeadowApp : App<F7FeatherV2>
public class MeadowApp : App<F7CoreComputeV2>
{
/// <summary>
/// Name of the notify characteristic.
/// </summary>
const string NOTIFY_FIELD_NAME = "NotifyField";

/// <summary>
/// UUID of the notify characteristic.
/// </summary>
const string NOTIFY_FIELD_UUID = "018e99d6-8a61-11eb-8dcd-0242ac1300cc";

/// <summary>
/// Definition of the Bluetooth service.
/// </summary>
Definition bleTreeDefinition;

/// <summary>
/// Notification characteristic.
/// </summary>
CharacteristicInt32 _notifyCharacteristic;

/// <summary>
/// Set up the service and definition objects for the BLE server and start Bluetooth with the services
/// defined for service A.
/// </summary>
public override Task Initialize()
{
Resolver.Log.Info("Starting the BLE server.");

_notifyCharacteristic = new CharacteristicInt32(NOTIFY_FIELD_NAME,
uuid: NOTIFY_FIELD_UUID,
permissions: CharacteristicPermission.Write | CharacteristicPermission.Read,
properties: CharacteristicProperty.Write | CharacteristicProperty.Read | CharacteristicProperty.Notify
);
var service = new Service(
"GattService",
253,

_notifyCharacteristic
);
bleTreeDefinition = new Definition(Device.Information.DeviceName, service);
Device.BluetoothAdapter.StartBluetoothServer(bleTreeDefinition);

return base.Initialize();
}

/// <summary>
/// Run the test.
/// </summary>
public override Task Run()
{
Resolver.Log.Info("Running Bluetooth_Notify test.");

for (int index = 0; index < 60; index++)
{
_notifyCharacteristic.SetValue(index + 1);
Resolver.Log.Info($"Notification value: {index + 1}");
Thread.Sleep(1000);
}

Resolver.Log.Info("Test complete.");

return Task.CompletedTask;
}
}
25 changes: 25 additions & 0 deletions Source/Meadow F7/Bluetooth/Bluetooth_Notify/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Bluetooth Notification Characteristic Example

This example demonstrates how to use a notification characteristic.

## Description

This application will set up a service with a single characteristic. The characteristic will have notification properties meaning the system will notify a connected client each time the characteristic value changes. The application will set the value from 1 to 60 once per second.

## Connecting to Meadow

The application behaviour can be examined using a Bluetooth client application such as LightBlue. When LightBlue first starts it will display a list of devices detected:

![Bluetooth Devices](../../../../Design/BTNotify-Devices.png)

Clicking on the _MeadowF7_ will bring up the list of available characteristic:

![Bluetooth Characteristics](../../../../Design/BTNotify-NotificationCharacteristic.png)

Clicking on the characteristic will present the properties of the characteristic:

![Bluetooth Characteristic Properties](../../../../Design/BTNotify-CharacteristicProperties.png)

Note the characteristic supports subscriptions (notifications). Clicking on the _Subscribe_ button will show the notifications appearing with the updated values appearing every second for up to 60 seconds.

![Bluetooth Characteristic Notifications](../../../../Design/BTNotify-NotificationCharacteristicValues.png)
63 changes: 63 additions & 0 deletions Source/Meadow F7/Bluetooth/Bluetooth_Notify/meadow.config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#
# Device specific config.
#
Device:
#
# Name of the device on the network.
#
Name: BluetoothNotify
#
# Network configuration.
#
Network:
Interfaces:
- Name: Ethernet
UseDHCP: false
IPAddress: 192.168.1.40
NetMask: 255.255.255.0
Gateway: 192.168.1.254
- Name: WiFi
UseDHCP: true
IPAddress: 192.168.1.16
NetMask: 255.255.255.0
Gateway: 192.168.1.254
#
# Which interface should be used?
#
DefaultInterface: WiFi
#
# Automatically attempt to get the time at startup?
#
GetNetworkTimeAtStartup: 1
#
# Name of the NTP servers.
#
NtpServers:
- 0.pool.ntp.org
- 1.pool.ntp.org
- 2.pool.ntp.org
- 3.pool.ntp.org
#
# How often should the time be refreshed?
#
NtpRefreshPeriodSeconds: 3600
#
# IP address(es) of the DNS servers.
#
DnsServers:
# Cloudflare
- 1.1.1.1
# Google
- 8.8.8.8
# Open DNS (Cisco)
- 208.67.222.222
# Quad 9
- 9.9.9.9
#
# ESP32 properties.
#
CoProcessor:
#
# Should we start the network using stored WiFi credentials.
#
AutomaticallyStartNetwork: false
8 changes: 4 additions & 4 deletions Source/Meadow F7/Bluetooth/Bluetooth_Restart/MeadowApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

namespace Bluetooth_Restart;

// public class MeadowApp : App<F7FeatherV1>, IApp
// public class MeadowApp : App<F7FeatherV2>, IApp
// public class MeadowApp : App<F7FeatherV1>
// public class MeadowApp : App<F7FeatherV2>
public class MeadowApp : App<F7CoreComputeV2>
{
/// <summary>
Expand Down Expand Up @@ -160,7 +160,7 @@ protected void SetupDefinitions()
};

_serviceA = new Service("GattServiceA", 0xfa, numberFieldA);
_bleADefinition = new Definition("MeadowF7A", _serviceA);
_bleADefinition = new Definition($"{Device.Information.DeviceName}A", _serviceA);

var numberFieldB = new CharacteristicInt32(
SERVICE_B_NUMBER_FIELD_NAME,
Expand Down Expand Up @@ -194,6 +194,6 @@ protected void SetupDefinitions()
};

_serviceB = new Service("GattServiceB", 0xfb, numberFieldB);
_bleBDefinition = new Definition("MeadowF7B", _serviceB);
_bleBDefinition = new Definition($"{Device.Information.DeviceName}B", _serviceB);
}
}
21 changes: 21 additions & 0 deletions Source/Meadow F7/Bluetooth/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Bluetooth Examples

## Bluetooth Server Examples

The server applications can be tested using client applications such as LightBlue or using a python script using the Bleak Python library.

### Bluetooth_Basics

This example sets up a basic Bluetooth server with a number of characteristics showing how to use:

* Integers
* Booleans
* Binary data

### Bluetooth_Notify

This example shows how to use the notification property of characteristics to notify a client, running on say a mobile phone, that the server has changed the value of the characteristic.

### Bluetooth_Restart

This example shows how to use the stop methods to change from one service to a new service with a different definition.
Loading
Loading