Skip to content

Commit

Permalink
Confirmed working under Docker on RP3 controlling Relay Plates. GPIO …
Browse files Browse the repository at this point in the history
…has yet to be confirmed, but should work.
  • Loading branch information
TWhidden committed Sep 23, 2018
1 parent 0aaa171 commit e7e2fd2
Show file tree
Hide file tree
Showing 19 changed files with 142 additions and 68 deletions.
7 changes: 7 additions & 0 deletions Docker/Client/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
echo "HOLIDAY SHOW CLIENT CORE"
echo "CONNECTING TO SERVER: $SERVER:$PORT"
echo "STORAGE PATH: $STORAGE"
echo "DEVICE ID: $DEVICEID"
echo "STARTING HOLIDAY SHOW CLIENT CORE..."
./HolidayShowClient.Core -s "$SERVER" -p $PORT -d $DEVICEID -a "$STORAGE"
File renamed without changes.
18 changes: 14 additions & 4 deletions HolidayShow.sln
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,23 @@ EndProject
Project("{E53339B2-1760-4266-BCC7-CA923CBCF16C}") = "docker-compose", "docker-compose.dcproj", "{9CBA41E6-BD68-4687-BE20-A41D0F231F7D}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "DockerScripts", "DockerScripts", "{46057768-9E98-4720-A0A5-D5053771E707}"
ProjectSection(SolutionItems) = preProject
client-entrypoint.sh = client-entrypoint.sh
server-entrypoint.sh = server-entrypoint.sh
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HolidayShowWeb", "HolidayShowWeb\HolidayShowWeb.csproj", "{E06AC049-69A0-4417-9A78-664661996853}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HolidayShowClient.Core", "HolidayShowClient.Core\HolidayShowClient.Core.csproj", "{45A4C0E8-1EAF-4491-B574-8B66AD897FF8}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HolidayShowLibShared.Core", "HolidayShowLibShared.Core\HolidayShowLibShared.Core.csproj", "{6B5D9B75-1AA4-4B12-93CF-2BC439F3ECB9}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Client", "Client", "{5CBC5C0C-5652-47CD-9EE4-2318C9E6CB27}"
ProjectSection(SolutionItems) = preProject
Docker\Client\entrypoint.sh = Docker\Client\entrypoint.sh
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Server", "Server", "{0D2BC627-1638-4ED3-8FFA-0D594141FAAD}"
ProjectSection(SolutionItems) = preProject
Docker\Server\entrypoint.sh = Docker\Server\entrypoint.sh
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -715,6 +721,10 @@ Global
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{5CBC5C0C-5652-47CD-9EE4-2318C9E6CB27} = {46057768-9E98-4720-A0A5-D5053771E707}
{0D2BC627-1638-4ED3-8FFA-0D594141FAAD} = {46057768-9E98-4720-A0A5-D5053771E707}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {6319B629-8641-4CF8-ACB8-E5BF1D344FA9}
EndGlobalSection
Expand Down
49 changes: 49 additions & 0 deletions HolidayShowClient.Core/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
FROM arm32v7/ubuntu:bionic AS base
WORKDIR /app

#Default Container Port 5555 will be used.
ARG DEFAULTPORT=5555
ARG DEFAULTSTORAGE='/Data'

EXPOSE $DEFAULTPORT

ENV DEVICEID=
ENV SERVER=
ENV PORT=$DEFAULTPORT
ENV STORAGE=$DEFAULTSTORAGE
ENV PORT=$DEFAULTPORT
ENV DOTNET_RUNNING_IN_CONTAINER=true

ENV TZ=America/Los_Angeles
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

FROM microsoft/dotnet:2.1-sdk AS build
WORKDIR /src

#Copy base projects because we use project links
COPY . .

WORKDIR /src/HolidayShowClient.Core

FROM build AS publish
RUN dotnet publish -r linux-arm -c Release -o /app HolidayShowClient.Core.csproj

FROM base AS final
WORKDIR /app
COPY --from=publish /app .
COPY /Docker/Client/entrypoint.sh .

#Copy some required assemblies to the base directory
#two different C++ libs use these. They have a different lib signature
#so bringing them both over.
WORKDIR /usr/lib
COPY /References/libwiringPi.so .
COPY /References/libwiringPi.so.2.46 .

WORKDIR /app

#QT is required for the relay plate - this is a big dependancy, and the library should later be staticly linked.
RUN apt-get update && \
apt-get install -y liblttng-ust0 libcurl3 libssl1.0.0 libkrb5-3 zlib1g libicu60 qt5-default

ENTRYPOINT ["/app/entrypoint.sh"]
2 changes: 1 addition & 1 deletion HolidayShowClient.Core/HolidayShowClient.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

<ItemGroup>
<Reference Include="PiRelayPlate.NetCore">
<HintPath>\\10.64.128.36\dev\GitHub-PiPlateRelay\PiPlateRelay\src\netcore\PiRelayPlate.NetCore\bin\Debug\netcoreapp2.1\PiRelayPlate.NetCore.dll</HintPath>
<HintPath>..\References\PiRelayPlate.NetCore.dll</HintPath>
</Reference>
</ItemGroup>

Expand Down
63 changes: 35 additions & 28 deletions HolidayShowClient.Core/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ static void Main(string[] args)

private async static Task Load()
{
Console.WriteLine("Loading...");
_availablePins = new List<OutletControl>();

// Identify if the device has a PiPlate attached.
Expand All @@ -125,16 +126,26 @@ private async static Task Load()
#endif

#if CORE
var relaysAvailable = PiRelayPlate.NetCore.RelayPlate.RelaysAvailable();
if (relaysAvailable > 0)
int relaysAvailable = 0;
Console.WriteLine("Finding what Relays are Available...");
try
{
// build up the ports
var portsAvailable = relaysAvailable * 7;
for (byte portIndex = 1; portIndex <= portsAvailable; portIndex++)
relaysAvailable = PiRelayPlate.NetCore.RelayPlate.RelaysAvailable();
Console.WriteLine($"Relays Found: {relaysAvailable}");
if (relaysAvailable > 0)
{
_availablePins.Add(new OutletControl(portIndex));
// build up the ports
var portsAvailable = relaysAvailable * 7;
for (byte portIndex = 1; portIndex <= portsAvailable; portIndex++)
{
_availablePins.Add(new OutletControl(portIndex));
}
}
}
catch (Exception ex)
{
Console.WriteLine($"Could not load pi relays. Error: {ex.Message}");
}
#else
if (PiPlateRelay.PiRelay.RelaysAvailable.Count > 0)
{
Expand All @@ -148,9 +159,9 @@ private async static Task Load()
}
#endif

else
if(relaysAvailable == 0)
{

Console.WriteLine("Loading GPIO Instance");
// Identify the pings available.
// Get the default GPIO controller on the system
#if CORE
Expand All @@ -160,7 +171,10 @@ private async static Task Load()
#endif

if (gpio == null)
return; // GPIO not available on this system
{
Console.WriteLine("No detected GPIO - Cant do anything :(");
return;
}; // GPIO not available on this system

// Reference: https://ms-iot.github.io/content/en-US/win10/samples/PinMappingsRPi2.htm
//Pin Added #4 - Gpio#: 4
Expand Down Expand Up @@ -195,18 +209,6 @@ private async static Task Load()
pin.PinMode = GpioPinDriveMode.Output;
pin.Write(GpioPinValue.Low);
_availablePins.Add(new OutletControl(pin)); // This is a pin we can use.

//GpioOpenStatus status;
//if (!gpio.TryOpenPin(i, GpioSharingMode.Exclusive, out GpioPin pin, out status)) continue;
//if (blockedIds.Contains(pin.PinNumber)) continue; // Dont process blocked pins.

//var supportsOutputMode = pin.IsDriveModeSupported(GpioPinDriveMode.Output);
//if (!supportsOutputMode) continue;
//_availablePins.Add(new OutletControl(pin)); // This is a pin we can use.
//pin.SetDriveMode(GpioPinDriveMode.Output); // We need this set to Output
//pin.Write(GpioPinValue.Low); // Init with a low value.
//pin.DebounceTimeout = TimeSpan.Zero; // Not all GPIO pins have this value set.
//Debug.WriteLine("Pin Added #{0} - Gpio#: {1}", i, pin.PinNumber);
}
}

Expand All @@ -215,21 +217,26 @@ private async static Task Load()

private static void CreateClient()
{
Console.WriteLine("Creating Client to connect");

DestroyClient();

if (DeviceId != 0)
{
var endPoint = new DnsEndPoint(ServerAddress, ServerPort);
var serverDetails = ResloverService.Resolve<ServerDetails>(endPoint);
ResloverService.Register<IServerDetails, IServerDetails>(serverDetails);
if (DeviceId == 0) return;

_protocolClient = ResloverService.Resolve<ClientLiveControl>(DeviceId, _availablePins);
}
var endPoint = new DnsEndPoint(ServerAddress, ServerPort);
Console.WriteLine($"Connecting to {endPoint.Host}:{endPoint.Port}");
var serverDetails = ResloverService.Resolve<ServerDetails>(endPoint);
ResloverService.Register<IServerDetails, IServerDetails>(serverDetails);

Console.WriteLine("Starting TCP Client");
_protocolClient = ResloverService.Resolve<ClientLiveControl>(DeviceId, _availablePins);
Console.WriteLine("Client Started.");

}

private static void DestroyClient()
{
Console.WriteLine("Destroying any existing client...");
_protocolClient?.Disconnect(false);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public async void PlayMediaUri(IAudioRequestController c, Uri uri)
_externalPlayerProcess = new Process()
{
StartInfo = new ProcessStartInfo("play", uri.AbsolutePath),


};
var result = _externalPlayerProcess.Start();
Expand Down Expand Up @@ -57,6 +58,8 @@ public void SetMediaElement(MediaElement mediaElement)

public async void StopPlayback()
{
Console.WriteLine($"StopPlayback() called for {_currentRequest.FileName}");

#if CORE
_externalPlayerProcess?.Close();
_externalPlayerProcess?.Dispose();
Expand Down
21 changes: 4 additions & 17 deletions HolidayShowServer.Core/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,18 @@ RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
FROM microsoft/dotnet:2.1-sdk AS build
WORKDIR /src

#Copy base projects because we use project links
COPY HolidayShowServer/HolidayShowServer.csproj HolidayShowServer/
COPY HolidayShowServer.Core/HolidayShowServer.Core.csproj HolidayShowServer.Core/

#Copy base projects because we use project links
COPY HolidayShowLib/HolidayShowLib.csproj HolidayShowLib/
COPY HolidayShowLib.Core/HolidayShowLib.Core.csproj HolidayShowLib.Core/

#Copy base projects because we use project links
COPY HolidayShow.Data/HolidayShow.Data.csproj HolidayShow.Data/
COPY HolidayShow.Data.Core/HolidayShow.Data.Core.csproj HolidayShow.Data.Core/

RUN dotnet restore HolidayShowServer.Core/HolidayShowServer.Core.csproj
COPY . .

WORKDIR /src/HolidayShowServer.Core
RUN dotnet build HolidayShowServer.Core.csproj -c ReleaseCore -o /app

FROM build AS publish
RUN dotnet publish HolidayShowServer.Core.csproj -c ReleaseCore -o /app
RUN dotnet publish HolidayShowServer.Core.csproj -c Release -o /app

FROM base AS final
WORKDIR /app
COPY --from=publish /app .
COPY server-entrypoint.sh .
COPY /Docker/Server/entrypoint.sh .

ENTRYPOINT ["/app/server-entrypoint.sh"]
ENTRYPOINT ["/app/entrypoint.sh"]


6 changes: 4 additions & 2 deletions HolidayShowServer.Core/HolidayShowServer.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
<Authors>Travis Whidden</Authors>
<Company>None</Company>
<AssemblyName>holidayshowserver.core</AssemblyName>
<AssemblyVersion>1.18.0805.0</AssemblyVersion>
<FileVersion>1.18.0721.0</FileVersion>
<AssemblyVersion>2.18.0917.0</AssemblyVersion>
<FileVersion>2.18.0917.0</FileVersion>
<Configurations>Debug;Release;ReleaseCore</Configurations>
<Version>2.18.0917</Version>
<PackageReleaseNotes>Reduced Database calls to reduce CPU. Code cleanup</PackageReleaseNotes>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion HolidayShowServer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ private static async void RunServer()
{
if (instructionState is DeviceInstructions item)
{
LogMessage("Sending Instruction: " + item.ToString());
//LogMessage("Sending Instruction: " + item.ToString());
SendInstruction(item);
}
Expand Down
2 changes: 1 addition & 1 deletion HolidayShowWeb/Controllers/DeviceIoPortsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public async Task<IActionResult> GetDeviceIoPortsByDeviceId([FromRoute] int devi
return BadRequest(ModelState);
}

var deviceIoPorts = await _context.DeviceIoPorts.Where(x => x.DeviceId == deviceId).ToListAsync();
var deviceIoPorts = await _context.DeviceIoPorts.Where(x => x.DeviceId == deviceId).OrderBy(x => x.CommandPin).ToListAsync();

if (deviceIoPorts == null)
{
Expand Down
Binary file added References/PiRelayPlate.NetCore.dll
Binary file not shown.
Binary file added References/libwiringPi.so
Binary file not shown.
Binary file added References/libwiringPi.so.2.46
Binary file not shown.
8 changes: 0 additions & 8 deletions client-entrypoint.sh

This file was deleted.

1 change: 1 addition & 0 deletions docker-compose-client.override.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
version: '3.4'
8 changes: 8 additions & 0 deletions docker-compose-client.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: '3.4'

services:
holidayshowserver.core:
image: ${DOCKER_REGISTRY}HolidayShowClient.Core
build:
context: .
dockerfile: HolidayShowClient.Core/Dockerfile
7 changes: 4 additions & 3 deletions docker-compose.dcproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@
<ProjectGuid>9cba41e6-bd68-4687-be20-a41d0f231f7d</ProjectGuid>
</PropertyGroup>
<ItemGroup>
<None Include="docker-compose.override.yml">
<DependentUpon>docker-compose.yml</DependentUpon>
<None Include="docker-compose-client.override.yml">
<DependentUpon>docker-compose-client.yml</DependentUpon>
</None>
<None Include="docker-compose.yml" />
<None Include="docker-compose-client.yml" />
<None Include=".dockerignore" />
<None Include="docker-compose.yml" />
</ItemGroup>
</Project>
13 changes: 10 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
version: '3.4'

services:
holidayshowserver.core:
image: ${DOCKER_REGISTRY}holidayshowservercore
HolidayShowClient:
image: holidayshowclient
build:
context: .
dockerfile: HolidayShowServer.Core/Dockerfile
dockerfile: HolidayShowClient.Core/Dockerfile


HolidayShowServer:
image: holidayshowserver
build:
context: .
dockerfile: HolidayShowServer.Core/Dockerfile

0 comments on commit e7e2fd2

Please sign in to comment.