Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions PHP_files/add.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<body bgcolor='#E6E6E6'>
<?php
/*$_POST['IP']='1';
$_POST['name']='test';
$_POST['loc']='test';*/
class MyDB extends SQLite3
{
function __construct()
{
$this->open('ESP8266.db');
}
}

$db1 = new MyDB();
if(!$db1){
echo $db1->lastErrorMsg();
} else {

$sql = "INSERT INTO nodes (IP,Name,Location) VALUES('".$_POST['IP']."', '".$_POST['name']."',' ".$_POST['loc']."');";
$ret = $db1->exec($sql);
if($ret) { echo "insert success<br>";} else {echo "failed";}


$db1->close();
$chipIP = $_POST['IP'];
$fh = fopen('controllerIP.txt','w');
fwrite($fh,$chipIP);
fclose($fh);
echo "IP: ".$chipIP." saved!";
echo "<META http-equiv='refresh' content='1;URL=.'>";
}

?>
37 changes: 37 additions & 0 deletions PHP_files/delete.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<body bgcolor='#E6E6E6'>
<?php
/*$_POST['IP']='1';
$_POST['name']='test';
$_POST['loc']='test';*/
class MyDB extends SQLite3
{
function __construct()
{
$this->open('ESP8266.db');
}
}

$db1 = new MyDB();
if(!$db1){
echo $db1->lastErrorMsg();
} else {

$sql = "DELETE FROM nodes WHERE IP= '".$_POST['IP']."';";
$ret = $db1->exec($sql);
if($ret) { echo "delete success<br>";} else {echo "failed";}


$db1->close();

$chipdata = file("controllerIP.txt"); // reads IP number for ESP
$chipIP = $chipdata[0];
if($chipIP==$_POST['IP']) {
$chipIP = "";
$fh = fopen('controllerIP.txt','w');
fwrite($fh,$chipIP);
fclose($fh);
}
echo "<META http-equiv='refresh' content='1;URL=.'>";
}

?>
63 changes: 62 additions & 1 deletion PHP_files/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,74 @@
<table border="0" bgcolor='#f0f0f0' cellpadding = "5" align = "center" width = "500">
<tr>
<td>
<script type="text/javascript">
function submitForm(action){
var form = document.getElementById('form1');
form.action = action;
form.method = "post";
form.submit();
}
</script>



<form id="form1">
IP <input type = "text" name="IP">

Name <input type = "text" name="name">
<br>
Location <input type = "text" name="loc">
<input type="button" onclick="submitForm('add.php')" value="Add" />
<input type="button" onclick="submitForm('delete.php')" value="Delete" />
</form>
<?php



class MyDB extends SQLite3
{
function __construct()
{
$this->open('ESP8266.db');
}
}
$db = new MyDB();
if(!$db){
echo $db->lastErrorMsg();
} else {
// echo "Opened database successfully\n";
$query = "CREATE TABLE IF NOT EXISTS nodes (IP TEXT, Name TEXT, Location TEXT)"; $db->exec($query);
$sql =<<<EOF
SELECT * from nodes;
EOF;

$ret = $db->query($sql);
// echo "Operation done successfully\n";

}

echo "<center>";

echo "<BR>";
$chipdata = file("controllerIP.txt"); // reads IP number for ESP
$chipIP = $chipdata[0];
$uploadfiles = scandir("./filebin"); // reads the /filebin dir and puts all files in an array.
echo "<form action='writeIP.php' method='post'>"; // writes updated IP
echo "Target Controller IP: <input type='text' name='chipIP' value='$chipIP' size='11'>&nbsp;";
echo "Target Controller IP: ".$chipdata[0]."<br>";

echo '<select name="chipIP">';

echo "<option selected=".$chipIP."value=". $chipIP.">".$chipdata[0] . "</option>";
while ($row = $ret->fetchArray(SQLITE3_ASSOC)){

echo "<option value=" . $row['IP'].">" . $row['IP']." " .$row['Name'] . "</option>";
}
echo '</select>';





echo "<input type='submit' value='Update'>";
echo "</form>";
echo "<BR>";
Expand Down Expand Up @@ -82,5 +142,6 @@
</tr>
</table>
<center> <font color = "#b0b0b0"> Bruce Reagan &copy; 2015
<center> <font color = "#b0b0b0"> Sqlite additions Jim Meyer &copy; 2017

</html>
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ Files in the Lua_files folder (4) should be uploaded to a freshly formated ESP82
init.lua should be edited to reflect your LAN SSID and Password settings.

PHP files should be uploaded to a web server on the common LAN with the ESP.

Added a sqlite database to store IP addresses, Name, and Location of each device.

sqlite3 and php-sqlite3 required.