Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Monitor & Control your Garage Door with Android App


  • Please log in to reply
31 replies to this topic

#21 Greg Zimmers

Greg Zimmers

    Member

  • Members
  • PipPip
  • 11 posts
  • LocationBroomfield CO

Posted 21 January 2012 - 02:55 AM

Great job! I have implemented this and added email notifications. My next goal is to add some sort of authentication to prevent unauthorized access to my garage. I know the public IP and custom port are a deterrent, but I would feel better with some sort of password entry. I will let you know if/when I come up with something.


I actually built a two server solution for my house. I have the Netduino only visible inside the network without any authentication. Then on my IIS server (exposed externally) I built a RESTful webservice with authentication. My Android app talks to the webservice which talks to the Netduino.

My main purpose for the app was to provide peace of mind that the door was closed while away and to be able to close it remotely. It also comes in handy to be able to open the door for someone who needs entry while your away.

#22 av8rdude

av8rdude

    New Member

  • Members
  • Pip
  • 1 posts

Posted 05 March 2012 - 10:34 PM

Thanks for sharing your project! I'm trying to port forward and use this remotely. But I find that on port 80 it is sometimes responsive and sometimes not. If I switch to another port in the code it never seems to work. Everything works great internally on any port I choose. I'm confident in my firewall settings. Any ideas? TIA, Scott

#23 Buddy

Buddy

    Member

  • Members
  • PipPip
  • 17 posts

Posted 26 November 2012 - 04:53 PM

I posted this question up on Greg's blog, but figured I would ask here too (just trying to knock this out on my day off of work). :-) I have the new Netduino Plus 2 and it is running 4.2. Have setup the development platforms (micro framework and android) per the instructions. Used the code as is, except for two things. Changed the IP address and change the android platform to 3.2 (to support my Samsung Tab7.7). Loaded the code on the Netduino and Tab. The app appears on the Tab. When I tap the black box on the app, the progression circle spins. Using Ethereal I see the TCP traffic transmit from the Tab to the Netduino. Then I see Netduino response transmitted to the tab. The issue that I am having is that the "OPEN" graphic does not appear. I have built a few sensors and even tested them with a multimeter to see the sensor's output voltage in both hi and low states. So, I am assuming that the new MF4.2 on the Netduino is my problem and right now the porting kit isn't an option. Below is the code that I modified from your version to the 4.2. Please let me know if you think it is whacked and if so how would you write it? Thanks! //Set the analog pin to monitor Pin 0 // OLD lanuage -> InputPort garageSensor = new InputPort.AnalogPort(Pins.GPIO_PIN_A0); AnalogInput garageSensor = new Microsoft.SPOT.Hardware.AnalogInput(Cpu.AnalogChannel.ANALOG_0); //Set sensor range // old 4.1 code -> garageSensor.SetRange(0, 1024); garageSensor.Read(); //Program loop while (false) { Debug.Print(garageSensor.Read().ToString()); Thread.Sleep(1000); } }

#24 emg

emg

    Advanced Member

  • Members
  • PipPipPip
  • 129 posts

Posted 26 November 2012 - 06:43 PM

I think there are still unresolved issues with 4.2 ethernet on N+2, see other threads about MAC address and fixed IP/DHCP problems...

#25 Buddy

Buddy

    Member

  • Members
  • PipPip
  • 17 posts

Posted 27 November 2012 - 03:20 PM

I think there are still unresolved issues with 4.2 ethernet on N+2, see other threads about MAC address and fixed IP/DHCP problems...



I really would like that to be the case.
  • Yes, the wrong MAC is being used by the N+2 Ethernet interface (00:04:A3:00:00:00) in the DHCP request and to pass traffic; when I saw this I just assumed that the sticker was wrong. Now I know that is an issue with the device, but I am still obtaining an IP address.
  • Why I am able to ping the IP address across my network and see the N+2 link light blinking when performing an extended ping?
  • If this were a traffic routing issue, why is the N+2 responding to the Samsung request? Granted, the request could be filled with useless info...
  • Also, I ran a debug on the app last night and the N+2 did refect the sensor change of state (0 vs. 1).

I am a network guy by trade, so this code stuff is demanding a sharp learning curve. I changed the SetRange to a Read, that change was guess and I am wondering if it was a good guess. Also, now I wonder if the Android side requires a change to match the change on the N+2 code.

________________________________________________________________________________________________

Sensor Code:

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 NetduinoInfraredSensor
{
public class Program
{

public static void Main()
{
//Set the analog pin to monitor Pin 0
// OLD lanuage -> InputPort garageSensor = new InputPort.AnalogPort(Pins.GPIO_PIN_A0);
AnalogInput garageSensor = new Microsoft.SPOT.Hardware.AnalogInput(Cpu.AnalogChannel.ANALOG_0);

//Set sensor range
// old 4.1 code -> garageSensor.SetRange(0, 1024);
garageSensor.Read();

//Program loop
while (true)
{
Debug.Print(garageSensor.Read().ToString());
Thread.Sleep(1000);
}
}

________________________________________________________________________________________________

#26 emg

emg

    Advanced Member

  • Members
  • PipPipPip
  • 129 posts

Posted 27 November 2012 - 05:59 PM

Sorry, don't know the specifics of the issue(s) but your description seems to match others trouble-shooting attempts and results. I have a brand new N+2 still sitting in the box waiting for the firmware update that was due out last weekend. This is supposed to resolve this and SPI issues. Here's hoping... I would wait for the next firmware before changing any of your code and/or other devices.

#27 Buddy

Buddy

    Member

  • Members
  • PipPip
  • 17 posts

Posted 01 December 2012 - 01:47 PM

Yeah, so like the symptoms have changed with the new 4.2 release, but like I have spent a week trying to figure how this stuff like works and realize now that the way to fix it is with the rubber mallet in the garage.

#28 gfcwfzkm

gfcwfzkm

    Advanced Member

  • Members
  • PipPipPip
  • 52 posts
  • LocationBrig-Glis, Switzerland

Posted 03 December 2012 - 10:50 PM

Very nice stuff. I gona use it, to start my PC with my Netduino ;D But i go code the app on the Nokia N900 (awesome phone) -> Mono-Gtk ^^ mfg gfc

#29 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 13 December 2012 - 05:30 PM

Hi Buddy,

Yeah, so like the symptoms have changed with the new 4.2 release, but like I have spent a week trying to figure how this stuff like works and realize now that the way to fix it is with the rubber mallet in the garage.

Unfortunately rubber mallets aren't as soft and gentle as the word "rubber" would make one think.

What troubles are you experiencing? I'd like to see if we can help and get you up and running.

Chris

#30 shobana

shobana

    Member

  • Members
  • PipPip
  • 15 posts

Posted 11 April 2013 - 07:33 AM

hello greg , IMPORTANT

 

now i have problem with this coding i don know what wud be the reason, the program is for netduino v4.1 but m having netduino plus 2 v4.2, i upgraded the project version 4.1 to 4.2 if i run this program i get an ip called 192.168.1.4 but if i give this ip in the web browser no data is received from the device

i set the network cofiguration using MFDeploy with 192.168.1.4
subnet mask is 255.255.255.0
default gateway is 192.168.1.1
but dns primary i gave the default 8.8.8.8
dns secoundary 8.8.4.4
in my pc i use one lan for that it shows ip 192.168.1.7
for device in the output window it shows 192.168.1.4

but if i put in the web browser the page is not opening

this is the source code

weserver.cs

using System;
using System.Net.Sockets;
using System.Net;
using System.Threading;
using System.Text;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.Netduino;
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 OKrnContent-Type: text; charset=utf-8rnContent-Length: " + response.Length.ToString() + "rnConnection: closernrn";
  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 OKrnContent-Type: text; charset=utf-8rnContent-Length: " + response.Length.ToString() + "rnConnection: closernrn";
  //   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

  }
}

program.cs

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.Netduino;
namespace NetduinoGarageDoorOpener
{
  public class Program
  {
  public static void Main()
  {
  Microsoft.SPOT.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()[0].EnableDhcp();
  WebServer webServer = new WebServer();
  webServer.ListenForRequest();
  }
  }

}

 

http://netduinohacki...-with-your.html

 

 

in this link the code u hv given is not working i want to interface the app with neduino plus 2 tel me the solution in what network configuration changes to be done..



#31 iced98lx

iced98lx

    Advanced Member

  • Members
  • PipPipPip
  • 134 posts
  • LocationSouth Dakota

Posted 25 June 2013 - 07:30 PM

Greg - wanted to say thank you, your basic webserver example you used is being used on my reef controller project:

 

http://forums.netdui...ntroller/page-2

 

I appreciate how simple and strait forward it is.



#32 Buddy

Buddy

    Member

  • Members
  • PipPip
  • 17 posts

Posted 07 July 2013 - 01:10 PM

 

The release of 4.2.2 made the transferring of Greg's code easier for NOOBs. I've almost figured out this project, but I need to finish a few more pieces.

 

I can standup a standalone project with this code and it works for reading the output of a photo interrupter sensor (Photo Interrupter GP1A57HRJ00F https://www.sparkfun.com/products/9299).

namespace NetduinoApplication1{    public class Program    {        public static void Main()        {            const double maxVoltage = 3.3;            const int maxAdcValue = 4096; // 10-bit Resolution (ADC) change to 4096 for ND+2 as it is 12-bit            SecretLabs.NETMF.Hardware.AnalogInput garageSensor = new SecretLabs.NETMF.Hardware.AnalogInput(SecretLabs.NETMF.Hardware.NetduinoPlus.Pins.GPIO_PIN_A0);            while (true)            {                int rawValue = garageSensor.Read();                double value = (rawValue * maxVoltage) / maxAdcValue;                Debug.Print(rawValue + " " + value.ToString("f"));                Thread.Sleep(300);            }        }    }}

The sensor debug:

 

1 0.00

1 0.00

1 0.00

2 0.00

1004 0.81

1004 0.81

1003 0.81

1005 0.81

1 0.00

1 0.00

2 0.00

1 0.00

1005 0.81

1003 0.81

1004 0.81

1004 0.81

 

  • If the interrupter beam is blocked the reading is in the 1-3 range.
  • If the interrupter beam is not blocked the reading in in the 1000 range.
  • I am not sure what to do with the 0.00 or 0.81, since they are not needed.
  • The main issue is that I need to convert these output ranges (~1-3 and ~1000-1004) from an integer to text (Open or Closed). 

After converting them, this project requires pulling that text (Closed or Open) and placing it into the following line for the GET response. Right now, I have the text [color=rgb(178,34,34);]Closed [/color]manually populated and the an Droid app thinks the door is closed, so the green button on the app is active and the door can be opened or closed by pressing this button, but I have no idea if the door is really opened or closed.

 

Line 72-73 of solution:

string response1 = "Closed";

 

This pic is from when I manually entered Open, so the Droid Tablet thinks that the GET contains Open. Also notice that the red button is raised/enabled so I can click it to activate the garage door remote control.

 

 

 

I could be looking at this last piece wrong. Maybe I need to delete the string response1 line and insert the conversion somewhere else in this area (I bet there is more than one way to complete the task.)

                            case "checkdoor":                                IsGarageDoorOpen();                                //Compose a response                                string response1 = "Closed";  //Manually entering Closed or Open makes the Droid app happy enough to activate the garage door bottom, the problem with this approach is that the actual state of the garage door is not known.                                     string header1 = "HTTP/1.0 200 OKrnContent-Type: text; charset=utf-8rnContent-Length: " + response1.Length.ToString() + "rnConnection: closernrn";                                clientSocket.Send(Encoding.UTF8.GetBytes(header1), header1.Length, SocketFlags.None);                                clientSocket.Send(Encoding.UTF8.GetBytes(response1), response1.Length, SocketFlags.None);                                break;

So the challenge to convert the integer to text and then to populate the text in the GET response.

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_D9, 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 OKrnContent-Type: text; charset=utf-8rnContent-Length: " + response.Length.ToString() + "rnConnection: closernrn";                                clientSocket.Send(Encoding.UTF8.GetBytes(header), header.Length, SocketFlags.None);                                clientSocket.Send(Encoding.UTF8.GetBytes(response), response.Length, SocketFlags.None);                                break;                            case "checkdoor":                                IsGarageDoorOpen();                                //Compose a response                                string response1 = "Closed";  //Manually entering Closed or Open makes the Droid app happy enough to activate the garage door bottom, the problem with this approach is that the actual state of the garage door is not known.                                     string header1 = "HTTP/1.0 200 OKrnContent-Type: text; charset=utf-8rnContent-Length: " + response1.Length.ToString() + "rnConnection: closernrn";                                clientSocket.Send(Encoding.UTF8.GetBytes(header1), header1.Length, SocketFlags.None);                                clientSocket.Send(Encoding.UTF8.GetBytes(response1), response1.Length, SocketFlags.None);                                break;                            default:                                //Did not recognize command                                response = "Bad commando";                                header = "HTTP/1.0 200 OKrnContent-Type: text; charset=utf-8rnContent-Length: " + response.Length.ToString() + "rnConnection: closernrn";                                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                }        private void IsGarageDoorOpen()        {//keep, this works for reading                        const double maxVoltage = 3.3;//keep, this works for reading                        const int maxAdcValue = 4096; // 10-bit Resolution (ADC) change to 4096 for ND+2 as it is 12-bit//keep, this works for reading            //keep, this works for reading                        SecretLabs.NETMF.Hardware.AnalogInput garageSensor = new SecretLabs.NETMF.Hardware.AnalogInput(SecretLabs.NETMF.Hardware.NetduinoPlus.Pins.GPIO_PIN_A0);//keep, this works for reading            //keep, this works for reading                        while (true)//keep, this works for reading                        {//keep, this works for reading                            int rawValue = garageSensor.Read();//keep, this works for reading                            double value = (rawValue * maxVoltage) / maxAdcValue;//keep, this works for reading                            Debug.Print(rawValue + " " + value.ToString("f"));//keep, this works for reading                            Thread.Sleep(300);//keep, this works for reading                        }        }        #region IDisposable Members        ~WebServer()        {            Dispose();        }        public void Dispose()        {            if (socket != null)                socket.Close();        }        #endregion    }}

Dave VanderWekke, thanks for the AnalogInput code. http://forums.netdui...nput#entry47244 I used it as an update to Greg's original project.






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.