Added NightAlert project for travel kit
This commit is contained in:
136
NightScout/Program.cs
Normal file
136
NightScout/Program.cs
Normal file
@@ -0,0 +1,136 @@
|
||||
using System;
|
||||
using System.Configuration;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using log4net;
|
||||
using NightScout;
|
||||
using NightscoutLibrary.Configuration;
|
||||
using Quobject.SocketIoClientDotNet.Client;
|
||||
|
||||
namespace NightScoutAlert
|
||||
{
|
||||
internal class Program
|
||||
{
|
||||
private static void Main(string[] args)
|
||||
{
|
||||
if (args.Any(arg => arg.Equals("--test-audio")))
|
||||
{
|
||||
Console.WriteLine("Starting audio test...");
|
||||
RaspberryPiAudioAlert alerter = new RaspberryPiAudioAlert();
|
||||
alerter.StartAlert();
|
||||
Thread.Sleep(3000);
|
||||
alerter.StopAlerts();
|
||||
return;
|
||||
}
|
||||
Quobject.EngineIoClientDotNet.Modules.LogManager.Enabled = true;
|
||||
|
||||
//NightscoutTestConfiguration configuration = new NightscoutTestConfiguration();
|
||||
//MonoCompatibleNightscoutAlertConfiguration configuration = new MonoCompatibleNightscoutAlertConfiguration("http://nightscout.chrispr.org:8082", "ThisIsATerribleAuthSystem");
|
||||
String nightscoutEndpoint = ConfigurationManager.AppSettings["NightscoutEndpoint"];
|
||||
String nightscoutCredentials = ConfigurationManager.AppSettings["NightscoutCredentials"];
|
||||
if (String.IsNullOrEmpty(nightscoutEndpoint) || String.IsNullOrEmpty(nightscoutCredentials))
|
||||
{
|
||||
Console.WriteLine("The nightscout endpoint and credentials must be filled into the App.config");
|
||||
return;
|
||||
}
|
||||
MonoCompatibleNightscoutAlertConfiguration configuration = new MonoCompatibleNightscoutAlertConfiguration(nightscoutEndpoint, nightscoutCredentials);
|
||||
RaspberryPIButtonSource buttonSource = null;
|
||||
|
||||
try
|
||||
{
|
||||
if (!String.IsNullOrEmpty(ConfigurationManager.AppSettings["ButtonSourceEnabled"]) &&
|
||||
Boolean.Parse(ConfigurationManager.AppSettings["ButtonSourceEnabled"]))
|
||||
{
|
||||
buttonSource = new RaspberryPIButtonSource(1);
|
||||
Console.WriteLine("Button source made");
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{}
|
||||
|
||||
NightscoutDataSource dataSource =null;
|
||||
RaspberryPiAudioAlert audioAlerter = null;
|
||||
|
||||
if (buttonSource != null)
|
||||
{
|
||||
dataSource = new NightscoutDataSource(configuration,
|
||||
log4net.LogManager.GetLogger("NightscoutAlert"), buttonSource);
|
||||
audioAlerter = new RaspberryPiAudioAlert(buttonSource);
|
||||
}
|
||||
else
|
||||
{
|
||||
dataSource = new NightscoutDataSource(configuration,
|
||||
log4net.LogManager.GetLogger("NightscoutAlert"));
|
||||
audioAlerter = new RaspberryPiAudioAlert();
|
||||
}
|
||||
ILog log = log4net.LogManager.GetLogger("NightscoutAlertMain");
|
||||
log.Debug("Log started");
|
||||
ConsoleAlerter consoleAlerter = new ConsoleAlerter();
|
||||
//
|
||||
|
||||
NightscoutAlerter nightscoutAlerter = new NightscoutAlerter(dataSource,
|
||||
new MultiAlerter(new IAlerter[] {consoleAlerter, audioAlerter, buttonSource}));
|
||||
|
||||
//var socket = IO.Socket(configuration.NightscoutBaseURL);
|
||||
|
||||
//socket.On(Socket.EVENT_CONNECT, () =>
|
||||
//{
|
||||
// Console.WriteLine("Connected...");
|
||||
// JObject authRequest = new JObject();
|
||||
// authRequest.Add("client", "web");
|
||||
|
||||
// socket.Emit("authorize", authRequest);
|
||||
//});
|
||||
//socket.On(Socket.EVENT_ERROR, (obj) =>
|
||||
//{
|
||||
// Console.WriteLine(obj.ToString());
|
||||
//});
|
||||
|
||||
//socket.On("dataUpdate", (data) =>
|
||||
//{
|
||||
// Console.WriteLine(data);
|
||||
//});
|
||||
|
||||
//socket.On("alarm", (data) =>
|
||||
//{
|
||||
// Console.WriteLine(data.ToString());
|
||||
//});
|
||||
|
||||
//socket.On(Socket.EVENT_MESSAGE, (data) =>
|
||||
//{
|
||||
// Console.WriteLine(data.ToString());
|
||||
//});
|
||||
|
||||
//socket.On("urgent_alarm", (data) =>
|
||||
//{
|
||||
// Console.WriteLine(data.ToString());
|
||||
//});
|
||||
|
||||
//socket.On("clear_alarm", (data) =>
|
||||
//{
|
||||
// Console.WriteLine(data.ToString());
|
||||
//});
|
||||
Console.WriteLine("Started");
|
||||
Console.ReadLine();
|
||||
}
|
||||
}
|
||||
|
||||
class NightscoutTestConfiguration : INightscoutAlertConfiguration
|
||||
{
|
||||
|
||||
public String NightscoutBaseURL
|
||||
{
|
||||
//get { return "http://straylight.chrispr.lan:8082"; }
|
||||
get { return "http://192.168.1.100:8082"; }
|
||||
set
|
||||
{throw new NotImplementedException();}
|
||||
}
|
||||
|
||||
public string APISecretKey
|
||||
{
|
||||
get { return "ThisIsATerribleAuthSystem"; }
|
||||
set
|
||||
{throw new NotImplementedException();}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user