I always go with a deluxe hosting account with Godaddy. With this account, you can add as many domains to it as you want for around 10.00 each. It is a minimal effort to create a mysqyl database and add fields. So you need several ingredients to do what I suggest. First, I do not bother trying to write code on the Prop for http protocol, that gets to be a headache for me, especially for things like accessing a database. Instead, PHP is very easy to figure out, and create little pages that do all the real http work and just echo the responses. I will give you an example of a PHP page that you can pass the database address, username, and password. The mysql database can be on the same server or on any other server. Finding a free webserver may be possible to park the pages, but parking a database for free.. I am not sure if that exists, you can google free mysql database, free hosting etc. Who cares if they banners etc, no one is ever going to see the page but you probably. Most of the sites I have used are cheap, domains can be around 10 a year, hosting for a single site can be around 10 also. Finding a service with a quick install mysql db will make things easier. It doesn't get much easier than Godaddy IMO.
This is a page that will read a database and echo what you need back. This could be one or many values returned.
You would need to modify this to your needs. PHP is quite easy compared to Spin, so it would be no problem to modify the code here. Server is the address to find the db. DBU is the username and DBP is the password.
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Read DB</title>
</head>
<body>
<br>
<?php $con = mysql_connect($_REQUEST[SERVER],$_REQUEST[DBU],$_REQUEST[DBP]);
if (!$con)
// See if the connection to the DB was made
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
if ($con)
{
echo "CONNECTED TO DB";
}
mysql_select_db($_REQUEST[DBU], $con);
$result = mysql_query("SELECT * FROM $_REQUEST[TABLE]");
while($row = mysql_fetch_array($result))
{
echo "DVR=";
echo $row['DVR']
WHERE ID='$_REQUEST[ID]';
echo "DVON=";
echo $row['DVON']
WHERE ID='$_REQUEST[ID]';
echo "DVOFF=";
echo $row['DVOFF']
WHERE ID='$_REQUEST[ID]';
echo "BASEIP=";
echo $row['BASEIP']
WHERE ID='$_REQUEST[ID]';
echo "SDOWN=";
echo $row['SDOWN']
WHERE ID='$_REQUEST[ID]';
echo "CLEAR=";
echo $row['CLEAR']
WHERE ID='$_REQUEST[ID]';
echo "RSTTIMER=";
echo $row['RSTTIMER']
WHERE ID='$_REQUEST[ID]';
echo "DAY=";
echo $row['DAY']
WHERE ID='$_REQUEST[ID]';
echo "HOUR=";
echo $row['HOUR']
WHERE ID='$_REQUEST[ID]';
echo "MINUTE=";
echo $row['MINUTE']
WHERE ID='$_REQUEST[ID]';
echo "CLOSED" . mysql_error();
}
mysql_close($con);
?>
<br>
<br>
</body>
</html>
This is the code I used on the Prop to access the ReadDB page. It is not coded for the Spinerette, but rather for a wifi device via UART with the 4 port object( port 1 is for serial terminal debug, port 2 is the wifi device commands)
Code:
PUB ReadDB
ser.str(1, string("READ DB"))
ser.tx(1, CR)
beep(19, 2500, 100)
w(20_000_000) ' wait
beep(19, 2500, 100)
w(20_000_000)
beep(19, 2500, 100)
ex 'exit if it was open from previous
ex
ser.str(1, string("---")) 'debug
ser.str(2, string("$$$")) ' enter command mode on wifi
Viewreply
ser.str(2, string("open xxxxxxxxxx.com 80")) ' your webserver domain name where the page is loaded
ser.tx(2, CR)
Viewreply
Viewreply
ser.str(2, string("GET /readdb.php?")) ' open the web page shown above
ser.str(2, string("TABLE=table1")) 'DB table name ' provide the table name in the db
ser.str(2, string("&ID=1")) 'system ID in case of multiple systems using same db
ser.str(2, string("&SERVER=xxxxxx.db.xxxxxxxxxx.xxxxxxxxxresource.com")) '' DB server
ser.str(2, string("&DBU=xxxxxxxx")) ''DB username
ser.str(2, string("&DBP=xxxxxxxxx")) 'DB password
ser.str(2, string(" HTTP/1.1")) 'http GET terminator
ser.tx(2, CR)
ser.tx(2, LF)
ser.str(2, string("Host: xxxxxxxxx.com"))
ser.tx(2, LF) ' two LF required
ser.tx(2, LF)
RecWifiData 'after sending the command to open the page, now read whatever comes back
ParseDBReply 'disect and act on commands
The last ingredient is the page that is used to update the DB remotely by the user. This would mean changing a value on the database, this could be as simple as making a value become a 1 if you want to turn on an LED, or make the value 0 to turn it off. However, If the command is not desired to repeat over and over, you should add a field that I call a Confirmation Flag that the Spinerette can then toggle OFF after it successfully executes the command. For example.
1. A page with some buttons on it can be loaded by a user, pressing a button sends an update to the database and modifies a field with a command value. It also sets the CONFIRM flag to 1 so that the Spinerette will know there is data available for use. Sort of a flow control.
2. Spinerette reads DB and checks to see if the Confirm Flag has been to 1 = DATA READY( this could be as simple as the remote page setting the flag to a 1 if there was new data or commands added to the DB.
3. If the Flag is a 1, meaning new data or commands posted, the Spinerret will then parse the commands and do what it should do based on the command
4. After doing the command, the Spinerette accesses a page I call CONFIRM.php. This page will then reset the Confirm flag to a 0 so that A. The remote user can know if the command has been executed, and B. The Spinerette does not keep repeating the same command over and over again.
5. A Status page can be set up that reads the CONFIRM flag and shows the status of the command. Continuous refreshing will eventually show the flag set back to 0, meaning the command was executed.
Bookmarks