Vol. 11: Net Data Meter

Antique voltmeter displays current air quality from the web.

By Tom Igoe

Photos by Tom Igoe



+ Downloads & Extras:

Non-Windows Programs

Finding a Lantronix Device on a Subnet

If your router doesn't disclose the IP table, there are at least 5 ways you can discover the Xport's IP; one PC-dependent, one Mac-dependent, and 3 platform independent.

Mac-dependent: Download IPNetMonitorX and use it to ping all devices on your subnet. It won't find Xports specifically, it'll just find all active devices. Do it once with the Xport unplugged, and note all addresses active. Do it again with the Xport plugged in, and note the new address in your list. That's the Xport. NOTE: IPNetMonitorX is not free, but it is very handy software if you administer a system and work on a Mac.

PC-dependent: Download the DeviceInstaller software from Lantronix on your PC. It's free and it's designed to sniff out and configure Xports on a network. It'll find your Xport and tell you its IP and let you configure it.

Independent: Download the classes for my cobox query application. Run it. It will send out broadcast UDP packets, querying every device on the subnet. Any that are Xports or Coboxes will reply, and you'll have their IP addresses. You could also use the Processing application below, which does the same thing as the Java app. If you do use it, you'll need Processing and the UDP library from Hypermedia.

NOTE: Both my app and the installer app will return all Xport addresses. If you're on a subnet with a lot of Xports (like ITP) make sure you know the MAC address of yours, so you can identify it in the table.

Fourth method: Serially configure your Xport with a hard-coded address, e.g. 192.168.2.150. That way you'll always know. This is the easiest method.

Fifth method: Serially configure your Xport to auto-connect to another IP on the network (connectMode C5 or D5, IP address of a machine that you can run a Java app on). Run a simple server application that can tell you the address of the device that logged in; MyTcpServer will do the trick, or you can write your own. Any Java app that receives TCP connections will be able to pull out the IP address of the device connecting to it.

Code

Arduino Code

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). 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 -- the analogWrite() command on the Arduino.

The web scraper is written in PHP. Its code follows below the Arduino code.

Arduino code

PHP code. Note that this scraper is specific to the site mentioned here. You would need to modify it to scrape a different site. Learn the methods from this one, don't copy the code.

Join the conversation -- every MAKE article has an online page that includes a place for discussion. We've made these RSS and Atom feeds to help you watch the discussions: subscribe.