-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
59 lines (51 loc) · 1.76 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using GreenHouseAssistant.Api;
using GreenHouseAssistant.Gpio;
using GreenHouseAssistant.Network;
using System;
using System.Diagnostics;
using System.Threading;
namespace GreenHouseAssistant
{
public class Program
{
private static OnBoardLed _boardLed;
public static void Main()
{
//dotnet tool update -g nanoff
//nanoff --update --platform esp32 --serialport COM3 --preview
ConnectToWiFiRouter();
Thread.Sleep(Timeout.Infinite);
}
private static void ConnectToWiFiRouter()
{
_boardLed = OnBoardLed.GetOnBoardLed();
WiFiNetworkAdapter adapter = new WiFiNetworkAdapter();
adapter.OnConnected += WiFiAdapter_OnConnected;
adapter.OnConnectingError += WiFiAdapter_OnConnectingError;
_boardLed.StartBlinking();
adapter.InitWithDHCP("PA-WIFI", "!panfilii@#");
//adapter.InitWithDHCP("wifi-ssid", "password");
}
private static void StartWebServer()
{
_boardLed.StartBlinkingFast();
var isWebServerStarted = WebApiServer.StartWebServer();
if (isWebServerStarted)
{
_boardLed.TurnOff();
return;
}
_boardLed.TurnOn();
}
private static void WiFiAdapter_OnConnectingError(WiFiConnectionErrorEventArgs e)
{
Debug.WriteLine($"Wifi connection error: {e.ConnectionError} \n Exception: {e.Exception}");
_boardLed.TurnOn();
}
private static void WiFiAdapter_OnConnected(WiFiConnectedEventArgs e)
{
Debug.WriteLine($"Wifi connected with IP Address: {e.IpAddress}");
StartWebServer();
}
}
}