Posts: 1
Joined: Sat Dec 31, 2016 4:12 am

Best way to control RPi background app from PC

Sat Dec 31, 2016 5:11 am

I have an app on the Raspberry Pi running in the background [Background Aplication(IoT)]. It can't be started as the "head" because another application is using UI. There is the problem because i need to control this background app from Universal Windows app running on desktop or Windows Phone. All the devices are running on the same network.

so my question is what is the best way to control background app from desktop?
Is this posible using AppServiceConnection or do I need use some protocol?

Posts: 4
Joined: Mon Nov 21, 2016 6:47 pm

Re: Best way to control RPi background app from PC

Tue Jan 03, 2017 7:16 pm

I have been controlling a pi running my app in the background from another uwp device with a web server.

Server (running on pi in the background):

Connect to it from a web page, desktop, or phone app. If connecting from a upw app use HttpClient.


Code: Select all

 //This is using my setup so your use will use a different .html string and ip address.        

const string _serverUrl = ""; 

        public void ClientHeaderInfo(HttpClient client)
            client.BaseAddress = new Uri(_serverUrl);
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

        public async Task<bool> SendRequest(string id, string url)
            HttpClientHandler handler = new HttpClientHandler { UseDefaultCredentials = true };
            using (var client = new HttpClient(handler))
                var result = await client.GetAsync(AddParameterToUri(url, AddStateToParameter(id)));

                return result.IsSuccessStatusCode;

        private KeyValuePair<string, string> AddStateToParameter(string id)
            return  new KeyValuePair<string, string>("state", id);

        private string AddParameterToUri(string uri, KeyValuePair<string, string> parameter)
            return string.Format("{0}?{1}={2}", uri, parameter.Key, parameter.Value);

        private async void GreenOn()
            DataTransfer dt = new DataTransfer();
            DelayedServerResponce = await dt.SendRequest("on", "GpioBinaryController.html");

        private async void GreenOff()
            DataTransfer dt = new DataTransfer();
            var result = await dt.SendRequest("off", "GpioBinaryController.html");
            DelayedServerResponce = !result;

//To use this 

Return to “Windows 10 for IoT”