Пример #1
0
        private void sendAuthRequest(string scannedRFID, GT.Picture capturedImage)
        {
            /* Code for sending rfid and picture to webserver */
            if (ethernetJ11D.IsNetworkUp)
            {
                string jsonString = getJsonString(scannedRFID, capturedImage);
                //displayText("JSON string: " + jsonString);
                Debug.Print("JSON string: " + jsonString);
                displayText("Network up. Trying to send authentication request..");

                POSTContent jsonContent = POSTContent.CreateTextBasedContent(jsonString);
                var         req         = HttpHelper.CreateHttpPostRequest(webserverUrl, jsonContent, "application/json");

                //var req = HttpHelper.CreateHttpGetRequest("http://192.168.1.2:8008/DEMOService/prova");
                req.ResponseReceived += new HttpRequest.ResponseHandler(req_ResponseReceived);
                req.SendRequest();
                displayText("Request sended!");
            }
            else
            {
                string jsonString = getJsonString(scannedRFID, capturedImage);
                //displayText("JSON string: " + jsonString);
                displayText("Authentication failed because network is down");
            }

            authInProgress = false;
            timeOutTimer.Stop();
        }
Пример #2
0
        void timer_Tick(Gadgeteer.Timer timer)
        {
            temperature = thermocouple.GetExternalTemperature();

            DC.DCPushTemperature tem = new DC.DCPushTemperature()
            {
                Temperature = temperature
            };

            string jsonRequest = Json.NETMF.JsonSerializer.SerializeObject(tem);

            POSTContent postData = POSTContent.CreateTextBasedContent(jsonRequest);

            var reqData =
                HttpHelper.CreateHttpPostRequest("http://simil.cloudapp.net/SmartFridgeServer/Api/Fridge/PushTemperature",
                                                 postData, "application/json");

            reqData.ResponseReceived += reqData_ResponseReceived;
            reqData.SendRequest();

            if (OnTemRead != null)
            {
                OnTemRead(this, null);
            }
        }
Пример #3
0
        void sdcard_TouchDown(object sender, Microsoft.SPOT.Input.TouchEventArgs e)
        {
            timer.Stop();
            button.TurnLedOn();
            button.ButtonPressed += button_ButtonPressed;
            HideButtons();
            displayTE35.SimpleGraphics.DisplayImage(istruzioniSD, 0, 0);
            Thread.Sleep(5000);
            if (sdCard.IsCardInserted && sdCard.IsCardMounted)
            {
                button.ButtonPressed -= button_ButtonPressed;
                button.TurnLedOff();
                HideButtons();
                displayTE35.SimpleGraphics.DisplayImage(authTry, 0, 0);
                string rootdirectory = sdCard.StorageDevice.RootDirectory;
                rootdirectory += @"\accessDoor";
                FileStream fileStream = new FileStream(rootdirectory + @"\authDoor.txt", FileMode.Open);
                byte[]     data       = new byte[fileStream.Length];
                Debug.Print(fileStream.Length + "");
                fileStream.Read(data, 0, data.Length);
                fileStream.Close();
                Debug.Print("data: " + data);
                string text = new string(Encoding.UTF8.GetChars(data));
                Debug.Print("text: " + text);
                userStr = text.Substring(0, 6);
                Debug.Print(userStr);
                pinStr = text.Substring(8, 4);
                Debug.Print(pinStr);


                button.ButtonPressed -= button_ButtonPressed;
                Debug.Print("Contatta server");


                utenteCorrente.id   = userStr.ToString();
                utenteCorrente.user = userStr.ToString();
                utenteCorrente.pin  = pinStr.ToString();

                //Debug.Print("Net AVAIL: " + netif.NetworkIsAvailable);
                //Debug.Print("IP ADD: "+netif.IPAddress);
                //Debug.Print("DHCP EN: " + netif.IsDhcpEnabled);
                //Debug.Print("SUBNET MASK:" + netif.SubnetMask);
                //Debug.Print("GATEWAY" + netif.GatewayAddress);
                //Debug.Print("PIN "+ pinStr.ToString());
                Hashtable ht = new Hashtable();
                ht.Add("Id", utenteCorrente.id);
                ht.Add("User", utenteCorrente.user);
                ht.Add("Pwd", utenteCorrente.pin);

                POSTContent content = Gadgeteer.Networking.POSTContent.CreateWebFormData(ht);
                var         request = HttpHelper.CreateHttpPostRequest(@"http://169.254.202.73/api/Utente/", content, "application/x-www-form-urlencoded");
                request.ResponseReceived += request_ResponseReceived_USER_PIN;

                request.SendRequest();
                HideButtons();
            }

            SetupDisplay();
        }
Пример #4
0
        public void SendIpHTTP(string ip)
        {
            setProcessing(true);
            POSTContent emptyPost = new POSTContent();
            var         req       = HttpHelper.CreateHttpPostRequest(serverAddress + "ip/" + ip, emptyPost, null);

            req.ResponseReceived += new HttpRequest.ResponseHandler(req_ResponseReceived);
            req.SendRequest();
            Debug.Print("[CLIENT] " + serverAddress + "ip/" + ip);
        }
Пример #5
0
        public void sendPictureTCP(byte[] pictureBytes)
        {
            this.setProcessing(true);
            pictureRecognized = false;

            this.pictureBytes = pictureBytes;
            POSTContent postContent = new POSTContent();
            var         req         = HttpHelper.CreateHttpPostRequest(
                serverAddress + "picture/TCP/" + pictureBytes.Length.ToString(), postContent, null);

            req.ResponseReceived += new HttpRequest.ResponseHandler(req_ResponseReceived_picture);
            req.SendRequest();
            Debug.Print("[CLIENT] " + serverAddress + "picture/TCP/" + pictureBytes.Length.ToString());
        }
Пример #6
0
        public void getServerTime()
        {
            POSTContent emptyPost = new POSTContent();

            // Create the request
            var request = Gadgeteer.Networking.HttpHelper.CreateHttpPostRequest(
                IPAddress + @"RestService.svc/getServerTime" // the URL to post to
                , emptyPost                                  // the form values
                , null                                       // the mime type for an HTTP form
                );

            request.ResponseReceived += new HttpRequest.ResponseHandler(getServerTime_ResponseReceived);

            // Post the form
            request.SendRequest();
        }
Пример #7
0
        void sendDataToServer()
        {
            object item;

            while (true)
            {
                while (!this.ethernetJ11D.NetworkInterface.NetworkIsAvailable)
                {
                    Thread.Sleep(1000);
                }
                while (queue.pull(out item))
                {
                    InfoToHost info = (InfoToHost)item;
#if DEBUG
                    Debug.Print("Sending to the server " + info);
#endif


                    try
                    {
                        string address = "http://" + hostRunningWCFService + "/domotic/insert/" + info.DataType;

                        POSTContent content = Gadgeteer.Networking.POSTContent.CreateTextBasedContent(info.JSONValue);

                        HttpRequest req =
                            HttpHelper.CreateHttpPostRequest(address, content, "text/json");
                        req.AddHeaderField("Content-Type", "text/json");
                        req.ResponseReceived += req_ResponseReceived;
#if DEBUG
                        Debug.Print("Sending request to " + req.URL);
#endif

                        lock (lokcker)
                        {
                            req.SendRequest();
                        }
                    }
                    catch (System.Exception e)
                    {
                        Debug.Print("exception!!!");
                        Debug.Print(e.Message);
                        break;
                    }
                }
            }
        }
Пример #8
0
        void UpdateDoorStatus(bool status)
        {
            DC.DCPushDoorStatus doorStat = new DC.DCPushDoorStatus()
            {
                DoorIsOpened = status
            };

            string jsonRequest = Json.NETMF.JsonSerializer.SerializeObject(doorStat);

            POSTContent postData = POSTContent.CreateTextBasedContent(jsonRequest);

            var reqData =
                HttpHelper.CreateHttpPostRequest("http://simil.cloudapp.net/SmartFridgeServer/Api/Fridge/PushDoorIsOpened",
                                                 postData, "application/json");

            reqData.ResponseReceived += reqData_ResponseReceived;
            reqData.SendRequest();
        }
Пример #9
0
        void camera_PictureCaptured(Camera sender, GT.Picture picture)
        {
            InitDisplay();
            display_TE35.SimpleGraphics.DisplayImage(picture, 0, 0);



            string reaURI = "http://" + reqHOST + ":" + reqPORT + "/gadg/Service1/transfer/" + lightMEAS.ToString() + "/" + humMEAS.ToString() + "/" + tempMEAS.ToString();

            POSTContent postCont = POSTContent.CreateBinaryBasedContent(picture.PictureData);
            var         req      = HttpHelper.CreateHttpPostRequest(reaURI, postCont, "image/bmp");

            req.ResponseReceived += new HttpRequest.ResponseHandler(req_ResponseReceived);
            req.SendRequest();

            DisplayText(2, "Req sent - PicSize: " + picture.PictureData.Length.ToString());
            DisplayText(3, "MEAS li:" + lightMEAS.ToString() + " hu:" + humMEAS.ToString() + " te:" + tempMEAS.ToString());
        }
Пример #10
0
        private void timer_TakeMeasure(GT.Timer timer)
        {
            Debug.Print("Measuring conditions ... ");
            GT.Timer t = new GT.Timer(300);
            t.Tick += timer_blinkLed;
            t.Start();
            TempHumidSI70.Measurement m = temp.TakeMeasurement();
            double l    = light.ReadProportion();
            int    mois = moisture.ReadMoisture();

            Debug.Print("Measurement --- Light " + l + " - Temperature " + m.Temperature + " - Moisture " + mois);

            if (!NETWORK_UP)
            {
                Debug.Print("Network down... not sending data to server.");
            }
            else
            {
                Debug.Print("Sending data to server....");

                Debug.Print("Attempt B1 - Sending data to server using just POST....");

                POSTContent emptyPost = new POSTContent();
                String      pathA     = httpPath + "SmartService.svc/web/Measurements/Create/" + m.Temperature.ToString().Substring(0, 4) +
                                        "/" + l.ToString().Substring(0, 4) + "/" + mois.ToString() + "/";
                var reqA = HttpHelper.CreateHttpPostRequest(pathA, emptyPost, null);
                Debug.Print("HTTP request to server: " + pathA);

                reqA.ResponseReceived += new HttpRequest.ResponseHandler(req_ResponseReceived);
                reqA.SendRequest();
            }

            Thread.Sleep(1000);
            t.Stop();
            ledStrip.SetLed(MEASUREMENT_LED, false);

            if (AUTOPILOT && !IRRIGATING && checkIrrigationNecessary(m.Temperature, l, mois))
            {
                irrigate();
            }
        }
Пример #11
0
        private void PushItem(string idItem, bool input)
        {
            DCItemInv dcitem = new DCItemInv()
            {
                IdItem = idItem,
                In     = input
            };

            string jsonRequest = Json.NETMF.JsonSerializer.SerializeObject(dcitem);

            POSTContent postData = POSTContent.CreateTextBasedContent(jsonRequest);


            var reqData =
                //HttpHelper.CreateHttpPostRequest("http://localhost/SmartFridgeServer/Api/Fridge/PushProduct",
                HttpHelper.CreateHttpPostRequest("http://simil.cloudapp.net/SmartFridgeServer/Api/Fridge/PushProduct",
                                                 postData, "application/json");

            reqData.ResponseReceived += reqPushItem_ResponseReceived;
            reqData.SendRequest();
        }
Пример #12
0
        public void PutGas(String lpg, String co, String smoke, String date)
        {
            // Create the form values
            var formValues = "lpg=" + lpg + "&co=" + co + "&smoke=" + smoke + "&date=" + date;


            // Create GET content
            //var content = Gadgeteer.Networking.POSTContent.CreateTextBasedContent(formValues);
            POSTContent emptyPost = new POSTContent();

            // Create the request
            var request = Gadgeteer.Networking.HttpHelper.CreateHttpPostRequest(
                IPAddress + @"RestService.svc/putGas?" + formValues // the URL to post to
                , emptyPost                                         // the form values
                , null                                              // the mime type for an HTTP form
                );

            request.ResponseReceived += new HttpRequest.ResponseHandler(PutGas_ResponseReceived);

            // Post the form
            request.SendRequest();
        }
Пример #13
0
        public void GetGas(string n)
        {
            // Create the form values
            var formValues = "n=" + n;


            // Create GET content
            var         content   = Gadgeteer.Networking.POSTContent.CreateTextBasedContent(formValues);
            POSTContent emptyPost = new POSTContent();

            // Create the request
            var request = Gadgeteer.Networking.HttpHelper.CreateHttpPostRequest(
                IPAddress + @"RestService.svc/getGas?n=" + n // the URL to post to
                , emptyPost                                  // the form values
                , null                                       // the mime type for an HTTP form
                );

            request.ResponseReceived += new HttpRequest.ResponseHandler(GetGas_ResponseReceived);

            // Post the form
            request.SendRequest();
        }
Пример #14
0
        public void PutCross(string t)
        {
            // Create the form values
            var formValues = "date=" + t;

            Debug.Print("Cross timestamp: " + t);
            // Create GET content
            //var content = Gadgeteer.Networking.POSTContent.CreateTextBasedContent(formValues);
            POSTContent emptyPost = new POSTContent();

            // Create the request
            var request = Gadgeteer.Networking.HttpHelper.CreateHttpPostRequest(
                IPAddress + @"RestService.svc/putCross?" + formValues // the URL to post to
                , emptyPost                                           // the form values
                , null                                                // the mime type for an HTTP form
                );

            request.ResponseReceived += new HttpRequest.ResponseHandler(PutCross_ResponceRecevided);

            // Post the form
            request.SendRequest();
        }
Пример #15
0
        //Metodo para subir los archivos a un servidor
        private void sendBitmapToServer(GT.Picture picture)
        {
            if (ethernetJ11D.IsNetworkUp)
            {
                try
                {
                    //POSTContent content = POSTContent.CreateBinaryBasedContent(currentBitmap.GetBitmap());
                    POSTContent fileToUpload = POSTContent.CreateBinaryBasedContent(picture.PictureData);
                    HttpRequest pedido       = HttpHelper.CreateHttpPostRequest("http://christianvergara.net16.net/upload.php?submit=true&action=upload", fileToUpload, "multipart/form-data");


                    pedido.SendRequest();
                    pedido.ResponseReceived += pedido_ResponseReceived;

                    Debug.Print("Imagen enviada");
                }
                catch (System.ObjectDisposedException oe)
                {
                    Debug.Print("Error in sendBitmapToCloud(): " + oe.Message);
                }
            }
        }
Пример #16
0
        private void init()
        {
            Buzzer.init(breakout2.CreatePwmOutput(GT.Socket.Pin.Nine));
            StatusLed.led = ledStrip;
            StatusLed.led.SetLed(0, true);
            DisplayLCD.lcd = displayTE35;
            DisplayTimer();
            while (!wifi.NetworkInterface.Opened)
            {
                try
                {
                    Debug.Print("Opening Wifi interface");
                    wifi.NetworkInterface.Open();
                    Thread.Sleep(1000);
                }
                catch (Exception)
                {
                    Thread.Sleep(1000);
                    continue;
                }
            }
            GeoMessage geomessage = new GeoMessage(wifi.NetworkInterface.Scan());

            wifi.NetworkInterface.Close();
            RemovableMedia.Insert += (sender, e) => {
                mountEvent.Set(); Debug.Print("SD Mounted");
            };
            while (!sdCard.IsCardInserted)
            {
                DisplayLCD.addSDInfo(false, 0);
                Thread.Sleep(1000);
                Debug.Print("Waiting for sd card");
            }

            while (!sdCard.IsCardMounted)
            {
                DisplayLCD.addSDInfo(false, 0);
                Thread.Sleep(1000);
                if (!sdCard.IsCardMounted)
                {
                    sdCard.Mount();
                }
            }
            //mountEvent.WaitOne();
            //byte[] data = Encoding.UTF8.GetBytes("Hello World!");
            //sdCard.StorageDevice.WriteFile("measure" + 0, data);
            //sdCard.StorageDevice.CreateDirectory(@"test");

            /*if (VolumeInfo.GetVolumes()[0].IsFormatted)
             * {
             *  string rootDirectory =
             *      VolumeInfo.GetVolumes()[0].RootDirectory;
             *  string[] files = Directory.GetFiles(rootDirectory);
             *  string[] folders = Directory.GetDirectories(rootDirectory);
             *
             *  Debug.Print("Files available on " + rootDirectory + ":");
             *  for (int i = 0; i < files.Length; i++)
             *  {
             *      Debug.Print("Deleted " + files[i]);
             *      sdCard.StorageDevice.Delete(files[i]);
             *  }
             *  Debug.Print("Folders available on " + rootDirectory + ":" + folders.Length);
             * }
             * else
             * {
             *  Debug.Print("Storage is not formatted. " +
             *      "Format on PC with FAT32/FAT16 first!");
             * }*/
            DisplayLCD.addSDInfo(true, 0);
            Ethernet eth = new Ethernet(ethernetJ11D);

            Debug.Print("Ethernet created");
            mqtt = eth.MQTT;
            Debug.Print("Mqtt created");
            MeasureOrchestrator.setMqtt(mqtt);
            MeasureDB.sd = sdCard;
            Debug.Print("Time updated");
            TimeSync.update();
            while (!mqtt.isConnected())
            {
                Thread.Sleep(1000);
            }
            POSTContent pc = POSTContent.CreateTextBasedContent(GeoMessage.Json(geomessage));

            try
            {
                HttpRequest wc = HttpHelper.CreateHttpPostRequest("http://52.57.156.220/geolocation", pc, "application/json");
                wc.ResponseReceived += wc_ResponseReceived;
                wc.SendRequest();
            }
            catch (Exception) {
                mqtt.Publish("cfg", Configuration.Json(new Configuration(45.0631, 7.66004)));
            }

            //send a request with GeoMessage.Json(message) and set the configuration
            FlameSensor       flame       = new FlameSensor(breakout.CreateAnalogInput(GT.Socket.Pin.Three), "0");
            SmokeSensor       smoke       = new SmokeSensor(breakout.CreateAnalogInput(GT.Socket.Pin.Four), "1");
            COSensor          co          = new COSensor(breakout.CreateAnalogInput(GT.Socket.Pin.Five), "2");
            TemperatureSensor temperature = new TemperatureSensor(breakout3.CreateAnalogInput(GT.Socket.Pin.Three), "3");

            registerSensor(temperature);
            registerSensor(smoke);
            registerSensor(co);
            registerSensor(flame);
            pubTimer(3000);
            pubOldTimer(2000);
        }
Пример #17
0
        private void sendAuthRequest(string scannedRFID, GT.Picture capturedImage)
        {
            /* Code for sending rfid and picture to webserver */
            if (ethernetJ11D.IsNetworkUp)
            {
                string hashSession = "";

                IPEndPoint ipep         = new IPEndPoint(IPAddress.Parse("192.168.1.2"), 11000);
                Socket     clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                clientSocket.ReceiveTimeout = TIMEOUT;
                clientSocket.SendTimeout    = TIMEOUT;

                try
                {
                    clientSocket.Connect(ipep);
                    MySocketFunctions.socketSendFile(clientSocket, capturedImage.PictureData);
                    hashSession = MySocketFunctions.socketReadLine(clientSocket);       //reads the session hashstring received from server socket as response
                }
                catch (Exception e)
                {
                    displayMessage("Network down", true);
                    authInProgress = false;
                    return;
                }
                finally
                {
                    clientSocket.Close();
                }

                string jsonString = getJsonString(scannedRFID, hashSession); //parse user RFID and session hash into JSON string
                //Debug.Print("JSON string: " + jsonString);
                //string jsonString = "{\"rfid\":\"" + scannedRFID + "\",\"session\":\"" + hashSession + "\"}";

                POSTContent jsonContent = POSTContent.CreateTextBasedContent(jsonString);

                if (currentRequestType == 1)     //user had pushed ENTER
                {
                    webserverUrl = "http://192.168.1.2:8008/DEMOService/enter";
                }
                else if (currentRequestType == 2)        //user had pushed EXIT
                {
                    webserverUrl = "http://192.168.1.2:8008/DEMOService/exit";
                }
                var req = HttpHelper.CreateHttpPostRequest(webserverUrl, jsonContent, "application/json");
                req.ResponseReceived += new HttpRequest.ResponseHandler(req_ResponseReceived);
                timeOutTimer.Start();       //start timeout timer (30 sec)
                req.SendRequest();
                //Debug.Print("Request sent!");
            }
            else
            {
                //Debug.Print("Authentication failed because network is down");
                multicolorLED.TurnRed();
                displayMessage("Network down, check cable", true);
                authInProgress = false;
                //timeOutTimer.Stop();
            }

            /*
             * authInProgress = false;
             * timeOutTimer.Stop();
             */
        }
Пример #18
0
        public HttpRequest createSignedRequest()
        {
            String oauth_nonce            = getOauthNonce();
            String oauth_signature_method = getOauthSignatureMethod();
            String oauth_timestamp        = getOauthTimestamp();
            String oauth_token            = getOauthToken();
            String oauth_version          = getOauthVersion();

            Debug.Print("OauthNonce: " + oauth_nonce);
            Debug.Print("OauthSignatureMethod: " + oauth_signature_method);
            Debug.Print("OauthTimestamp: " + oauth_timestamp);
            Debug.Print("OauthToken: " + oauth_token);
            Debug.Print("OauthVersion: " + oauth_version);

            /*
             * Se genera la cadena que luego se firmará
             */
            String signature_base_string = createSignatureBaseString(http_method, http_uri, http_get, http_post, oauth_nonce, oauth_timestamp, oauth_token, oauth_version);

            Debug.Print("SignatureBaseString: " + signature_base_string);


            /*
             * Se genera la firma a partir del signature_base_string
             */

            String signing_key = getSigningKey();

            Debug.Print("SigningKey: " + signing_key);


            String oauth_signature = getOauthSignature(signature_base_string, signing_key);

            Debug.Print("OauthSignature: " + oauth_signature);


            /*
             * Se crea el header de autorizacion
             */

            String authorization_header = createAuthorizationHeader(oauth_nonce, oauth_signature, oauth_signature_method, oauth_timestamp, oauth_token, oauth_version);

            Debug.Print("AuthorizationHeader: " + authorization_header);


            HttpRequest request;
            POSTContent post_content;
            String      post_query;
            String      get_query;

            post_query = createPostQuery(http_post);
            get_query  = createGetQuery(http_get);

            Debug.Print("PostQuery: " + post_query);
            Debug.Print("GetQuery: " + get_query);


            if (http_method == "POST")
            {
                post_content = POSTContent.CreateTextBasedContent(post_query);
                request      = HttpHelper.CreateHttpPostRequest(http_uri + get_query, post_content, null);
            }
            else if (http_method == "GET")
            {
                request = HttpHelper.CreateHttpGetRequest(http_uri + get_query);
            }
            else
            {
                Debug.Print("El metodo " + http_method + " no está soportado.");
                return(null);
            }

            request.AddHeaderField("Authorization", authorization_header);

            Debug.Print("Request Url: " + request.URL);

            return(request);
        }
Пример #19
0
        void numericKey_TouchDown(object sender, Microsoft.SPOT.Input.TouchEventArgs e)
        {
            // cancella tutto con delete e con invio contatta il server
            int y, x;

            e.GetPosition(mainWindow, 0, out x, out y);
            char carattere = riconosci_tocco_tastiera(x, y);

            if (carattere == 'v')
            {
                return;
            }

            if (ntoccou == 10 && carattere != 'e')
            {
                return;
            }

            if (carattere == 'e' && ntoccou == 10)
            {
                button.ButtonPressed -= button_ButtonPressed;
                Debug.Print("Contatta server");

                utenteCorrente.id   = userStr.ToString();
                utenteCorrente.user = userStr.ToString();
                utenteCorrente.pin  = pinStr.ToString();

                //Debug.Print("Net AVAIL: " + netif.NetworkIsAvailable);
                //Debug.Print("IP ADD: "+netif.IPAddress);
                //Debug.Print("DHCP EN: " + netif.IsDhcpEnabled);
                //Debug.Print("SUBNET MASK:" + netif.SubnetMask);
                //Debug.Print("GATEWAY" + netif.GatewayAddress);
                //Debug.Print("PIN "+ pinStr.ToString());
                Hashtable ht = new Hashtable();
                ht.Add("Id", utenteCorrente.id);
                ht.Add("User", utenteCorrente.user);
                ht.Add("Pwd", utenteCorrente.pin);

                POSTContent content = Gadgeteer.Networking.POSTContent.CreateWebFormData(ht);
                var         request = HttpHelper.CreateHttpPostRequest(@"http://169.254.202.73/api/Utente/", content, "application/x-www-form-urlencoded");
                request.ResponseReceived += request_ResponseReceived_USER_PIN;

                request.SendRequest();
                HideButtons();
                return;
            }
            else if (carattere == 'e')
            {
                return;
            }

            if (ntoccou == 0 && carattere == 'c')
            {
                SetupDisplay();
            }

            if (ntoccou >= 0 && ntoccou <= 6)
            {
                if (carattere == 'c' && ntoccou != 0)
                {
                    if (ntoccou == 1)
                    {
                        userStr = "";
                        ntoccou = 0;
                        usernameValue.TextContent = "";
                        return;
                    }
                    else
                    {
                        userStr = userStr.Substring(0, ntoccou - 1);
                        ntoccou--;
                        usernameValue.TextContent = userStr;
                        return;
                    }
                }
                else if (carattere != 'c' && ntoccou != 6)
                {
                    userStr += carattere.ToString();
                    ntoccou++;
                    usernameValue.TextContent = userStr;
                    return;
                }
            }

            if (ntoccou >= 6 && ntoccou <= 10)
            {
                if (carattere == 'c' && ntoccou != 6)
                {
                    if (ntoccou == 7)
                    {
                        pinStr = "";
                        pinValue.TextContent = "";
                        ntoccou = 6;
                        ntoccop = 0;
                        return;
                    }
                    else
                    {
                        pinStr = pinStr.Substring(0, ntoccop - 1);
                        string tmp = "";
                        for (int j = 0; j < pinStr.Length; j++)
                        {
                            tmp += '*';
                        }
                        pinValue.TextContent = tmp;
                        ntoccop--;
                        ntoccou--;
                        return;
                    }
                }
                else if (carattere != 'c' && ntoccou != 10)
                {
                    pinStr += carattere.ToString();
                    pinValue.TextContent += '*';
                    ntoccou++;
                    ntoccop++;
                    return;
                }
            }
        }