Net Data Meter
Read this article in MAKE:
11: Alt Vehicles, Page 133.
To get MAKE, subscribe or purchase single volumes.
Antique voltmeter displays current air quality from the web.
From the column DIY: Circuits
By Tom Igoe
Photos by Tom Igoe
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.
Links
Make: Noise — Discuss this article
You must be logged in to post a talkback.[ Display main threads only] [ Oldest First]
Showing messages 1 through 24 of 24.
- 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
- Finding Antique Voltmeter
You must be logged in to reply.
Flea markets? Junk shops? Old stereos? It's idiosyncratic. I got mine when my university physics dept. was throwing them out. I don't have an easy source, it just takes hunting.Posted by tigoe on September 03, 2008 at 11:43:36 Pacific Time
- Finding Antique Voltmeter
You must be logged in to reply.
Thanks. I'll keep looking.Posted by veldel37 on September 04, 2008 at 17:23:06 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
- PHP code
You must be logged in to reply.
It looks like, in copying it from my site, someone forgot the opening comment bracket at the top:
/*
other than that, it's all there.
Posted by tigoe on September 12, 2007 at 10:04:32 Pacific Time
- PHP code
You must be logged in to reply.
I mean:
Where is the opening PHP start tag
"
Posted by bartj on September 12, 2007 at 10:46:48 Pacific Time
- PHP code
You must be logged in to reply.
Why, it's before the comment tag that got cut, of course!
:)
Should look like this:
<?php
/*
Scrape AQI Page
This program reads the Air Quality index page at
http://airnow.gov/index.cfm?action=airnow.showlocal&cityid=164
and removes everything but the values for particulate air quality and ozone level. It prints those two values in the following format:
< particulate > followed by a linefeed character (ASCII 10)
< ozone > followed by a linefeed character (ASCII 10)
null character (ASCII 0)
*/Posted by tigoe on September 12, 2007 at 11:19:32 Pacific Time
- PHP code
You must be logged in to reply.
Where is the opening Posted by bartj on September 12, 2007 at 10:44:36 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
- 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
- xport http connection
You must be logged in to reply.
I seem to have struck a wall with this (at least until Tom's book arrives). I also seem to connect OK, but then I just get zero bytes back.
I've tried tweaking the XPort's connection settings to see if that would make a difference. No luck. Here's a dump of my telnet session. Does this all look OK?
Trying 192.168.1.104...
Connected to 192.168.1.104.
Escape character is '^]'.
MAC address 00204A99C617
Software version V6.1.0.0 (051122) XPTEXE
Password :---
Press Enter for Setup Mode
*** basic parameters
Hardware: Ethernet TPI
IP addr - 0.0.0.0/DHCP/BOOTP/AutoIP, no gateway set
Telnet config password set
DHCP device name : not set
*** Security
SNMP is enabled
SNMP Community Name: public
Telnet Setup is enabled
TFTP Download is enabled
Port 77FEh is enabled
Web Server is enabled
Web Setup is enabled
ECHO is disabled
Enhanced Password is disabled
Port 77F0h is enabled
*** Channel 1
Baudrate 9600, I/F Mode 4C, Flow 00
Port 10001
Connect Mode : D4
Send '+++' in Modem Mode enabled
Auto increment source port disabled
Remote IP Adr: --- none ---, Port 00000
Disconn Mode : 48
Flush Mode : 00
Terminal name: lantronix
*** Expert
TCP Keepalive : 45s
ARP cache timeout: 600s
High CPU performance: disabled
Monitor Mode @ bootup : enabled
HTTP Port Number : 80
SMTP Port Number : 25
MTU Size: 1400
Alternate MAC: disabled
Ethernet connection type: auto-negotiate
*** E-mail
Mail server: 0.0.0.0
Unit :
Domain :
Recipient 1:
Recipient 2:
- Trigger 1
Serial trigger input: disabled
Channel: 1
Match: 00,00
Trigger input1: X
Trigger input2: X
Trigger input3: X
Message :
Priority: L
Min. notification interval: 1 s
Re-notification interval : 0 s
- Trigger 2
Serial trigger input: disabled
Channel: 1
Match: 00,00
Trigger input1: X
Trigger input2: X
Trigger input3: X
Message :
Priority: L
Min. notification interval: 1 s
Re-notification interval : 0 s
- Trigger 3
Serial trigger input: disabled
Channel: 1
Match: 00,00
Trigger input1: X
Trigger input2: X
Trigger input3: X
Message :
Priority: L
Min. notification interval: 1 s
Re-notification interval : 0 s
Change Setup:
0 Server
1 Channel 1
3 E-mail
5 Expert
6 Security
7 Defaults
8 Exit without save
9 Save and exit Your choice ? 1
Baudrate (9600) ?
I/F Mode (4C) ?
Flow (00) ?
Port No (10001) ?
ConnectMode (D4) ?
Send '+++' in Modem Mode (Y) ?
Auto increment source port (N) ?
Remote IP Address : (000) .(000) .(000) .(000)
Remote Port (0) ?
DisConnMode (48) ? 00
FlushMode (00) ?
DisConnTime (00:00) ?:
SendChar 1 (00) ?
SendChar 2 (00) ?
Change Setup:
0 Server
1 Channel 1
3 E-mail
5 Expert
6 Security
7 Defaults
8 Exit without save
9 Save and exit Your choice ? 9
Parameters stored ...
Connection closed by foreign host.
Posted by cspurgeon on September 19, 2007 at 07:23:18 Pacific Time
- xport http connection
You must be logged in to reply.
Try making a test server on your laptop and setting the Xport to connect to that. That way you can see all the bytes being exchanged between server and Xport, and see if there's something missing. LIkewise, you can write a test HTTP client to see what the server's sending. It's possible there's a byte missing somewhere that one side or the other is waiting to see; either the Xport/Arduino combo isn't sending some termination that the server wants, or the reverse. I have examples of test servers and clients on my code blog at tigoe.net/pcomp/codePosted by tigoe on September 19, 2007 at 07:51:44 Pacific Time
- xport http connection
You must be logged in to reply.
Quick answer, so I don't know if I'll be able to help properly, but:
If you're seeing the CXXX.XXX.XXX.XXX/80 string a few times, that might mean that the server's responded, but the LTRX isn't properly acknowledging the connection. I seem to remember seeing this once after writing the article. I think I improved the code for the net meter in the book, which is coming soon, but I'm sorry, I forget the details at the moment. The trick is, find a way to make sure the server's not confused by extra connect strings. Might want to look at the server logs, if you can, to figure that out. The 0 returned was my clue on that. Shouldn't get that if there's no connect.
re: stringToNumber, I wrote that because the version of Arduino I was working in at the time didn't have the atoi() function in its C libraries (I wrote the article around Arduino 005 or 6, I think). It had been cut to save space on the code download. David Mellis later worked magic on the libraries, and put that function back in. So you can just use the standard C atoi() function now. You'll see that in the book too.
Anyway, hope that helps. If not, I know the longer explanation in the "Making Things Talk" book will help. Good luck!
Posted by tigoe on September 11, 2007 at 11:30: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
- Powering the XPort device via the Arduino 5V source
You must be logged in to reply.
No, the Xport's voltage regulator should be able to supply the necessary current, as long as your 9V supply supplies enough current. I recoommend something beefy, like 800mA or greater.
Also, I know the XPort docs say it can handle 5V, but I find that it tends to overheat and behave erratically on 5V, so I really recommend using a 3.3V regulator in between the XPort and the 5V.Posted by tigoe on September 05, 2007 at 03:34:36 Pacific Time
- Powering the XPort device via the Arduino 5V source
You must be logged in to reply.
Ooh, that's good to know about the voltage! The device I'm building will run unattended for long periods, so I'll definitely toss in a voltage regulator. The 9V power supply I'm using to power the Arduino claims to be 800mA, so we'll see if the 3.3V output has enough oomph. Thanks again!Posted by cspurgeon on September 05, 2007 at 09:04:11 Pacific Time
- Powering the XPort device via the Arduino 5V source
You must be logged in to reply.
Sorry, could you be a bit more specific!?! I'm new to all this malarkey and I'll need to try to track down the part online. As it is, I think I'm going to order the bits and pieces from US websites and get them shipped to the UK.
Cheers
awPosted by AndrewWestley on September 08, 2007 at 13:09:29 Pacific Time
- Powering the XPort device via the Arduino 5V source
You must be logged in to reply.
Specific about which part? the 3.3V regulator? I use the LM7833, which I usually order from Sparkfun, but there are several others you can use.
If you're interested in a more basic guide, I can recommend a book on it:
http://tinyurl.com/ytgy2t
:)Posted by tigoe on September 10, 2007 at 09:21:11 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
- Help w/ scaling
You must be logged in to reply.
2 things to keep in mind:
1. The meter's physical movement in response to PWM is not exactly linear.
2. I am not an engineer, nor a very good mathematician. I messed with the formula until I was happy with the aesthetics of the meter movement.
I didn't take a mathematical approach to it. I tried a few different formulae across a few different inputs until I got one that looked right on my meter. It's likely going to look different on your meter, particularly if yours is an antique like mine. So I suggest taking an experimental approach to the formula. Mess around until it looks the way you want it to. You can test it by sending in different values from the PHP script. Then when you know what you like, let the real values come in from the AQI page.Posted by tigoe on August 27, 2007 at 19:34:53 Pacific Time
- Help w/ scaling
You must be logged in to reply.
Great, Tom. Thanks for taking the time to read and answer my question. I particularly like "messed with the formula until I was happy with the aesthetics of the meter movement". Suits me to a T. Can't wait to get my Ardi in the mail.
-StevePosted by geobarefoot on August 28, 2007 at 09:18:38 Pacific Time
- 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
- Which Lantronix product?
You must be logged in to reply.
I tend to get part number XP1001001-03R from www.semiconductorstore.com, and an Rj-45 breakout board from SparkfunPosted by tigoe on August 21, 2007 at 10:30:38 Pacific Time
- Which Lantronix product?
You must be logged in to reply.
Got it. Thanks Tom!Posted by cspurgeon on August 21, 2007 at 16:49:23 Pacific Time
|
Showing messages 1 through 24 of 24. |
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.
Explore More in Make Magazine
Search the pages of MAKE
Raves for MAKE!
“Now we've got geek DIY (do it yourself) porn. Just as would-be Emerils pore over lushly illustrated cookbooks with recipes involving hard-to-find morels and complicated instructions for roux, Tom Swift wanna-bes are devouring MAKE.”
— Steven Levy, Newsweek
“...O'Reilly Media recently launched what has already become the bible of this new movement, a magazine called MAKE.”
— Daniel Roth, FORTUNE
“If you're the type who views the warnings not to pry open your computer as more a challenge than admonition, MAKE is for you.”
— Rolling Stone
“One of the most innovative magazines I've seen in a long time.”
— Steve Riggio, CEO Barnes & Noble
“The kind of magazine that would impress MacGyver”
— Marcus Chan, San Francisco Chronicle





