However, after waking up, there is a hang when trying to send a message.
public class MeadowApp : App<F7FeatherV2>
{
RgbPwmLed onboardLed;
public override async Task Run()
{
var cloudLogger = new CloudLogger();
Resolver.Log.AddProvider(cloudLogger);
var mcs = Resolver.Services.Get<IMeadowCloudService>();
mcs.ConnectionStateChanged += (sender, state) =>
{
if (state == CloudConnectionState.Connected)
{
Device.PlatformOS.Sleep(TimeSpan.FromSeconds(60));
}
};
Device.PlatformOS.BeforeSleep += () =>
{
onboardLed.SetColor(Color.Green, 1);
// go to sleep after all queued messages have been sent
// APP HANGS HERE AFTER THE FIRST WAKE UP
while (mcs.QueueCount > 0)
{
Thread.Sleep(2000);
Resolver.Log.Trace($"queue count: {mcs.QueueCount}");
}
onboardLed.SetColor(Color.Red, 0);
};
Device.PlatformOS.AfterWake += async (sender, source) =>
{
onboardLed.SetBrightness(1);
Resolver.Log.Info("queue message after wake up.");
await Task.Delay(2000);
Device.PlatformOS.Sleep(TimeSpan.FromSeconds(60));
};
onboardLed.SetColor(Color.Red, 1);
Resolver.Log.Info("queue up message to be sent.");
Resolver.Log.Info("queue another message to be sent.");
}
public override Task Initialize()
{
onboardLed = new RgbPwmLed(
redPwmPin: Device.Pins.OnboardLedRed,
greenPwmPin: Device.Pins.OnboardLedGreen,
bluePwmPin: Device.Pins.OnboardLedBlue,
CommonType.CommonAnode);
return base.Initialize();
}
}
Currently Sleep works as expected in simple cases without networking. The app below sleeps for 5s and runs for 5s, continuously.
However, after waking up, there is a hang when trying to send a message.