示例#1
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);
            }
        }
示例#2
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();
        }
示例#3
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();
        }
示例#4
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();
        }
示例#5
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);
        }
示例#6
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);
        }
示例#7
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();
             */
        }