ocpistol
Posts: 7
Joined: Tue Jun 23, 2015 4:58 pm

Sending Data

Tue Jun 23, 2015 5:39 pm

Hello Everybody,
I am sorry I am a huge noob, I am making a program for a PI2 to basically look at 2 switches and send data to a database when they open or close.
I have been looking at the best way to perform this with what has all been implemented in win10iot so far.
I have done this previously with arduino but sent it via php this worked well.

Any ideas concerns or questions let me know, I appreciate any help I can get in this matter.
Thank You So Much

tweedie
Posts: 19
Joined: Wed Mar 04, 2015 11:32 am

Re: Sending Data

Wed Jun 24, 2015 10:03 am

You not saying where this database is, but if you want to run database locally (within the pi), then worth checking out SQLite (viewtopic.php?f=105&t=111447). if want to write to db remotely like azure, then this interesting weather station project (http://www.hackster.io/windowsiot/build ... windows-10) might offer you some clues.

as for the two switches, there is a push button sample online (http://ms-iot.github.io/content/en-US/w ... Button.htm) that you can use in a similar sort of way.

ocpistol
Posts: 7
Joined: Tue Jun 23, 2015 4:58 pm

Re: Sending Data

Wed Jun 24, 2015 1:37 pm

tweedie wrote:You not saying where this database is, but if you want to run database locally (within the pi), then worth checking out SQLite (viewtopic.php?f=105&t=111447). if want to write to db remotely like azure, then this interesting weather station project (http://www.hackster.io/windowsiot/build ... windows-10) might offer you some clues.

as for the two switches, there is a push button sample online (http://ms-iot.github.io/content/en-US/w ... Button.htm) that you can use in a similar sort of way.
Thank you for replying! I got the pushbutton app to work with that I want to do. But I was looking to connect to a mysql server that I am currently running in hyper-v with replication, because that is what I use for all my websites and I think it would be easier to keep all my databases the same. I do run windows server 2012 so can I install azure sql on that?

tweedie
Posts: 19
Joined: Wed Mar 04, 2015 11:32 am

Re: Sending Data

Wed Jun 24, 2015 4:24 pm

AFAIK, azure is microsoft cloud version of database and not something you can install on your OS.

To connect to mysql database, you will have to add some mysql dll to your project. something like http://www.codeproject.com/Tips/423233/ ... ing-Csharp. (I am guessing you using c#)

Personally, I probably have some sort of rest/soap/api web app on your server to receive request of various button states and let app write/read to the mysql database.

ocpistol
Posts: 7
Joined: Tue Jun 23, 2015 4:58 pm

Re: Sending Data

Wed Jun 24, 2015 4:34 pm

That is what I wanted to do was have an web app do it like php but I couldnt get c# on pi2 work with going to php page. I have done that on a netdunio.

jtanner_msft
Posts: 105
Joined: Fri May 01, 2015 7:12 pm

Re: Sending Data

Wed Jun 24, 2015 5:24 pm

tweedie is correct that SQL Azure is a hosted service. If you are running Windows Server 2012, you'd likely want to look at running something like some edition of SQL Server 2014:
https://www.microsoft.com/en-us/server- ... ql-server/
Jonathan Tanner | Microsoft | Windows 10 IoT Core Insider Preview Support | This posting is provided 'as is' with no warranties and confers no rights.

tweedie
Posts: 19
Joined: Wed Mar 04, 2015 11:32 am

Re: Sending Data

Wed Jun 24, 2015 5:37 pm

ocpistol wrote: I couldnt get c# on pi2 work with going to php page.
have you tried something like (c# code)

Code: Select all

            HttpClient webClient = new HttpClient(); 
            Uri serviceUri = new Uri(@"http://www.mywebapp.com/buttonApp.php?button1=1&button2=0"); 
            HttpResponseMessage serviceResponse = await webClient.GetAsync(serviceUri); 

ocpistol
Posts: 7
Joined: Tue Jun 23, 2015 4:58 pm

Re: Sending Data

Wed Jun 24, 2015 10:07 pm

tweedie wrote:
ocpistol wrote: I couldnt get c# on pi2 work with going to php page.
have you tried something like (c# code)

Code: Select all

            HttpClient webClient = new HttpClient(); 
            Uri serviceUri = new Uri(@"http://www.mywebapp.com/buttonApp.php?button1=1&button2=0"); 
            HttpResponseMessage serviceResponse = await webClient.GetAsync(serviceUri); 

That Worked with some light alterations, Thank you! makes life so much easier!

Code: Select all


public async void SendData()
        {
            HttpClient webClient = new HttpClient();
            Uri serviceUri = new Uri(@"http://url.php");

            try
            {

                HttpResponseMessage serviceResponse = await webClient.GetAsync(serviceUri);
                HelloMessage.Text = "Worked";
               
            }
            catch { 

                HelloMessage.Text = "Failed";

            }
        }

Milla284
Posts: 1
Joined: Thu Oct 18, 2018 5:17 am

Re: Sending Data

Tue Nov 13, 2018 4:44 am

ocpistol wrote:
Tue Jun 23, 2015 5:39 pm
Hello Everybody,
I am sorry I am a huge noob, I am making a program for a PI2 to basically look at 2 switches and send data to a database when they open or close. prepaid gift balance
I have been looking at the best way to perform this with what has all been implemented in win10iot so far.
I have done this previously with arduino but sent it via php this worked well.

Any ideas concerns or questions let me know, I appreciate any help I can get in this matter.
Thank You So Much
if you want to run database locally (within the pi), then worth checking out SQLite..

Return to “Windows 10 for IoT”