Vol. 11: Net Data Meter
Antique voltmeter displays current air quality from the web.
Digital Edition
SUBSCRIBERS:Read this article now in your digital edition!
Get Make:
Subscribe to MAKE and get the best rate!
+ Downloads & Extras:
Non-Windows Programs
Finding a Lantronix Device on a SubnetIf 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.
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.
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.
» MAKE: NOISE — Discuss this article
You must be logged in to post a talkback.[ Display full threads] [ Newest First]
Showing messages 1 through 7 of 7.
- Which Lantronix product?
You must be logged in to reply.
Looking at the Lantronix website, there are several variations in the XPort product line. Which is the (best/correct) one to get?Posted by cspurgeon on August 21, 2007 at 09:58:04 Pacific Time
- Help w/ scaling
You must be logged in to reply.
I don't own an Arduino yet, but it should be arriving any day, so this question is based a bit on ignorance:
I studied the Arduino code and I can't quite understand the conversion between AQI and voltage. The code states:
meterMax 165 (this is to peg the meter?)
meterScale 150 (meter reads 0-150...got that)
And the conversion function:
airQualityValue = desiredValue * meterMax/meterScale
So let's take an AQI of 80. According to the formula, we have 80 * (165/150) = 88, so 88 is what is sent to the meter pin. I'm sure this is where I go screwy -- Arduino can write "analog" values of 0-255 to the PWM digital ports, resulting in voltages from 0-5v. 5v/255 steps = roughly 0.02 V/step. With that logic, doesn't a value of 88 equate to about 1.75 volts, which equates to...er...about 88 on the scale? Thinking aloud here, I wouldn't expect any conversion using the given scale. An AQI of 50 unconverted and written to the meter pin as "50" (*.02 volts per step) would result in 1 volt output to that pin. Isn't that what we need? What am I missing here? I understand the concept of scaling, but I can't see how it applies here since it seems to skew the results. Thanks for the help!!Posted by geobarefoot on August 27, 2007 at 16:47:24 Pacific Time
- Powering the XPort device via the Arduino 5V source
You must be logged in to reply.
OK, I've almost got this puppy working. I'm powering the Arduino board via an external 9V power supply, and I was hoping I could then use the board's 5V power source to power the XPort (the XPort documentation says that while it calls for 3.3V power supply it can handle 5V) but when I connect it to the Arduino's 5V it doesn't seem to work. (The XPort *does* work if I drive it with a couple of AA batteries as the power source). Does the Arduino's 5V source just lack the power to run the XPort?
Posted by cspurgeon on September 05, 2007 at 01:12:18 Pacific Time
- xport http connection
You must be logged in to reply.
First, thanks for this article. I've been wanting to do this since I first saw Tom's email clock.
I'm having trouble with my xport HTTP connection. After reset, the arduino/xport will attempt to connect with the connection string "C255.255.255.255/80" (with my IP address). This is all that will happen - it seems to stall out here. To overcome this I have added some code in the (status==connecting) block:
if (inByte == 68) { // 'D' in ascii, disconnected
status = disconnected;
blink(3);
}
if (inByte == 78) { // 'N' in ascii, host unreachable
status = disconnected;
blink(4);
}
This code says to start completely over if anythig besides a "C" is returned from the xport.
With this code after reset, I get the following in arduino's serial monitor:
C63.247.90.194/80
C63.247.90.194/80
GET /physical-computing/index.php HTTP/1.1
HOST: www.markroland.com
I got 3 bytes, total: 0 string: 128
which is exactly what I want, however upon the next connection things start to go haywire:
C63.247.90.194/80
C63.247.90.194/80
C63.247.90.194/80
GET /physical-computing/index.php HTTP/1.1
HOST: www.markroland.com
I got 0
There is nothing fancy going on with the PHP script, in fact all it does is echo "< AQI: 128>".
The arduino code I'm using is posted here
Using xport's web manager (not via telnet or serial as discussed in the article) I have set the xport's
Channel 1 > Connection:
Active Connection = Manual Connection
Connect Reponse = Char Response
Hard Disconnect = No
I could use help understanding why the HTTP request works reliably the first run through the code but becomes unpredicatable after that. Ultimately I would like to use this setup to use a query string to save information to a MySQL database as frequently as possible.
Final note: The arduino code posted on this page for Make does not include the function "stringToNumber" however I found it over on Tom's site, however on this code watch out because the HTTP request's new line characters aren't escaped! :)
Okay, I realize that's a lot, thanks for any help!Posted by uci_acer on September 11, 2007 at 10:58:46 Pacific Time
- One thing to try if you can't see the XPort on your network
You must be logged in to reply.
Just want to say that if you're assigning (or attempting to assign) an IP address to your XPort dynamically via DHCP, it's good to have a little patience. In my setup it can take a good 30 seconds after power-up before the XPort has an IP and is visible on the network. Before I realized that I spent a bit of frustrating time powering things up, immediately checking for the device on the net, not finding it, cursing, powering everything down, rechecking my circuits and connections and then powering up and trying again.Posted by cspurgeon on September 11, 2007 at 18:15:51 Pacific Time
- PHP code
You must be logged in to reply.
Hi, I am a novice to PHP, but it appears that the posted PHP code is incomplete?
Thanks!Posted by bartj on September 12, 2007 at 09:28:13 Pacific Time
- Finding Antique Voltmeter
You must be logged in to reply.
Where can I look for an antique/old voltmeter? I tried Ebay and Google but neither yielded anything too promising. Any ideas would be appreciated.
VelinPosted by veldel37 on September 02, 2008 at 19:47:13 Pacific Time
|
Showing messages 1 through 7 of 7. |
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.










