Category Archives: PHP
Web Scraping using a Microcontroller
This program connects a Wiring or Arduino module to the internet through a Lantronix serial-to-ethernet converter (Xport, WiPort, or Micro)…. When the web page comes back, it parses the page for < and > symbols, and takes the string between them. Continue reading
Network Data Logging Suite
This suite of programs takes data from a sensor and saves it to a text file on a network. Each sensor reading is time stamped. The suite illustrates the basic principles involved in sending sensor data to a networked file or database.
Continue reading
Basic XML Parsing Example
I also added lines to print the results.Instantiating the class with $xml = new xmlClass() sets up the XML parsing engine and defines handlers that will get called automatically whenever a new XML tag is encountered. You can parse either a file by using $xml->parse(“filename.xml”) or a string using $xml->parseString($someString). Continue reading
PHP to TCP Socket Form
This assumes the remote device accepts the socket connection on the port you choose to connect to.Thanks to John Schimmel for writing the code.<?php/*by John Schimmel, john.schimmel@gmail.comMay 9, 2005This script will display a html form. On submit, the form will call itself and then check to see if the form element ‘text1′ is set. If set a socket is made to the define IP address and port and the value of ‘text1′ is sent down the pipe.The socket then disconnects and the form is redisplayed with the value of ‘text1′ in the html form’s textbox.IMPORTANT: If you are using an XPORT or COBOX change the connect mode to C4so no IP address is being concatenating with the incoming message to the pic….unless you like it that way.*/$xportIP = “128.122.151.44″; //IP adddress to connect to$port = 10001; // port number of IPif ((isset($_POST["text1"])) && (isset($_POST["ip"])) && (isset($_POST["port"]))) { //if a filled textbox was submitted $data = $_POST["text1"]; $ip = $_POST["ip"]; $port = $_POST["port"]; $fp = fsockopen ($ip, $port, $errno, $errstr, 30); //open the socket if (!$fp) { //if the socket does not exist echo “$errstr ($errno)\n”; } else { //if the socket exists fputs ($fp, $data); // send the data down the hole to the other end echo “<font size=’2′ color=’navy’>Message Sent: ” .
Continue reading
TCP Socket Server in PHP
Run it locally on your own machine; don’t try it on a production server first. It has an endless loop that will keep it going until you kill the process.Thanks to John Schimmel for writing it. Continue reading