This program connects a Wiring or Arduino module to the internet through a Lantronix serial-to-ethernet converter (Xport, WiPort, or Micro). The microcontroller makes a TCP connection to a web server first. Once it’s got a connection, it sends an HTTP request for a web page. When the web page comes back, it parses the page for < and > symbols, and takes the string between them. Then it converts the string to an integer. It assumes the string is made only of numeric ASCII characters (0 – 9).
This program couldn’t parse an entire web page very easily, so it’s best used in conjunction with a web scraper PHP script like this one, which reads the AIRNow site and extracts the Air Quality Index into a single string like this:
< AQI: 54>
This program was written to make an air quality index meter out of an analog voltmeter.
The electrical connections to the microcontroller are as follows:
- disconnected LED: Arduino digital I/O 6
- connected LED: Arduino digital I/O 7
- connecting LED: Arduino digital I/O 8
- requesting LED: Arduino digital I/O 9
- Lantronix module reset: Arduino digital I/O 10
- Voltmeter: Arduino digital I/O 11. The voltmeter is controlled by using pulse width modulation (analogWrite() command on the Arduino).
The web scraper is written in PHP. Its code follows below the Arduino code.
Technorati Tags: networked objects, networks
Continue reading “Web Scraping using a Microcontroller”