예제 #1
0
        //private static byte[] RetiraHeaderWebService(byte[] receive)
        //{
        //    //<string
        //    var endOfHeader = new byte[] { 60, 115, 116, 114, 105, 110, 103 };
        //    byte[] responseHeaderRaw;

        //    var headerEnd = FindArray(endOfHeader, receive);

        //    if (headerEnd != -1)
        //    {
        //        // Copy data from header
        //        responseHeaderRaw = new byte[headerEnd];
        //        Array.Copy(receive, responseHeaderRaw, responseHeaderRaw.Length);

        //        // Strip header from response
        //        var responseTemp = new byte[receive.Length - headerEnd];
        //        Array.Copy(receive, headerEnd, responseTemp, 0, responseTemp.Length);
        //        receive = responseTemp;
        //    }

        //    return receive;
        //}

        public static void WebPost(string url, string referer,
                                   string extraHeaders, string requestMethod,
                                   string postContentType, string postBody)
        {
            //Trata Url
            url = url.Substring(7);

            string destIp = "184.172.63.50";

            try
            {
                //Realiza conexão com o socket
                EthernetW5100.ConnectTCP(destIp, 80);
                System.Threading.Thread.Sleep(1000); //1 segundos

                //Constroi o Header da mensagem
                var request = BuscaHeader(url, referer, extraHeaders, requestMethod, postContentType, postBody);

                //Envia requisição
                EthernetW5100.Send(request);

                //Aguarda os dados
                var timeoutInicial = DateTime.Now.AddSeconds(30);
                while (EthernetW5100.Available <= 0 && DateTime.Now < timeoutInicial)
                {
                    System.Threading.Thread.Sleep(500); //0,5 segundo
                }
            }
            finally
            {
                try
                {
                    //Desconecta o socket
                    EthernetW5100.Disconnect();
                }
                catch (Exception) { }
            }
        }
예제 #2
0
        public static bool Ping(string ipDestino)
        {
            var retorno = false;

            try
            {
                //Realiza conexão com o socket
                EthernetW5100.ConnectTCP(ipDestino, 80);
                System.Threading.Thread.Sleep(1000); //1 segundos

                retorno = true;
            }
            finally
            {
                try
                {
                    //Desconecta o socket
                    EthernetW5100.Disconnect();
                }
                catch (Exception) { }
            }

            return(retorno);
        }
예제 #3
0
        public static void Main()
        {
            //Acende Led principal
            var ledPrincipal = new FEZ_Components.LED(FEZ_Pin.Digital.LED);

            ledPrincipal.TurnOn();

            PersistentStorage wrkSd = null;

            try
            {
                //Inicia relés / saidas digitais
                var wrkSaidas = new Saidas();

                //Monta diretórios do Cartão SD
                wrkSd = new PersistentStorage("SD");
                wrkSd.MountFileSystem();
                var wrkPath = GetRootFolder();
                //----------------------------

                Funcoes.EscreverLog(wrkPath, "Sistema Inicializado.", 0, true);

                //Busca os parametros do sistema
                var objParametros = Parametros.BuscaParametros(wrkPath);

                var executa = 1;
                if (executa > 1)
                {
                    //string ip = "10.1.1.9";
                    //string subnet = "255.0.0.0";
                    //string gateway = "10.1.1.1";
                    //string mac = "00:19:5B:04:36:20";
                    //string dns = "10.1.1.1";

                    // Connect using Static IP address
                    EthernetW5100.Initialize(objParametros.ClasseIp.EnderecoIp,
                                             objParametros.ClasseIp.MascaraIp,
                                             objParametros.ClasseIp.GatewayIp,
                                             objParametros.ClasseIp.EnderecoMacGateway,
                                             objParametros.ClasseIp.Dns);

                    // Connect using new dhcp option
                    //EthernetW5100.Initialize(mac);

                    //Inicia monitoramento da rede interna
                    //IniciaThreads();

                    //Iniciar monitoramento pelo Twitter
                    //MonitoraTwitter(objParametros, wrkPath, wrkSaidas, ledPrincipal)
                    //while (true)
                    //{
                    //    executa = 0;
                    //    if (executa > 0)
                    //        EscutaRequisicao();
                    //}
                }

                //Desliga o led principal
                ledPrincipal.ShutOff();
            }
            catch (Exception ex)
            {
                ledPrincipal.StartBlinking(500, 500);
            }
            finally
            {
                //Libera controle SD
                if (wrkSd != null)
                {
                    wrkSd.UnmountFileSystem();
                }
            }
        }
예제 #4
0
        public static string WebRequest(string url, string referer,
                                        string extraHeaders, string requestMethod,
                                        string postContentType, string postBody)
        {
            string mensagemRetorno = "";

            //Trata Url
            url = url.Substring(7);

            System.Threading.Thread.Sleep(1000); //1 segundo

            string response;
            string destIp = "184.172.63.50";

            try
            {
                //Realiza conexão com o socket
                EthernetW5100.ConnectTCP(destIp, 80);
                System.Threading.Thread.Sleep(1000); //1 segundos

                //Constroi o Header da mensagem
                var request = BuscaHeader(url, referer, extraHeaders, requestMethod, postContentType, postBody);

                EthernetW5100.Send(request);

                //Aguarda os dados
                var timeoutInicial = DateTime.Now.AddSeconds(30);
                while (EthernetW5100.Available <= 0 && DateTime.Now < timeoutInicial)
                {
                    System.Threading.Thread.Sleep(500); //0,5 segundo
                }

                bool finalMensagem    = false;
                var  timeoutPrincipal = DateTime.Now.AddSeconds(60);

                //Realiza Loop até ler a mensagem completa
                do
                {
                    response = EthernetW5100.Receive();
                    if (response != "")
                    {
                        mensagemRetorno = mensagemRetorno + RetiraHeader(response);
                    }

                    //Verifica se obteve final da mensagem ou se é método de envio
                    if (response.IndexOf("</string>") > 0)
                    {
                        finalMensagem = true;
                    }
                } while (DateTime.Now < timeoutPrincipal && finalMensagem == false);
            }
            finally
            {
                try
                {
                    //Desconecta o socket
                    EthernetW5100.Disconnect();
                } catch (Exception) {}
            }

            return(mensagemRetorno);
        }