Jump to content

KenHorse

Members
  • Posts

    70
  • Joined

  • Last visited

Everything posted by KenHorse

  1. USB > serial? https://www.amazon.com/Sabrent-Serial-Adapter-Chipset-CB-FTDI/dp/B006AA04K0/ref=sxts_sxwds-bia-wc-drs1_0?cv_ct_cx=usb+ftdi&dchild=1&keywords=usb+ftdi&pd_rd_i=B006AA04K0&pd_rd_r=ddec056b-609e-486c-b2d8-d38beba84201&pd_rd_w=0Ev9e&pd_rd_wg=sCNyr&pf_rd_p=ecbfa24d-f48c-4d5c-83aa-9549f4e7c925&pf_rd_r=ENNAVCF3SFBC582P3EJE&psc=1&qid=1602268074&sr=1-1-f6b8d51f-2c55-4dc3-89ad-0c3639671b2d Works very well with minicom
  2. I've had good luck using FTDI based converters with Raspbian. I've done a few searches about actually using stream_set_blocking function but not having any luck. As I've never worked with it before, are there some examples of its implementation (as in actual code examples)?
  3. This is running Raspian Buster (Debian 10). Sorry, I didn't think the script itself was an issue but here it is: <?php include("global.php"); $senddata = "SetClock" . date("His"); $serial = serial("$senddata"); echo $serial; sleep(1); $senddata = "SetCalendar" . date("mdy"); $serial = serial("$senddata"); echo $serial; exit() //<----recently added to try to force close but no difference ?> In global.php are my serial functions function serial($cmd){ $port = "/dev/ttyUSB0"; $c = exec('stty -F '.$port.' cs8 -parenb -cstopb -echo raw speed 57600'); if(!file_exists($port)) { echo "I am not blocked!"; } else { $f = fopen($port, "w+"); fwrite($f, $cmd."\r"); while(1) { $dataOut = fgets($f); if(strlen($dataOut) > 5) { // echo $dataOut; fclose($f); break; } else { fwrite($f, $cmd."\r"); } } } return $dataOut; }
  4. I have a script that is called from crontab. : 0,5,10,15,20,25,30,35,40,45,50,55 * * * * /usr/bin/php /var/www/settime.php I checked back later and notice many instances of php running: root@mypi:~# ps aux |grep settime root 1646 0.0 0.0 1856 380 ? Ss 10:20 0:00 /bin/sh -c /usr/bin/php /var/www/settime.php root 1647 0.0 2.0 75676 19860 ? S 10:20 0:00 /usr/bin/php /var/www/settime.php root 1777 0.0 0.0 1856 352 ? Ss 10:25 0:00 /bin/sh -c /usr/bin/php /var/www/settime.php root 1778 0.0 2.0 75676 19604 ? S 10:25 0:00 /usr/bin/php /var/www/settime.php root 1898 0.0 0.0 1856 340 ? Ss 10:30 0:00 /bin/sh -c /usr/bin/php /var/www/settime.php root 1899 0.1 2.0 75676 19672 ? S 10:30 0:00 /usr/bin/php /var/www/settime.php root 1943 0.0 0.0 4396 544 pts/0 S+ 10:31 0:00 grep settime settime.php is a script that sets an external clock via /dev/ttyUSB0 Obviously I'm doing something wrong as it should run and stop
  5. Are you saying it's possible to call minicom from a script, pass it an argument and have it return data?
  6. Here's the code I'm using, which works just fine as long as serial data is returned: //***NEW SERIAL FUNCTION*** function serial($cmd) { $port = "/dev/ttyUSB0"; $c = exec('stty -F '. $port .' cs8 -parenb -cstopb -echo raw speed 57600'); if(!file_exists($port)) { echo "I am not blocked!"; } else { $f = fopen($port, "w+"); fwrite($f, $cmd."\r"); while(1) { $read = fgets($f); if(strlen($read) >5) { // echo $read; $x = $read; fclose($f); break; } else { fwrite($f, $cmd."\r"); // echo "[Error Resend]\n"; } } } $substring = substr($read,0,1); if($substring =="-"){ print"<CENTER><H2>We encountered an error when sending $read". "Please close window and try again</H2></CENTER>"; //$noDataToSend ="False"; exit(); } return $x; } BUT, if the communicated-with device doesn't respond, obviously fgets hangs. Normally I'd refer to that circumstance as a serial timeout. That's what I'm trying to get around. And I do know minicom but that's not a help in this case
  7. Doesn't that require that /dev/ttyUSB0 is opened as a socket? I don't know how to do that
  8. I have a USB to serial convertor (/etc/ttyUSB0) that I read from, using fgets. I'm looking for a way, that if nothing is received with a few seconds, the script terminates. As in a "serial timeout" Of course, fgets seems to hang forever if it never sees a EOL and I need a way around that
  9. Yes, I agree and that's why I'm here! It should work but it doesn't. and yes, I KNOW what's in $buffer as I if I place a print statement after the $buffer assignment, that line shows VERY frustrating, yes
  10. The line I posted is the contents of $buffer 20210721153256,1100,TXKEY,89790
  11. $handle = fopen("/etc/rpt.fifo", "r") or die("Unable to open file!"); $buffer = trim(fgets($handle)); $ary = explode (",", $buffer); $x = $ary[2]; print $x; flush(); pclose($handle); When I run it, it reports: Notice: Undefined offset: 2 on line 4 This is the line in /etc/rpt.fifo that is being read (there are 4 indices) 20210721153256,1100,TXKEY,89790 The error makes no sense to me but I'm no expert <g>
  12. Nope, I didn't ignore but using include introduced a different issue that was even a bigger problem for me. In any case, it is running (and yes, I do believe the shell_exec setting must be something proprietary for them. I've noticed thaat Bluehost/Hostmonster and their myriad of spinoff hosting services do kind do things their own way but I never expected this to be an issue, especially as my scripts were working fine there a while ago (but I can't say exactly what that time frame is)
  13. Thanks for the assist. Sometimes it takes a swift kick to get the brain cells working
  14. Then again, adding shell_exec=on in my php.ini fixed it....grrrrrrrr I swear I tried that before....oh well
  15. I understand that. Since clearflags.php is so small and only called from control.php, maybe the easiest solution is tol move the contents over instead of invoking a separate script....
  16. It must be as I CAN run it from the command line, no? phpinfo() doesn't report safe mode is on nor are any functions disabled
  17. I understand but why would it work on my own development server but not the hosted one, especially since safe mode isn't on and neither exec nor shell_exec are disabled_functions?
  18. If that were the case, it wouldn't work on my Debian development server nor even a Raspberry Pi (also running its version of Debian 10), no? But here's clearflags.php: <?php include("global.php"); //flag vars database entry as being sent $query = "update vars set changed = 0"; $result=safe_query($query); //flag commands database entry as being sent $query = "update commands set changed = 0"; $result=safe_query($query); //flag config database entry as being sent $query = "update config set changed = 0"; $result=safe_query($query); //flag config database entry as being sent $query = "update remote set changed = 0"; $result=safe_query($query); ?> global.php contains the MySQL logon stuff as well as the function safe_query: host = 'localhost'; $user = '<user>'; $pass = '<pass>; $db = '<db>'; $charset = 'utf8'; // This part sets up the connection to the // database (so you do not need to reopen the connection again on the same page). $con= new mysqli($host,$user,$pass,$db); // check connection if ($con->connect_errno) { printf("Connect failed: %s\n", $con->connect_error); exit(); } // This function will execute an SQL query against the currently open // MySQL database. If the global variable $query_debug is not empty, // the query will be printed out before execution. If the execution fails, // the query and any error message from MySQL will be printed out, and function safe_query ($query = "") { global $con; global $query_debug; if (empty($query)) { return FALSE; } if (!empty($query_debug)) { print "<pre>$query</pre>\n"; } $result = $con->query($query) or die("ack! query failed: " ."<li>errorno=". $con->errno ."<li>error=". $con->error ."<li>query=". $query ); return $result; } I've changed the db login info in this post for security reasons of course
  19. You'll note it is being called from a webpage button, hence the reason for calling it
  20. if(isset($_POST['clearflags'])){ $output = shell_exec('php clearflags.php'); } The above works fine on my local development server running Debian 10, PHP 7.4 and Apache 2.4.25. clearflags.php is a script that clears various fields in a MySQL database so it's easy to determine if it properly ran or not. On my hosted server however (Bluehost), clearflags.php is never executed. My hosting service swears that SAFE MODE is not on in PHP (which is also Version 7.4). If I call from the command line (php clearflags.php), it runs fine. $output on the hosted server is "Content-type: text/html; charset=UTF-8 " but nothing on my local server where the script is called and runs OK. No entry appears in the error log about this I've also tried using exec() with the same failed result Running phpinfo() on the hosted server shows that disabled_functions are "no value" Thoughts?
  21. Mon Aug 24, 2020 2:41 pm I'm using php_serial.class.php, called once require_once("php_serial.class.php"); and call it $serial: $serial = new phpSerial; The above are in a global.php file that sets up the serial com parameters. In another file, I include global.php that contains my other code to send and read from the class In a function, I pass the class: Function checkInput($serial){ And one in the Function: $read = $serial->readPort(); This throws an error: "PHP Fatal error: Uncaught Error: Call to a member function readPort() on string" If I do the $read outside of the Function, it doesn't throw the error so I assume I'm doing something wrong passing the class to the function?
  22. Disregard, problem resolved. Sorry for the spam
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.