Client now connects to the broker
This commit is contained in:
@@ -14,7 +14,7 @@ namespace PlantBox.Client.Forms.Controls.StatusBar
|
||||
public partial class StatusBar : ContentView
|
||||
{
|
||||
// Progress
|
||||
public static readonly BindableProperty ProgressProperty = BindableProperty.Create(nameof(Progress), typeof(double), typeof(StatusBar));
|
||||
public static readonly BindableProperty ProgressProperty = BindableProperty.Create(nameof(Progress), typeof(double), typeof(StatusBar), 0.5);
|
||||
public double Progress
|
||||
{
|
||||
get => (double)GetValue(ProgressProperty);
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
BoundColor="DarkSlateGray"
|
||||
BoundHeight="2"
|
||||
LowerBound="{Binding LuminosityCaptor.Min, Converter={x:StaticResource CaptorConverter}, ConverterParameter={x:Static models:CaptorType.Luminosity}}"
|
||||
UpperBound="-1"
|
||||
UpperBound="{Binding LuminosityCaptor.Max, Converter={x:StaticResource CaptorConverter}, ConverterParameter={x:Static models:CaptorType.Luminosity}}"
|
||||
Image="{extensions:ImageResource Luminosity_Icon.png}"
|
||||
FlexLayout.Basis="{StaticResource BarWidth}" />
|
||||
<statusbar:StatusBar Progress="{Binding TemperatureCaptor.Value, Converter={x:StaticResource CaptorConverter}, ConverterParameter={x:Static models:CaptorType.Temperature}}"
|
||||
@@ -49,8 +49,8 @@
|
||||
FlexLayout.Basis="{StaticResource BarWidth}" />
|
||||
<statusbar:StatusBar Progress="{Binding TankValue, Converter={x:StaticResource CaptorConverter}, ConverterParameter={x:Static models:CaptorType.Tank}}"
|
||||
Label="{Binding TankValue, StringFormat='\{0:F0} %'}"
|
||||
ForegroundColor="DeepSkyBlue"
|
||||
HintColor="SkyBlue"
|
||||
ForegroundColor="{StaticResource HumidityColor}"
|
||||
HintColor="{StaticResource HumidityColorSecondary}"
|
||||
BoundColor="DarkSlateGray"
|
||||
BoundHeight="2"
|
||||
LowerBound="-1"
|
||||
|
||||
@@ -170,11 +170,13 @@ namespace PlantBox.Client.Forms.Plant
|
||||
int index = 0;
|
||||
for (uint i = 0; index < entries.Length; i += (uint)step)
|
||||
{
|
||||
var value = values[i];
|
||||
entries[index] = new Entry((float)value.Value)
|
||||
var entry = values[i];
|
||||
double value = entry.Value != 0 ? entry.Value : 0.0001;
|
||||
|
||||
entries[index] = new Entry((float)value)
|
||||
{
|
||||
Label = value.Date.ToString(labelFormat),
|
||||
ValueLabel = string.Format(valueFormat, value.Value),
|
||||
Label = entry.Date.ToString(labelFormat),
|
||||
ValueLabel = string.Format(valueFormat, value),
|
||||
Color = colors[index]
|
||||
};
|
||||
|
||||
|
||||
@@ -9,19 +9,19 @@ namespace PlantBox.Client.Models
|
||||
public HistoricEntries MinutelyHistoric { get; }
|
||||
public HistoricEntries HourlyHistoric { get; }
|
||||
public HistoricEntries DailyHistoric { get; }
|
||||
public HistoricEntries WeeklyHistoric { get; }
|
||||
public HistoricEntries MonthlyHistoric { get; }
|
||||
|
||||
public Historic
|
||||
(
|
||||
HistoricEntries minutelyHistoric, HistoricEntries hourlyHistoric, HistoricEntries dailyHistoric,
|
||||
HistoricEntries weeklyHistoric, HistoricEntries monthlyHistoric
|
||||
HistoricEntries minutelyHistoric,
|
||||
HistoricEntries hourlyHistoric,
|
||||
HistoricEntries dailyHistoric,
|
||||
HistoricEntries monthlyHistoric
|
||||
)
|
||||
{
|
||||
MinutelyHistoric = minutelyHistoric;
|
||||
HourlyHistoric = hourlyHistoric;
|
||||
DailyHistoric = dailyHistoric;
|
||||
WeeklyHistoric = weeklyHistoric;
|
||||
MonthlyHistoric = monthlyHistoric;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using PlantBox.Client.Extensions;
|
||||
using PlantBox.Shared.Communication.Commands;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -26,6 +27,10 @@ namespace PlantBox.Client.Models
|
||||
Luminosities = ValuesToEntries(luminosities);
|
||||
Temperatures = ValuesToEntries(temperatures);
|
||||
}
|
||||
public HistoricEntries(HistoricResponse response, TimeSpan time) : this(DateTime.Now - response.Time, time, response.Humidities, response.Luminosities, response.Temperatures)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private HistoricEntry[] ValuesToEntries(double[] values)
|
||||
{
|
||||
|
||||
@@ -11,13 +11,25 @@ namespace PlantBox.Client.Models
|
||||
public ulong ID { get; }
|
||||
public PlantType Type { get; }
|
||||
public PlantState State { get; }
|
||||
public double HumidityMin { get; }
|
||||
public double HumidityMax { get; }
|
||||
public double LuminosityMin { get; }
|
||||
public double LuminosityMax { get; }
|
||||
public double TemperatureMin { get; }
|
||||
public double TemperatureMax { get; }
|
||||
|
||||
public PlantInfo(string name, ulong iD, PlantType type, PlantState state)
|
||||
public PlantInfo(string name, ulong id, PlantType type, PlantState state, double humidityMin, double humidityMax, double luminosityMin, double luminosityMax, double temperatureMin, double temperatureMax)
|
||||
{
|
||||
Name = name;
|
||||
ID = iD;
|
||||
ID = id;
|
||||
Type = type;
|
||||
State = state;
|
||||
HumidityMin = humidityMin;
|
||||
HumidityMax = humidityMax;
|
||||
LuminosityMin = luminosityMin;
|
||||
LuminosityMax = luminosityMax;
|
||||
TemperatureMin = temperatureMin;
|
||||
TemperatureMax = temperatureMax;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
using PlantBox.Client.Models;
|
||||
using PlantBox.Shared.Communication;
|
||||
using PlantBox.Shared.Communication.Commands;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Net.Sockets;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@@ -24,16 +26,37 @@ namespace PlantBox.Client.ViewModels
|
||||
|
||||
public ObservableCollection<PlantInfo> LoadPlants(IEnumerable<ulong> ids)
|
||||
{
|
||||
// Mock
|
||||
return new ObservableCollection<PlantInfo>
|
||||
(
|
||||
new[] {
|
||||
new PlantInfo("Salon", 0, PlantType.Ficus, PlantState.Good),
|
||||
new PlantInfo("Chambre", 1, PlantType.Bamboo, PlantState.Warning),
|
||||
new PlantInfo("Hellx", 2, PlantType.Cactus, PlantState.Bad),
|
||||
new PlantInfo("Hello", 3, PlantType.Cactus, PlantState.Bad)
|
||||
}.OrderBy(x => x.State).ThenBy(x => x.Name)
|
||||
);
|
||||
IEnumerable<PlantInfo> infos = GetPlantInfos(ids);
|
||||
|
||||
return new ObservableCollection<PlantInfo>(infos);
|
||||
}
|
||||
|
||||
private IEnumerable<PlantInfo> GetPlantInfos(IEnumerable<ulong> ids)
|
||||
{
|
||||
using (var client = new TcpClient(App.Settings.BrokerIP, Connection.TCP_CLIENT_PORT))
|
||||
{
|
||||
var stream = new CommandStream(client.GetStream());
|
||||
|
||||
foreach (ulong id in ids)
|
||||
{
|
||||
stream.Send(new InfoRequest().ToCommandPacket(id));
|
||||
(_, var responseInfo) = stream.Receive<InfoResponse>();
|
||||
|
||||
yield return new PlantInfo
|
||||
(
|
||||
responseInfo.Name,
|
||||
id,
|
||||
responseInfo.Type,
|
||||
responseInfo.State,
|
||||
responseInfo.HumidityMin,
|
||||
responseInfo.HumidityMax,
|
||||
responseInfo.LuminosityMin,
|
||||
responseInfo.LuminosityMax,
|
||||
responseInfo.TemperatureMin,
|
||||
responseInfo.TemperatureMax
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void OnPropertyChanged([CallerMemberName] string propertyName = null)
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
using PlantBox.Client.Models;
|
||||
using PlantBox.Shared.Communication;
|
||||
using PlantBox.Shared.Communication.Commands;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Net.Sockets;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
|
||||
@@ -119,27 +121,38 @@ namespace PlantBox.Client.ViewModels
|
||||
|
||||
private void LoadValues()
|
||||
{
|
||||
// TODO
|
||||
//throw new NotImplementedException();
|
||||
using (var client = new TcpClient(App.Settings.BrokerIP, Connection.TCP_CLIENT_PORT))
|
||||
{
|
||||
var stream = new CommandStream(client.GetStream());
|
||||
|
||||
// Temp
|
||||
HumidityCaptor = new CaptorValue(20, 80, 21);
|
||||
LuminosityCaptor = new CaptorValue(50, 1000, 375.6);
|
||||
TemperatureCaptor = new CaptorValue(20, 35, 27);
|
||||
TankValue = 78.45;
|
||||
// Captors info
|
||||
stream.Send(new CaptorsRequest().ToCommandPacket(PlantInfo.ID));
|
||||
(_, var captorsReponse) = stream.Receive<CaptorsResponse>();
|
||||
|
||||
var humidities = new[] { 45.5, 45, 89, 78, 42, 56, 45, 23, 14, 89, 10, 5 };
|
||||
var luminosities = new[] { 45.5, 45, 89, 78, 42, 56, 45, 23, 14, 89, 10, 5 };
|
||||
var temperatures = new[] { 45.5, 45, 89, 78, 42, 56, 45, 23, 14, 89, 10, 5 };
|
||||
var humidities2 = new[] { 45.5, 45, 89, 78, 42, 56, 45, 23, 14, 89, 10, 5, 45, 89, 78, 42, 56, 45, 23, 14, 89, 10, 5, 9 };
|
||||
var luminosities2 = new[] { 45.5, 45, 89, 78, 42, 56, 45, 23, 14, 89, 10, 5, 45, 89, 78, 42, 56, 45, 23, 14, 89, 10, 5, 9 };
|
||||
var temperatures2 = new[] { 45.5, 45, 89, 78, 42, 56, 45, 23, 14, 89, 10, 5, 45, 89, 78, 42, 56, 45, 23, 14, 89, 10, 5, 9 };
|
||||
HumidityCaptor = new CaptorValue(PlantInfo.HumidityMin, PlantInfo.HumidityMax, captorsReponse.Humidity);
|
||||
LuminosityCaptor = new CaptorValue(PlantInfo.LuminosityMin, PlantInfo.LuminosityMax, captorsReponse.Luminosity);
|
||||
TemperatureCaptor = new CaptorValue(PlantInfo.TemperatureMin, PlantInfo.TemperatureMax, captorsReponse.Temperature);
|
||||
TankValue = captorsReponse.Tank;
|
||||
|
||||
Historic = new Historic(new HistoricEntries(DateTime.Now, TimeSpan.FromMinutes(5), humidities, luminosities, temperatures),
|
||||
new HistoricEntries(DateTime.Now, TimeSpan.FromHours(1), humidities2, luminosities2, temperatures2),
|
||||
new HistoricEntries(DateTime.Now, TimeSpan.FromDays(1), humidities2, luminosities2, temperatures2),
|
||||
new HistoricEntries(DateTime.Now, TimeSpan.FromDays(7), humidities2, luminosities2, temperatures2),
|
||||
new HistoricEntries(DateTime.Now, TimeSpan.FromDays(31), humidities2, luminosities2, temperatures2));
|
||||
// Historic
|
||||
stream.Send(new HistoricRequest(HistoricInterval.Minutely, 12).ToCommandPacket(PlantInfo.ID));
|
||||
(_, var minutelyHistoric) = stream.Receive<HistoricResponse>();
|
||||
stream.Send(new HistoricRequest(HistoricInterval.Hourly, 48).ToCommandPacket(PlantInfo.ID));
|
||||
(_, var hourlyHistoric) = stream.Receive<HistoricResponse>();
|
||||
stream.Send(new HistoricRequest(HistoricInterval.Daily, 186).ToCommandPacket(PlantInfo.ID));
|
||||
(_, var dailyHistoric) = stream.Receive<HistoricResponse>();
|
||||
stream.Send(new HistoricRequest(HistoricInterval.Monthly, 36).ToCommandPacket(PlantInfo.ID));
|
||||
(_, var monthlyHistoric) = stream.Receive<HistoricResponse>();
|
||||
|
||||
var historic = new Historic
|
||||
(
|
||||
new HistoricEntries(minutelyHistoric, TimeSpan.FromMinutes(5)),
|
||||
new HistoricEntries(hourlyHistoric, TimeSpan.FromHours(1)),
|
||||
new HistoricEntries(dailyHistoric, TimeSpan.FromDays(1)),
|
||||
new HistoricEntries(monthlyHistoric, TimeSpan.FromDays(31))
|
||||
);
|
||||
Historic = historic;
|
||||
}
|
||||
}
|
||||
|
||||
protected void OnPropertyChanged([CallerMemberName] string propertyName = null)
|
||||
|
||||
Reference in New Issue
Block a user