Skip to content
This repository has been archived by the owner on Mar 12, 2024. It is now read-only.

Update cellular project #88

Merged
merged 5 commits into from
Oct 23, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<AssemblyName>App</AssemblyName>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Meadow.F7" Version="*" />
<ProjectReference Include="..\..\..\..\Meadow.Core\source\implementations\f7\Meadow.F7\Meadow.F7.csproj" />
jorgedevs marked this conversation as resolved.
Show resolved Hide resolved
</ItemGroup>
<ItemGroup>
<None Update="meadow.config.yaml">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
using System;
using System.Diagnostics;
using System.Net.Http;
using System.Threading.Tasks;
using Meadow;
using Meadow;
using Meadow.Devices;
using Meadow.Hardware;
using Meadow.Networking;
using System;
using System.Diagnostics;
using System.Net.Http;
using System.Threading.Tasks;

namespace Cell_Basics
{
public class MeadowApp : App<F7FeatherV2>
{
public override async Task Run()
public override Task Run()
{
var cell = Device.NetworkAdapters.Primary<ICellNetworkAdapter>();

Expand All @@ -21,27 +21,40 @@ public override async Task Run()
// (Optional) Call to retrieve cell connection logs, useful for troubleshooting
// GetCellConnectionLogs(cell);

// (Optional) Enable cell network scanner by setting 'ScanMode: true' in cell.config.yaml
// (Optional) Scan for available cellular networks
// CellNetworkScanner(cell);

// (Optional) Get current Cell Signal Quality (CSQ)
// FetchSignalQuality(cell);

return Task.CompletedTask;
}

// Useful method for troubleshooting by inspecting cell connection logs
void FetchSignalQuality(ICellNetworkAdapter cell)
{
double csq = cell.GetSignalQuality();
Console.WriteLine("Current Cell Signal Quality: " + csq);

double dbm = csq * 2 - 113;
Console.WriteLine("Current Cell Signal Quality (dbm): " + dbm);
}

// Useful method for troubleshooting by inspecting cellular connection logs
async void GetCellConnectionLogs(ICellNetworkAdapter cell)
{
while (!cell.IsConnected)
{
await Task.Delay(10000);
Console.WriteLine($"Cell AT commands output: {cell.AtCmdsOutput}"); // It only works with 'ScanMode: false'
Console.WriteLine($"Cell AT commands output: {cell.AtCmdsOutput}");
}
}

// Cell network scanner, useful to see the Cell available networks, including their Operator codes
// Get the available cellular networks, including their Operator codes
async void CellNetworkScanner(ICellNetworkAdapter cell)
{
try
{
// Scanning networks may take a few minutes
CellNetwork[] operatorList = cell.Scan(); // It only works with 'ScanMode: true' in cell.config.yaml
CellNetwork[] operatorList = cell.ScanForAvailableNetworks();
foreach (CellNetwork data in operatorList)
{
Console.WriteLine($"Operator Status: {data.Status}, Operator Name: {data.Name}, Operator: {data.Operator}, Operator Code: {data.Code}, Mode: {data.Mode}");
Expand All @@ -52,16 +65,16 @@ async void CellNetworkScanner(ICellNetworkAdapter cell)
Console.WriteLine(ex);
}
}

async void CellAdapter_NetworkConnected(INetworkAdapter networkAdapter, NetworkConnectionEventArgs e)
{
Console.WriteLine("Cell network connected!");

ICellNetworkAdapter cellAdapter = networkAdapter as ICellNetworkAdapter;
if (cellAdapter != null)
var cell = networkAdapter as ICellNetworkAdapter;
if (cell != null)
{
Console.WriteLine("Cell CSQ: " + cellAdapter.Csq);
Console.WriteLine("Cell IMEI: " + cellAdapter.Imei);
Console.WriteLine("Cell CSQ at the time of connection: " + cell.Csq);
Console.WriteLine("Cell IMEI: " + cell.Imei);
await GetWebPageViaHttpClient("https://postman-echo.com/get?fool=bar1&foo2=bar2");
}
}
Expand All @@ -71,7 +84,7 @@ void CellAdapter_NetworkDisconnected(INetworkAdapter networkAdapter)
Console.WriteLine("Cell network disconnected!");
}

public async Task GetWebPageViaHttpClient(string uri)
async Task GetWebPageViaHttpClient(string uri)
{
Console.WriteLine($"Requesting {uri} - {DateTime.Now}");
Stopwatch stopwatch = new Stopwatch();
Expand All @@ -80,7 +93,7 @@ public async Task GetWebPageViaHttpClient(string uri)
using (HttpClient client = new HttpClient())
{
// In weak signal connections and large download scenarios, it's recommended to increase the client timeout
client.Timeout = new TimeSpan(0, 60, 0);
client.Timeout = TimeSpan.FromMinutes(5);
using (HttpResponseMessage response = await client.GetAsync(uri, HttpCompletionOption.ResponseHeadersRead))
{
try
Expand Down Expand Up @@ -120,6 +133,5 @@ public async Task GetWebPageViaHttpClient(string uri)
}
}
}

}
}
13 changes: 13 additions & 0 deletions Source/Cellular/Cell_Basics/cell.config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Settings:
APN: YOUR-APN # (required) Access Point Name
Module: BG95M3 # (required) Module model (BG770A, BG95M3 or M95)
User: USER # (optional) APN user
Password: PASSWORD # (optional) APN password
Operator: 00000 # (optional) Carrier numeric operator code
Mode: CATM1 # (optional) Network mode (CATM1, NBIOT or GSM)
Interface: /dev/ttyS1 # (optional) Serial interface
# UART1 (COM1) = /dev/ttyS0
# UART4 (COM4) = /dev/ttyS1 (default),
# UART6 = /dev/ttyS3)
TurnOnPin: D10 # (optional) Enable pin to turn the module on/off.
# Default value is Meadow Pin name D10
13 changes: 13 additions & 0 deletions Source/Cellular/Cell_Basics/meadow.config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Device specific config.
Device:
# Name of the device on the network.
Name: CellBasics

# Corresponding MCU pin names for the reserved pins
# (COMX_RX pin, COM_TX pin, TURN_ON pin)
ReservedPins: I9;H13;C7

# Network configuration.
Network:
# Which interface should be used?
DefaultInterface: Cell
11 changes: 11 additions & 0 deletions Source/Meadow.Core.Samples.sln
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ChargeState", "OS\ChargeSta
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OS_Telemetry", "OS\OS_Telemetry\OS_Telemetry.csproj", "{F00D3CE4-803C-47E2-A34A-CB02AEF06454}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Cellular", "Cellular", "{1A8C277C-CD42-4C96-A372-582053CA8A4F}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cell_Basics", "Cellular\Cell_Basics\Cell_Basics.csproj", "{95117C8F-3EF0-4ADE-95C9-2493ED7802B7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -404,6 +408,12 @@ Global
{F00D3CE4-803C-47E2-A34A-CB02AEF06454}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F00D3CE4-803C-47E2-A34A-CB02AEF06454}.Release|Any CPU.Build.0 = Release|Any CPU
{F00D3CE4-803C-47E2-A34A-CB02AEF06454}.Release|Any CPU.Deploy.0 = Release|Any CPU
{95117C8F-3EF0-4ADE-95C9-2493ED7802B7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{95117C8F-3EF0-4ADE-95C9-2493ED7802B7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{95117C8F-3EF0-4ADE-95C9-2493ED7802B7}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
{95117C8F-3EF0-4ADE-95C9-2493ED7802B7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{95117C8F-3EF0-4ADE-95C9-2493ED7802B7}.Release|Any CPU.Build.0 = Release|Any CPU
{95117C8F-3EF0-4ADE-95C9-2493ED7802B7}.Release|Any CPU.Deploy.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -466,6 +476,7 @@ Global
{1711F10A-864D-4AE9-B6C2-5B36FD6B8171} = {E005B21B-E236-47DB-835A-6A86899BAFB3}
{DB7F472B-A997-4873-A44D-81C06FDE26BE} = {8D279C3D-43E8-4823-9D33-682231D1A48D}
{F00D3CE4-803C-47E2-A34A-CB02AEF06454} = {8D279C3D-43E8-4823-9D33-682231D1A48D}
{95117C8F-3EF0-4ADE-95C9-2493ED7802B7} = {1A8C277C-CD42-4C96-A372-582053CA8A4F}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {B3E6AE55-DFFB-4B7B-8143-96D0D1AA8CD9}
Expand Down
10 changes: 0 additions & 10 deletions Source/Meadow.Core.Samples/Network/Cell_Basics/cell.config.yaml

This file was deleted.

27 changes: 0 additions & 27 deletions Source/Meadow.Core.Samples/Network/Cell_Basics/meadow.config.yaml

This file was deleted.

Loading