Tuesday, March 8, 2011

Kevin's Week 7 Report

This week I worked more on setting up my program to accept data through Ethernet.  I have looked through some examples online on how this can be done and have written up a bit of code for a possible php source solution.  Shown below is the code I have written based off an example on a forum.  I have also recently found some examples of possible solutions done in C++/C#, so I will need to look at those as well to see if they will work better.

<?php

                    $DATA = $_GET['value'];

                    //Connect to database, IP address will need to match
                    $opendb = mysql_connect("192.168.1.1", "powertracker") or mysql_error("Could not connect to database");
                    mysql_select_db("powertracker");

     if ($opendb)
                                         {
                                         mysql_query(" INSERT INTO datatemp  VALUES ( NOW() ,  ‘Sensor1’, $DATA )");
                                         mysql_close($opendb);
                                           }
                    ?>

This should get data from the connection and put it directly into the database.  From there the rest of the program should operate in the same fashion.  I will need to create a client/server socket for the data streams.  The address should just be the same as the computer the database is running on.  I still have to test this possible solution to see how it works.  The only modification to my program in C# that will need to be made for testing is that I will not attempt to load data into the database through C#, it will be done through the PHP code.  The ‘value’ should be passed to the PC from the microcontroller.  I was hoping to get more done with the drop down buttons on the display this week, however I did not get much code down for that part due to midterms.  Thinking through it though, I have written up some pseudocode that I should be able to easily implement.

Set dropdowns to not visible
Check ‘type’ selected (year, month, day, hour)
If (year selected)
Set visible( year dropdown)
Read from database, go through entries and add year value to drop down list
If year is already in dropdown list, go to next data entry

If (month selected)
                Set visible( year and month dropdown)
Read from database, go through entries and add month with respective year selected in year dropdown
If month is already in dropdown list, go to next data entry

If(day selected)
                Set visible( year, month, and day dropdown)
Read from database, go through entries and add day with respective month and year selected in the month and year dropdown
If day is already in dropdown list, go to next data entry

If(hour selected)
                Set Visible(year, month, day, and hour dropdown)
Read from database, go through entries and add hour with respective day, month, and year selected in the day, month, and year dropdown
If year is already in dropdown list, go to next data entry

Next week and over break I want to finish the dropdown button issue and test some Ethernet communication.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home