-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ed1fe17
commit de8a32f
Showing
11 changed files
with
788 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 11.00 | ||
# Visual Studio 2010 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NetduinoGarageDoorOpener", "NetduinoGarageDoorOpener\NetduinoGarageDoorOpener.csproj", "{CFCB4443-0CFD-4AA7-92EE-291C70A205B9}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{CFCB4443-0CFD-4AA7-92EE-291C70A205B9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{CFCB4443-0CFD-4AA7-92EE-291C70A205B9}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{CFCB4443-0CFD-4AA7-92EE-291C70A205B9}.Debug|Any CPU.Deploy.0 = Debug|Any CPU | ||
{CFCB4443-0CFD-4AA7-92EE-291C70A205B9}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{CFCB4443-0CFD-4AA7-92EE-291C70A205B9}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{CFCB4443-0CFD-4AA7-92EE-291C70A205B9}.Release|Any CPU.Deploy.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
EndGlobal |
45 changes: 45 additions & 0 deletions
45
NetduinoGarageDoorOpener/NetduinoGarageDoorOpener/NetduinoGarageDoorOpener.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<AssemblyName>NetduinoGarageDoorOpener</AssemblyName> | ||
<OutputType>Exe</OutputType> | ||
<RootNamespace>NetduinoGarageDoorOpener</RootNamespace> | ||
<ProjectTypeGuids>{b69e3092-b931-443c-abe7-7e7b65f2a37f};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> | ||
<ProductVersion>9.0.21022</ProductVersion> | ||
<SchemaVersion>2.0</SchemaVersion> | ||
<ProjectGuid>{CFCB4443-0CFD-4AA7-92EE-291C70A205B9}</ProjectGuid> | ||
<TargetFrameworkVersion>v4.1</TargetFrameworkVersion> | ||
<NetMfTargetsBaseDir Condition="'$(NetMfTargetsBaseDir)'==''">$(MSBuildExtensionsPath32)\Microsoft\.NET Micro Framework\</NetMfTargetsBaseDir> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<Import Project="$(NetMfTargetsBaseDir)$(TargetFrameworkVersion)\CSharp.Targets" /> | ||
<ItemGroup> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
<Compile Include="Program.cs" /> | ||
<Compile Include="WebServer.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Reference Include="Microsoft.SPOT.Hardware" /> | ||
<Reference Include="Microsoft.SPOT.Native" /> | ||
<Reference Include="Microsoft.SPOT.Net" /> | ||
<Reference Include="SecretLabs.NETMF.Hardware" /> | ||
<Reference Include="SecretLabs.NETMF.Hardware.NetduinoPlus" /> | ||
<Reference Include="System" /> | ||
</ItemGroup> | ||
</Project> |
23 changes: 23 additions & 0 deletions
23
NetduinoGarageDoorOpener/NetduinoGarageDoorOpener/Program.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System; | ||
using System.Net; | ||
using System.Net.Sockets; | ||
using System.Threading; | ||
using Microsoft.SPOT; | ||
using Microsoft.SPOT.Hardware; | ||
using SecretLabs.NETMF.Hardware; | ||
using SecretLabs.NETMF.Hardware.NetduinoPlus; | ||
|
||
namespace NetduinoGarageDoorOpener | ||
{ | ||
public class Program | ||
{ | ||
public static void Main() | ||
{ | ||
Microsoft.SPOT.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()[0].EnableDhcp(); | ||
WebServer webServer = new WebServer(); | ||
webServer.ListenForRequest(); | ||
|
||
} | ||
|
||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
NetduinoGarageDoorOpener/NetduinoGarageDoorOpener/Properties/AssemblyInfo.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
|
||
// General Information about an assembly is controlled through the following | ||
// set of attributes. Change these attribute values to modify the information | ||
// associated with an assembly. | ||
[assembly: AssemblyTitle("NetduinoGarageDoorOpener")] | ||
[assembly: AssemblyDescription("")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("Microsoft")] | ||
[assembly: AssemblyProduct("NetduinoGarageDoorOpener")] | ||
[assembly: AssemblyCopyright("Copyright © Microsoft 2011")] | ||
[assembly: AssemblyTrademark("")] | ||
[assembly: AssemblyCulture("")] | ||
|
||
// Version information for an assembly consists of the following four values: | ||
// | ||
// Major Version | ||
// Minor Version | ||
// Build Number | ||
// Revision | ||
// | ||
[assembly: AssemblyVersion("1.0.0.0")] | ||
[assembly: AssemblyFileVersion("1.0.0.0")] |
101 changes: 101 additions & 0 deletions
101
NetduinoGarageDoorOpener/NetduinoGarageDoorOpener/WebServer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
using System; | ||
using Microsoft.SPOT; | ||
using System.Net.Sockets; | ||
using System.Net; | ||
using System.Threading; | ||
using System.Text; | ||
using Microsoft.SPOT.Hardware; | ||
using SecretLabs.NETMF.Hardware.NetduinoPlus; | ||
|
||
namespace NetduinoGarageDoorOpener | ||
{ | ||
public class WebServer : IDisposable | ||
{ | ||
private Socket socket = null; | ||
//open connection to onbaord led so we can blink it with every request | ||
private OutputPort led = new OutputPort(Pins.ONBOARD_LED, false); | ||
private OutputPort Garage2CarOpener = new OutputPort(Pins.GPIO_PIN_D13, false); | ||
|
||
public WebServer() | ||
{ | ||
//Initialize Socket class | ||
socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); | ||
//Request and bind to an IP from DHCP server | ||
socket.Bind(new IPEndPoint(IPAddress.Any, 80)); | ||
//Debug print our IP address | ||
Debug.Print(Microsoft.SPOT.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()[0].IPAddress); | ||
//Start listen for web requests | ||
socket.Listen(10); | ||
ListenForRequest(); | ||
} | ||
|
||
public void ListenForRequest() | ||
{ | ||
while (true) | ||
{ | ||
using (Socket clientSocket = socket.Accept()) | ||
{ | ||
//Get clients IP | ||
IPEndPoint clientIP = clientSocket.RemoteEndPoint as IPEndPoint; | ||
EndPoint clientEndPoint = clientSocket.RemoteEndPoint; | ||
//int byteCount = cSocket.Available; | ||
int bytesReceived = clientSocket.Available; | ||
if (bytesReceived > 0) | ||
{ | ||
//Get request | ||
byte[] buffer = new byte[bytesReceived]; | ||
int byteCount = clientSocket.Receive(buffer, bytesReceived, SocketFlags.None); | ||
string request = new string(Encoding.UTF8.GetChars(buffer)); | ||
string firstLine = request.Substring(0, request.IndexOf('\n')); //Example "GET /activatedoor HTTP/1.1" | ||
string[] words = firstLine.Split(' '); //Split line into words | ||
string command = string.Empty; | ||
if( words.Length > 2) | ||
{ | ||
string method = words[0]; //First word should be GET | ||
command = words[1].TrimStart('/'); //Second word is our command - remove the forward slash | ||
} | ||
switch (command.ToLower()) | ||
{ | ||
case "activatedoor": | ||
ActivateGarageDoor(); | ||
//Compose a response | ||
string response = "I just opened or closed the garage!"; | ||
string header = "HTTP/1.0 200 OK\r\nContent-Type: text; charset=utf-8\r\nContent-Length: " + response.Length.ToString() + "\r\nConnection: close\r\n\r\n"; | ||
clientSocket.Send(Encoding.UTF8.GetBytes(header), header.Length, SocketFlags.None); | ||
clientSocket.Send(Encoding.UTF8.GetBytes(response), response.Length, SocketFlags.None); | ||
break; | ||
default: | ||
//Did not recognize command | ||
response = "Bad command"; | ||
header = "HTTP/1.0 200 OK\r\nContent-Type: text; charset=utf-8\r\nContent-Length: " + response.Length.ToString() + "\r\nConnection: close\r\n\r\n"; | ||
clientSocket.Send(Encoding.UTF8.GetBytes(header), header.Length, SocketFlags.None); | ||
clientSocket.Send(Encoding.UTF8.GetBytes(response), response.Length, SocketFlags.None); | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
private void ActivateGarageDoor() | ||
{ | ||
led.Write(true); //Light on-board LED for visual cue | ||
Garage2CarOpener.Write(true); //"Push" garage door button | ||
Thread.Sleep(1000); //For 1 second | ||
led.Write(false); //Turn off on-board LED | ||
Garage2CarOpener.Write(false); //Turn off garage door button | ||
} | ||
#region IDisposable Members | ||
~WebServer() | ||
{ | ||
Dispose(); | ||
} | ||
public void Dispose() | ||
{ | ||
if (socket != null) | ||
socket.Close(); | ||
} | ||
#endregion | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 11.00 | ||
# Visual C# Express 2010 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TronDisc", "TronDisc\TronDisc.csproj", "{209B3EC6-E705-4A65-B438-EB4A45EF8299}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{209B3EC6-E705-4A65-B438-EB4A45EF8299}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{209B3EC6-E705-4A65-B438-EB4A45EF8299}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{209B3EC6-E705-4A65-B438-EB4A45EF8299}.Debug|Any CPU.Deploy.0 = Debug|Any CPU | ||
{209B3EC6-E705-4A65-B438-EB4A45EF8299}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{209B3EC6-E705-4A65-B438-EB4A45EF8299}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{209B3EC6-E705-4A65-B438-EB4A45EF8299}.Release|Any CPU.Deploy.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
EndGlobal |
Oops, something went wrong.