-
Posts
24 -
Joined
-
Last visited
Everything posted by ebolisa
-
I just want to read mqtt data when I'm refreshing the page. So, it's not a long term-process.
-
Hi, The code below fails with error and I just cannot understand what's causing the issue. So, I really appreciate some help. TIA <?php require("phpMQTT.php"); $server = "server.com"; // change if necessary $port = 1883; // change if necessary $username = ""; // set your username $password = ""; // set your password $client_id = "MqttClient-client"; // make sure this is unique for connecting to sever - you could use uniqid() $mqtt = new phpMQTT($server, $port, $client_id); if(!$mqtt->connect(true,NULL,$username,$password)){ echo "Connection error!"; exit(1); } else { echo "Connected!"; echo "<br>"; } //currently subscribed topics $topics["casa/rp2/soil/moist"] = array("qos"=>1, "function"=>"procmsg"); $mqtt->subscribe($topics, 1); while($mqtt->proc()){ } $mqtt->close(); function procmsg($topic,$msg){ echo "Msg Recieved: $msg"; } and lib's line 289 is
-
http://localhost loads fine as it's running on port 80 and using php 7.4 http://localhost:8080 fails (as mentioned above) as it is using php 8.1 Thank you.
-
Hi I just installed 8.1 on my Raspberry Pi and when I run a test, the code is not processed in my browser. Where did I go wrong? BTW, 7.4 is still resident. I appreciate some guidance. TIA code added in apache's default.conf: <VirtualHost *:8080> <FilesMatch ".+\.ph(ar|p|tml)$"> SetHandler "proxy:unix:/run/php/php8.1-fpm.sock|fcgi://localhost" </FilesMatch> </VirtualHost> code in test file: <?php echo "Hello world"; echo '<br>'; echo '<br>'; echo 'Local datetime is: '; echo date('Y-m-d H:i:s'); phpinfo(); ?> test shown in browser: '; echo ' '; echo 'Local datetime is: '; echo date('Y-m-d H:i:s'); phpinfo(); ?>
-
😄Thanks!! I realized what happened to the code when I ran the URL.
-
It deletes the file shown below which I call once the new firmware (https://www.mysite.net/ota/delete_ESP_data.php?file=program.py) is downloaded and stored on the microcontroller. <?php $file = $_GET['file']; $dir = getcwd(); $file = $dir.'/'.$file; unlink($file); ?>
-
I see the content of the file: https://www.mysite.net/ota/get_ESP_data.php?file=program.py
-
A new firmware is stored on my ISP. The microcontroller is using micropython to request and download, through the php code, the new firmware. My concern is if the php code is hacakble to a pont to modify my firmware code.
-
The microcontroller code checks for updates, every so often. If a new firmware is available, it's downloaded. I was wondering if any risks can exist by someone hacking the firmware code which is in Python and stored on a public web site "https://mysite.net/iot/".
-
Hi, I'm using the code below to retrieve a file into a microcontroller running micropython. I understand I'm open for easy attacks so, I appreciate some inputs. TIA <?php $file = $_GET['file']; $dir = getcwd(); $file = $dir.'/'.$file; $myfile = fopen($file, "r") or die("FAIL"); echo file_get_contents($file); fclose($myfile); ?>
-
Could you give me a hint on how to do that, please.
-
I understand, but I need to automate the process for my IOT projects 🤔
-
Yes, I have phpMyAdmin access but only once logged in their system. Do not have access to it directly.
-
<?php include 'db_conn.php'; // Keep this API Key value to be compatible with the ESP32 code provided in the project page. If you change this value, the ESP32 sketch needs to match $api_key_value = "myKey"; $api_key = $board = $ip = ""; //printf('<pre>Contents of $_POST %s</pre>', print_r($_POST, true)); if ($_SERVER["REQUEST_METHOD"] == "POST") { //printf('<pre>Contents of $_POST %s</pre>', print_r($_POST, true)); //var_dump($_POST)."<br>"; $api_key = test_input($_POST["api_key"]); //printf('<pre>Contents of $api_key: %s</pre>', print_r($api_key, true)); if($api_key == $api_key_value) { $ip = test_input($_POST["ip"]); $board = test_input($_POST["board"]); $uptime = test_input($_POST["uptime"]); $temp = test_input($_POST["temp"]); $conn = OpenCon(); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } else { //echo "Connected!"."<br>"; } $sql = "INSERT INTO washupips (board, uptime, temp, ip) VALUES ( '" . $board . "', '" . $uptime. "', '" . $temp . "','" . $ip . "')" ; //printf('<pre>Contents of $sql %s</pre>', print_r($sql, true)); if ($conn->query($sql) === TRUE) { echo "New record created successfully"; } else { echo "Error: " . $sql . "<br>" . $conn->error; } $conn->close(); } else { echo "Wrong API Key provided."; } } else { echo "No data posted with HTTP POST."; } function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } ?> Ok, I see the confusion, perhaps bridge is not the right definition in English. Normally, to store data to a DB we access it via an IP, no matter where that location is. In my case and for security reasons, the IP is not accessible via the Internet, but it's accessible via a web server since both servers are in the same ISP's network. So, I'm using a "bridge" to hop from the ISP's web server to the DB server as shown in the above code.
-
Hi, My ISP doesn't allow direct access to mysql Server so I created a bridge and stored the PHP code in the main web folder (https://www.mydomain.com/post.php). The bridge works fine and is used mainly for my IOT projects. In the same web folder, is located the conn.php code containing the server's credentials. The question is, how safe is the PHP code at that location? I can create a subfolder but not sure if it matters as far as security is concerned. TIA
-
Hum, If I comment line 3, it fixes the issue.
-
Hi, I've a simple code which uses a class from here. When I execute it, I get this error and I cannot understand why my code doesn't see the class. Both files, the class.php and test.php, are in the same folder. Any help is appreciated. TIA <?php require("phpMQTT.php"); $server = "192.168.0.250"; // change if necessary $port = 1883; // change if necessary $username = ""; // set your username $password = ""; // set your password $client_id = "phpMQTT-publisher"; // make sure this is unique for connecting to sever - you could use uniqid() $mqtt = new phpMQTT($server, $port, $client_id); if ($mqtt->connect(true, NULL, $username, $password)) { echo 'hereeeee'; $mqtt->publish("room/lamp", "on" . date("r"), 0); $mqtt->close(); } else { echo "Time out!\n"; } ?>
-
Ok, found the solution. Thank you. <div class="field"> <label for="ck1">Activa</label> <input name="ck1" type="checkbox" value = 1 <?php echo ($status=="1" ? 'checked' : '');?> /> </div>
-
In my first post you can see the php If statement within the form code.
-
Ok, so how do I include an If statement within a form code?
-
Modified a bit the code but still no avail... <?php if ($status == 1){ echo '<input name="ck1" type="checkbox" value='.$status.' checked >'; } else { echo '<input name="ck1" type="checkbox" value='.$status.' >'; } ?> The html output is this... <div class="field"> <label for="ck1">Activa</label> <input name="ck1" type="checkbox" value=0 > </div>
-
Yes, remains unchecked. It always sends out 0 instead of 1 when checked. I noticed that the double quotes remain around the word checked. Is I remove them, it works.
-
Hi, I'm trying to check a box in a form based on the $status variable read from a json file. If it's a 1 then the checkbox is checked, otherwise not. If I check/uncheck it, then the $status is written back to the json file. It's a rather simple code but I just cannot get it right. I appreciate any help. TIA <div class="field"> <?php if ($status == 1){ $checked = "checked"; } echo '<input name="ck1" type="checkbox" value='.$status.' '.$checked.' >'; ?> <label for="ck1">Active</label> <!-- <input name='ck1' type='checkbox' <? if $status : "checked" ?> value = "<?=$status ?>" /> --> </div>
-
Hi, In the following code I'm using a combo box to select a relay and activate it. The code works but if I refresh the page, the last selected relay is activated again. How can I reset the page to default to value '0' which has no relay control? TIA <!DOCTYPE html> <html> <head> <title>Relay control</title> <meta content="text/html; charset=utf-8" http-equiv="Content-Type" /> <meta name="apple-mobile-web-app-capable" content="yes" /> <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" /> <link rel="stylesheet" type="text/css" href="style.css" /> </head> <body> <h2><center>Status y control de relés</center></h2> <?php $arrleds = array(); if ($_SERVER["REQUEST_METHOD"] == "POST") { $selected_val = $_POST['sel']; if ($selected_val == '1'){ $cmd = exec("sudo ./trigger.py b 0"); } elseif ($selected_val == '2'){ $cmd = exec("sudo ./trigger.py b 1"); } elseif ($selected_val == '3'){ $cmd = exec("sudo ./trigger.py b 2"); } .... else {} } ?> <table class="center"> <tr> <td></td> <td><h1>Activación de relé</h1> <form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post"> <select name='sel' onchange='submit();'> <option value='0'>Sin activar</option> <!-- no action --> <option value='1'>Secadora 1</option> <option value='2'>Secadora 2</option> <option value='3'>Lavadora S</option> .... </select> </form> </td> <td></td> </tr> <tr> <td></td> <td><a href="index.php">Home</a> <td></td> </tr> </table> </body> </html>