Skip to content

Commit

Permalink
Update GetStartedExample
Browse files Browse the repository at this point in the history
  • Loading branch information
hbjorgo committed Dec 20, 2024
1 parent 44669e0 commit 08ab763
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/HeboTech.ATLib.TestConsole/GetStartedExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using HeboTech.ATLib.Parsing;
using System;
using System.IO.Ports;
using System.Linq;
using System.Threading.Tasks;

namespace HeboTech.ATLib.TestConsole
Expand All @@ -28,6 +27,18 @@ public static async Task RunAsync(string portName, int baudRate, string pin, str
// Create the modem
using IModem modem = new Fona3G(atChannel);

// Listen to incoming SMSs
modem.SmsReceived += (sender, args) =>
{
Console.WriteLine($"SMS received: {args.SmsDeliver}");
};

// Listen to incoming SMSs stored in memory
modem.SmsStorageReferenceReceived += (sender, args) =>
{
Console.WriteLine($"SMS received. Index {args.Index} at storage location {args.Storage}");
};

// Open AT channel
atChannel.Open();

Expand All @@ -48,11 +59,17 @@ public static async Task RunAsync(string portName, int baudRate, string pin, str
// Configure modem with required settings after PIN
var requiredSettingsAfterPin = await modem.SetRequiredSettingsAfterPinAsync();

// Read SMS at index 1
var sms = await modem.ReadSmsAsync(1);
if (sms.Success)
Console.WriteLine(sms.Result);

// Send SMS to the specified number
PhoneNumber phoneNumber = PhoneNumberFactory.CreateCommonIsdn(recepientPhoneNumber);
string message = "Hello ATLib!";
var smsReferences = await modem.SendSmsAsync(new SmsSubmitRequest(phoneNumber, message));
Console.WriteLine($"SMS Reference: {smsReferences.First()}");
foreach (var smsReference in smsReferences)
Console.WriteLine($"SMS Reference: {smsReference}");
}
}
}

0 comments on commit 08ab763

Please sign in to comment.