Exemplo n.º 1
0
        void ethernet_NetworkUp(GTM.Module.NetworkModule sender, GTM.Module.NetworkModule.NetworkState state)
        {
            Debug.Print("Network is Up with following properties");
            Debug.Print("IP:" + ethernetJ11D.NetworkSettings.IPAddress.ToString());

            Gadgeteer.Networking.WebServer.StartLocalServer(ethernetJ11D.NetworkSettings.IPAddress, 80);

            foreach (string s in sender.NetworkSettings.DnsAddresses)
            {
                Debug.Print("Dns:" + s);
            }

            var NetworkSettings = ethernetJ11D.NetworkSettings;

            Debug.Print("IP Address: " + NetworkSettings.IPAddress);
            Debug.Print("Subnet Mask: " + NetworkSettings.SubnetMask);
            Debug.Print("Gateway: " + NetworkSettings.GatewayAddress);

            test = Gadgeteer.Networking.WebServer.SetupWebEvent("test");
            test.WebEventReceived += new WebEvent.ReceivedWebEventHandler(test_WebEventReceived);

            seePicture = Gadgeteer.Networking.WebServer.SetupWebEvent("seepicture");
            seePicture.WebEventReceived += new WebEvent.ReceivedWebEventHandler(seePicture_WebEventReceived);

            button.TurnLedOn();
        }
Exemplo n.º 2
0
        void ethernet_J11D_NetworkUp(GTM.Module.NetworkModule sender, GTM.Module.NetworkModule.NetworkState state)
        {
            Debug.Print("Network up!");
            Debug.Print("IP Address: " + ethernet_J11D.NetworkSettings.IPAddress.ToString());

            // Configure TimeService settings.
            TimeServiceSettings settings = new TimeServiceSettings();
            settings.ForceSyncAtWakeUp = true;
            settings.RefreshTime = 1800;    // in seconds.

            IPAddress[] address = Dns.GetHostEntry("ntp.nasa.gov").AddressList;
            if (address != null && address.Length > 0)
                settings.PrimaryServer = address[0].GetAddressBytes();

            address = Dns.GetHostEntry("pool.ntp.org").AddressList;
            if (address != null && address.Length > 0)
                settings.AlternateServer = address[0].GetAddressBytes();

            TimeService.Settings = settings;
            TimeService.Start();

            WebServer.StartLocalServer(ethernet_J11D.NetworkSettings.IPAddress.ToString(), 80);
            GetReading = WebServer.SetupWebEvent("getreading");
            GetReading.WebEventReceived += new WebEvent.ReceivedWebEventHandler(GetReading_WebEventReceived);

            GetLog = WebServer.SetupWebEvent("getlog");
            GetLog.WebEventReceived += new WebEvent.ReceivedWebEventHandler(GetLog_WebEventReceived);

            ClearLog = WebServer.SetupWebEvent("clearlog");
            ClearLog.WebEventReceived += new WebEvent.ReceivedWebEventHandler(ClearLog_WebEventReceived);

            temperatureHumidity.RequestMeasurement();
        }
Exemplo n.º 3
0
        void ethernet_NetworkUp(GTM.Module.NetworkModule sender,
                              GTM.Module.NetworkModule.NetworkState state)
        {
            Debug.Print("Connected to network.");
            Debug.Print("IP address: " + ethernet.NetworkSettings.IPAddress);
            string ipAddress = ethernet.NetworkSettings.IPAddress;
            systemip = ipAddress;
            WebServer.StartLocalServer(ipAddress, 80);
            display.SimpleGraphics.Clear();
            SetupWindow("Climate Control Monitor", 10);
            SetupWindow("Enter this into PC application:", 50);
            RedSetupWindow(systemip, 70);
            SetupWindow("Please use the user guide to help you", 90);
            SetupWindow("Access this device online at: ",130);
            RedSetupWindow(systemip + "/view", 150);

            webEventtemperature = WebServer.SetupWebEvent("gettemp");
            webEventtemperature.WebEventReceived += new WebEvent.ReceivedWebEventHandler(webEventtemperature_WebEventReceived);

            webEventhumidity = WebServer.SetupWebEvent("gethumid");
            webEventhumidity.WebEventReceived += new WebEvent.ReceivedWebEventHandler(webEventhumidity_WebEventReceived);

            webEventlight = WebServer.SetupWebEvent("getlight");
            webEventlight.WebEventReceived += new WebEvent.ReceivedWebEventHandler(webEventlight_WebEventReceived);
            authentication = WebServer.SetupWebEvent("authenticate");
            authentication.WebEventReceived += new WebEvent.ReceivedWebEventHandler(authenticatesystem_WebEventReceived);
            view = WebServer.SetupWebEvent("view");
            view.WebEventReceived += new WebEvent.ReceivedWebEventHandler(view_WebEventReceived);

            Debug.Print("web event setup success");
        }
Exemplo n.º 4
0
 void ethernet_NetworkUp(GTM.Module.NetworkModule sender, GTM.Module.NetworkModule.NetworkState state)
 {
     led.TurnGreen();
     string ipAddress = ethernet.NetworkSettings.IPAddress;
     WebServer.StartLocalServer(ipAddress, 80);
     sayHello = WebServer.SetupWebEvent("hello");
     sayHello.WebEventReceived += new WebEvent.ReceivedWebEventHandler(sayHello_WebEventReceived);
 }
Exemplo n.º 5
0
 /// <summary>
 /// An event which is fired when the network is up, turns the status led blue, starts a http server operation on port 80
 /// Creates the web event bio, acessed via http://192.168.1.22:80/bio and its response handler 
 /// </summary>
 /// <param name="sender">The network module that fired the event</param>
 /// <param name="state">The state the network module was in</param>
 void ethernet_NetworkUp(GTM.Module.NetworkModule sender, GTM.Module.NetworkModule.NetworkState state)
 {
     led.TurnBlue();
     WebServer.StartLocalServer(ethernet.NetworkSettings.IPAddress, 80);
     //http://192.168.1.22:80/bio
     SendBioFeedback = WebServer.SetupWebEvent("bio");
     SendBioFeedback.WebEventReceived += new WebEvent.ReceivedWebEventHandler(SendBioFeedback_WebEventReceived);
 }
Exemplo n.º 6
0
 /// <summary>
 /// Adds a new web event to the server.
 /// </summary>
 /// <param name="webEvent">The web event and corresponding data that the server will handle.</param>
 /// <returns>A Boolean value that indicates whether the <see cref="WebEvent"/> could be added, <b>true</b> if added,
 /// <b>false</b>, if webEvent already exists. </returns>
 internal bool AddWebEvent(WebEvent webEvent)
 {
     if (!WebEvents.Contains(webEvent.GetWebEventId()))
     {
         WebEvents.Add(webEvent.GetWebEventId(), webEvent);
         return(true);
     }
     return(false);
 }
Exemplo n.º 7
0
        void ethernet_NetworkUp(GTM.Module.NetworkModule sender, GTM.Module.NetworkModule.NetworkState state)
        {
            led.TurnGreen();
            string ipAddress = ethernet.NetworkSettings.IPAddress;

            WebServer.StartLocalServer(ipAddress, 80);
            sayHello = WebServer.SetupWebEvent("hello");
            sayHello.WebEventReceived += new WebEvent.ReceivedWebEventHandler(sayHello_WebEventReceived);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Creates a path on the server so that an http GET request can be processed.
        /// Specifies a path of the form: http://{IP}:{port}/{path}.
        /// </summary>
        /// <param name="path">The path used to identify a resource.</param>
        /// <returns>A <see cref="T:GTM.NetworkModule.WebEvent"/> object that is used to update data and respond to incoming requests.
        /// </returns>
        public static WebEvent SetupWebEvent(string path)
        {
            WebEvent webEvent = WebServerManager.GetInstance().GetWebEventById(path);

            if (webEvent == null)
            {
                webEvent = new WebEvent(path);
            }
            return(webEvent);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Stops and removes the given <see cref="WebEvent"/>.
        /// </summary>
        /// <param name="webEvent">The <see cref="WebEvent"/> to stop.</param>
        /// <returns>Returns <b>true</b> if the <see cref="WebEvent"/> exists and can be removed, <b>false</b> if <see cref="WebEvent"/>
        /// does not exist or cannot be stopped.</returns>
        public bool Stop(WebEvent webEvent)
        {
            if (WebEvents.Contains(webEvent.GetWebEventId()))
            {
                WebEvents.Remove(webEvent.GetWebEventId());
                return(true);
            }

            // Debug.Print("Service not found");
            return(false);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Creates a path to a resource on the server so that a http GET requests can be processed.
        /// Specifies the path of the form: http://{IP}:{port}/{path}.
        /// </summary>
        /// <param name="path">The path used to identify a resource.</param>
        /// <param name="refreshAfter">Specifies the refresh interval in seconds.</param>
        /// <returns>A <see cref="WebEvent"/> object that is used to update data and respond to incoming requests.
        /// </returns>
        public static WebEvent SetupWebEvent(string path, uint refreshAfter)
        {
            WebEvent webEvent = WebServerManager.GetInstance().GetWebEventById(path);

            if (webEvent == null)
            {
                webEvent = new WebEvent(path);
            }
            webEvent.refreshAfter = refreshAfter;
            return(webEvent);
        }
Exemplo n.º 11
0
        void ethernet_NetworkUp(GTM.Module.NetworkModule sender, GTM.Module.NetworkModule.NetworkState state)
        {
            string ipaddress = ethernetJ11D.NetworkSettings.IPAddress;

            Debug.Print("IP:" + ipaddress.ToString());
            Gadgeteer.Networking.WebServer.StartLocalServer(ipaddress, 80);
            //foreach (string s in sender.NetworkSettings.DnsAddresses)
            //    Debug.Print("Dns:" + s);

            takePicture = Gadgeteer.Networking.WebServer.SetupWebEvent("takepicture");
            takePicture.WebEventReceived += new WebEvent.ReceivedWebEventHandler(takePicture_WebEventReceived);
        }
Exemplo n.º 12
0
        void ethernet_NetworkUp(GTM.Module.NetworkModule sender, GTM.Module.NetworkModule.NetworkState state)
        {
            Debug.Print("IP:" + ethernet.NetworkSettings.IPAddress.ToString());

            Gadgeteer.Networking.WebServer.StartLocalServer(ethernet.NetworkSettings.IPAddress, 80);

            foreach (string s in sender.NetworkSettings.DnsAddresses)
                Debug.Print("Dns:" + s);

            hello = Gadgeteer.Networking.WebServer.SetupWebEvent("hello");
            hello.WebEventReceived += new WebEvent.ReceivedWebEventHandler(hello_WebEventReceived);

            takePicture = Gadgeteer.Networking.WebServer.SetupWebEvent("takepicture");
            takePicture.WebEventReceived += new WebEvent.ReceivedWebEventHandler(takePicture_WebEventReceived);

            seePicture = Gadgeteer.Networking.WebServer.SetupWebEvent("seepicture");
            seePicture.WebEventReceived += new WebEvent.ReceivedWebEventHandler(seePicture_WebEventReceived);
        }
Exemplo n.º 13
0
        void ethernet_NetworkUp(GTM.Module.NetworkModule sender, GTM.Module.NetworkModule.NetworkState state)
        {
            Debug.Print("IP:" + ethernet.NetworkSettings.IPAddress.ToString());

            Gadgeteer.Networking.WebServer.StartLocalServer(ethernet.NetworkSettings.IPAddress, 80);

            foreach (string s in sender.NetworkSettings.DnsAddresses)
            {
                Debug.Print("Dns:" + s);
            }

            hello = Gadgeteer.Networking.WebServer.SetupWebEvent("hello");
            hello.WebEventReceived += new WebEvent.ReceivedWebEventHandler(hello_WebEventReceived);

            takePicture = Gadgeteer.Networking.WebServer.SetupWebEvent("takepicture");
            takePicture.WebEventReceived += new WebEvent.ReceivedWebEventHandler(takePicture_WebEventReceived);

            seePicture = Gadgeteer.Networking.WebServer.SetupWebEvent("seepicture");
            seePicture.WebEventReceived += new WebEvent.ReceivedWebEventHandler(seePicture_WebEventReceived);
        }
Exemplo n.º 14
0
        /// <summary>
        /// Stops and removes the given <see cref="WebEvent"/>.
        /// </summary>
        /// <param name="webEvent">The <see cref="WebEvent"/> to stop.</param>
        /// <returns>Returns <b>true</b> if the <see cref="WebEvent"/> exists and can be removed, <b>false</b> if <see cref="WebEvent"/>
        /// does not exist or cannot be stopped.</returns>
        public bool Stop(WebEvent webEvent)
        {
            if (WebEvents.Contains(webEvent.GetWebEventId()))
            {
                WebEvents.Remove(webEvent.GetWebEventId());
                return true;
            }

            // Debug.Print("Service not found");
            return false;
        }
Exemplo n.º 15
0
        /// <summary>
        /// Creates a path to a resource on the server so that a http GET requests can be processed.
        /// Specifies the path of the form: http://{IP}:{port}/{path}.
        /// </summary>
        /// <param name="path">The path used to identify a resource.</param>
        /// <param name="refreshAfter">Specifies the refresh interval in seconds.</param>
        /// <returns>A <see cref="WebEvent"/> object that is used to update data and respond to incoming requests.
        /// </returns>
        public static WebEvent SetupWebEvent(string path, uint refreshAfter)
        {
            WebEvent webEvent = WebServerManager.GetInstance().GetWebEventById(path);

            if (webEvent == null)
            {
                webEvent = new WebEvent(path);
            }
            webEvent.refreshAfter = refreshAfter;
            return webEvent;
        }
Exemplo n.º 16
0
            /// <summary>
            /// Processes incoming requests
            /// </summary>
            protected void ProcessRequest()
            {
                // accept an incoming connection request and once we have one, spawn a new thread to accept more
                bool newThread = false;

                System.Net.Sockets.Socket clientSocket = null;
                Responder responder = null;

                while (IsRunning && !newThread)
                {
                    try
                    {
                        // process incoming request
                        clientSocket = LocalServer.Accept();
                        clientSocket.ReceiveTimeout = Timeout;
                        clientSocket.SendTimeout    = Timeout;

                        // parse message an create an object containing parsed data
                        responder = new Responder();
                        responder.ClientEndpoint = clientSocket.RemoteEndPoint.ToString();
                        responder.ClientSocket   = clientSocket;

                        Thread t = new Thread(new ThreadStart(ProcessRequest));
                        t.Start();
                        newThread = true;
                    }
                    catch
                    {
                        if (clientSocket != null)
                        {
                            try
                            {
                                clientSocket.Close();
                            }
                            catch { }
                        }
                    }
                }

                // now process the request
                try
                {
                    bool finishedParsing = false;

                    TimeSpan parseStart = Timer.GetMachineTime();

                    while (!finishedParsing)
                    {
                        if (Timer.GetMachineTime() - parseStart > MaxProcessingTime)
                        {
                            return;
                        }

                        // receiving data, add to an array to process later
                        byte[] buffer = new byte[clientSocket.Available];
                        clientSocket.Receive(buffer);

                        finishedParsing = responder.parse(buffer);
                    }

                    // trigger event to get response
                    WebEvent webevent = null;

                    if (responder.Path != null && responder.Path.Length > 1)
                    {
                        webevent = serverManager.GetWebEventById(responder.Path);
                    }

                    if (webevent == null)
                    {
                        webevent = serverManager.DefaultEvent;
                    }

                    responder.webEvent = webevent;

                    webevent.OnWebEventReceived(responder.Path, responder.HttpMethod, responder);
                }
                catch
                {
                }
            }
Exemplo n.º 17
0
 ///<summary>
 /// Stops and removes a single resource. If the resource is requesterd again, the server will return the default page. 
 ///</summary>
 ///<param name="webEvent">The <see cref="WebEvent"/> to be stopped</param>
 ///<returns>The result of the operation, <b>true</b> if the resource is found and removed, otherwise <b>false</b>.</returns>
 public static bool DisableWebEvent(WebEvent webEvent)
 {
     return WebServerManager.GetInstance().Stop(webEvent);
 }
Exemplo n.º 18
0
        /// <summary>
        /// Creates a path on the server so that an http GET request can be processed.
        /// Specifies a path of the form: http://{IP}:{port}/{path}.
        /// </summary>
        /// <param name="path">The path used to identify a resource.</param>
        /// <returns>A <see cref="T:GTM.NetworkModule.WebEvent"/> object that is used to update data and respond to incoming requests.
        /// </returns>
        public static WebEvent SetupWebEvent(string path)
        {
            WebEvent webEvent = WebServerManager.GetInstance().GetWebEventById(path);

            if (webEvent == null)
            {
                webEvent = new WebEvent(path);
            }
            return webEvent;
        }
Exemplo n.º 19
0
        /// <summary>
        /// Adds a new web event to the server.
        /// </summary>
        /// <param name="webEvent">The web event and corresponding data that the server will handle.</param>
        /// <returns>A Boolean value that indicates whether the <see cref="WebEvent"/> could be added, <b>true</b> if added, 
        /// <b>false</b>, if webEvent already exists. </returns>
        internal bool AddWebEvent(WebEvent webEvent)
        {

            if (!WebEvents.Contains(webEvent.GetWebEventId()))
            {
                WebEvents.Add(webEvent.GetWebEventId(), webEvent);
                return true;
            }
            return false;
        }
Exemplo n.º 20
0
 ///<summary>
 /// Stops and removes a single resource. If the resource is requesterd again, the server will return the default page.
 ///</summary>
 ///<param name="webEvent">The <see cref="WebEvent"/> to be stopped</param>
 ///<returns>The result of the operation, <b>true</b> if the resource is found and removed, otherwise <b>false</b>.</returns>
 public static bool DisableWebEvent(WebEvent webEvent)
 {
     return(WebServerManager.GetInstance().Stop(webEvent));
 }