Digi had fixed the issues with the TCP/IP stack in the last post. I had found some time and wanted to get PowerMeter working wirelessly, using the XBEE Module. I wanted to use a DNS Server to do domain name resolution so I don’t have to hard code an IP in. My web servers IP could change. Problem is, the DNS Results from standard DNS Servers would CRASH the Xbee Module. Here is my ticket I submitted.

if PC01 sends UDP traffic to XBEE to port 0xBEF6 it appears in XBEE’s Terminal. If XBEE communicates to 4.2.2.1 (successful).. however, data is never properly returned to XBEE Terminal. At this point any other data from PC01/PC02 to XBEE is not received until XBEE changes port.

This is specifically caused by the returned data from the DNS Server. I can utilize 2 PCs and the XBEE sending/receiving data just fine. Not sure if the specific packet from a DNS Server crashes it. My Query Data packet sent to the UDP Server…

I had actually purchased a different brand module which has DNS/HTTP/NTP/etc all built in to the module. It’s the WiFly RN-171. Some reference it to be the Digi XBEE WiFi Killer. I started to use it, however, it had some of its own limitations and I can’t remember exactly what issues I was running in to. My jobs has me travel a lot, so I run in to times when I get side-tracked from my hobbies.

1/15/2013 – Ticket was closed by Digi (acknowledge problems with DNS that cannot be resolved)

After receiving mulltiple issues with DNS functionality on the current XBee WiFi module, the engineers did some more digging and found the chipset to have some DNS functionality issues that we are unable to fix.
We are, however, working on a next generation XBee WiFi that will be release in the next few months. It uses an Atheros chipset that is much more capable.

I’m not completely satisfied with their answer. The chip does not have issues with “DNS”… the chip does not know its doing a DNS queries.. the chip just knows its participating in UDP Communication. The real big question is, what other type of UDP traffic causes this chip to have problems? What type of data causes it to crash? Those would have been some good answers as a response to my ticket.

So I just bought two new XBEE WIFIs. If you’re not familure with XBEE’s they are little embedded RF Modules that provide a simple serial connection. In the past they have always been over the 802.15.4 protocol, but the new ones communicate over 802.11g/n! up to 65MBps. The new WIFI ones just came out a couple months ago, and there is little documentation online. Digi does provide a manual online.

So with XBEE’s you have Transparent AT Command Mode and API Mode. In Transparent mode you send serial ascii to both send data and must put the xbee in command mode to change any configuration items. You enter command mode by sending three consecutive +’s (“+++”). Now you can send Ascii Command’s with parameters such as “ATFR” to restart the module The more robust communication style is API Mode. In this mode you must generate XBEE API Packets at the byte level.

After configuring the XBEE in the X-CTU application to my Access Point (which it supports WPA2). It automatically DHCP’s an address.

And the problems begin…

I set the Registers for DEST_IP, DEST_PORT, SRC_PORT, PROTOCOL=TCP. After setting those registers, if I then send the module this data serial over UART it automatically creates a TCP/IP socket to the DEST_IP on SRC_PORT from DEST_PORT and sends data. It has no problem creating the Three Way Handshake, sending data over the tcp stream, or even closing the tcp stream. The problem that I have had is receiving data from the TCP Stream. In Transparent Mode it’s supposed to just come back over the UART. it’s not… It’s API Mode it’s supposed to generate a 0xB0 … it doesn’t…

I don’t understand why I’m not getting an HTTP response, I know that the web server was receiving the GET Request in both modes because it saves a msg to a log file. I unsecured my wireless network.. started up BackTrack and ran WireShark in promiscuous mode. After seeing a real TCP Socket Creation and all the correct data, yet still seing no response from the XBEE I decided to email tech support. I will admit they do respond very quickly. Although it’s like they didn’t read my question or look at my pictures.

TCP Stream between XBEE to Remote Host [Looks Good!

This is an example of me sending a GET request to my webserver, and receiving no return data. I do receive a message sent successfully message. Also, If I send it more than a couple times, it actually crashes the XBEE… not sure why the socket should have closed after the HTTP OK.

Dialog with XDIGI Support

Created 10/10/2011 23:37

Background

I’m Connecting to the XBEE via an FTDI cable connected to an Adafruit XBee Adapter Kit. I’m sending API packets from X-CTU. The same problems occur in Transparent Mode. The XBEE is connected to my wireless access point and I’ve set the router to OPEN security so I could debug the traffic. It DHCP’s the IP Address of 192.168.1.100. In Wireshark I see successful connection to the DEST IP with data coming back.

Connection Setup

I’m establishing a connection to a remote web server <4AD03B1F>(74.208.59.26) to port <0050>(80) from port <BEEF>(48879).

Problem #1) I never receive any data back in either Transparent or API Mode. I’m expecting an API packet of B0 (Rx IPV4 Packet). In wireshark I have seen TCP data being returned to the XBEE. [Attached]

Problem #2) If I try the connection again even though the webserver should have already closed the TCP Connection it crashes the XBEE. I’ve even seen the FIN, ACK in wireshark. I receive

[89] 01 03 – Transmission was purged because it was attempted before stack was up.

Data Sending [Transparent & API Mode]

GET /energy/CommitEnergy.php HTTP/1.0

Host: s157582434.onlinehome.us

//SEND Get REQUEST to Web Server

7E 00 57 20 01 4A D0 3B 1A 00 50 BE EF 01 00 47 45 54 20 2F 65

6E 65 72 67 79 2F 43 6F 6D 6D 69 74 45 6E 65 72 67 79 2E 70 68

70 20 48 54 54 50 2F 31 2E 30 0D 0A 48 6F 73 74 3A 20 73 31 35

37 35 38 32 34 33 34 2E 6F 6E 6C 69 6E 65 68 6F 6D 65 2E 75 73

0D 0A 0D 0A 0D 0A 12

10/11/2011 – 08:15 (Case Set to Presumably Fixed & Closed)

Matthew,

Thank you for contacting Digi. Try entering the port numbers in the X-CTU for the WIFI module in the Hex values. I think you will have better luck.

If there is anything else I can do for you, please let me know.

Sincerely,
Eric Flanders
Digi RF Technical Support

10/11/2011 – 09:55 (My Response to this statement)

I did use hex… I used 0x0050 for port 80, and 0xBEEF for port for 48879. I see that the XBEE is making clear connections and the webserver is sending TCP data back via Wireshark AIRMON capturing. However, no data is returned in either Tranparent Mode or API Packet B0 from the XBEE.

10/11/2011 – 10:11

Matthew,

Are you able to get it to work with the X-CTU and Hyper-terminal? Are you able to enter command mode and make changes to the radios settings?

10/11/2011 – 11:10

Yes, I can use Command Mode or API Mode to change radio settings.

In Transparent Mode I cat set the DEST in HEX, and PORT in HEX.

I am making a successful TCPIP Connection!!

The Device is doing the TCP Handshake, and TCPIPv4 Sending and in API Mode I receive a Success Message. The webserver did receive the Request because it acted on the the XBEE’s Request.

However, the XBEE is not showing me that it received the webserver’s communication back! In Transparent Mode I get nothing else in X-CTU Terminal and in API Mode I get no TCPIP Receive (B0) Packet.

10/11/2011 – 13:37 (wow.. and he got a leet time…)

Matthew,

To help narrow down the possible cause, are you able to use Hyper-terminal and X-CTU to create a connection to the radio via the PC’s COM port and the WIFI connection and then send and receive data back and forth? Keep in mind that your web server can’t do this so we are trying to take it out of the picture to see if it is an issue with it or not.

10/11/2011 – 14:59 (My Response)

Yes, I can make a connection to the XBEE over COM6.
Yes, I can connect and send TCP packets in either Transparent or API over WIFI.

However, if server sends data back, example:
TCP Packets returned from the webserver! through my router. (directed to my XBEE) they don’t appear
I know they are returned to the XBEE because I can see them from a third party wireshark sniffer in premiscuous mode..

The problem is XBEE does not aknowledge receiving TCP Packets!

Please view images from my original email, it shows a clear TCP/IP Connection to Close from XBEE to WebServer!
While Hyper Terminal or X-CTU shows ZERO data returned.Attached is another image.

10/11/2011 – 15:08

Matthew,

The radio does not accept direct TCP/IP packets. You need to create a socket to it for it to send and receive data via its WIFI ports.

10/11/2011 – 18:40

Ok… If I am sending data to a remote server over TCP/IP I am creating a socket correct? You use API “FrameType 0x20 Transmit (TX) request IPv4” to create a socket correct?

AFAIK it creates the socket automatically when you send data via the 0x20 command, am I mistaken? because that is what it is doing… and it creates a TCP Socket with 3-way hand shake and all, and sends the data….

The only problem is.. it’s not returning the received data from the TCPIP Socket to the ReadSerial with a 0xB0 API Packet.

And we wait for a response…

10/12/2011 – I was able to get the wifi expert on the phone and talked to him about the problem. He’ll be looking in to it.

10/18/2011 – Video I just created tonight to show problem.

*You’ll probably want to watch this in HD.

3/9/2012

I finally did get a response back from the DigiKey rep.

Welcome back from you deployment. The new version of the firmware fixes the TCP handling issues you were seeing.

When you are ready, just give me a call and we can continue to work on the XBee WF.

I did specifically test this. Works Fine — I was able to connect to a TCP server (e.g. webserver) and data received before timeout (connection closes) it returns the received data back to me as the end user.

Overtime I’ve wondered how much electricity am I really using, and where is it all going? I’ve always wanted a Kill-a-Watt so I could monitor different areas of my house but never bought one.
I recently ran into an old article on the Tweet-a-Watt, which was a winner of the Greener Gadgets 2009 competition. It’s a Kill-a-Watt with an XBEE in it so that it can remotely send the energy usage to another XBEE tied to your computer. It then posted your energy usage on twitter, which is less interesting to me. I was more interested in being able to view and analyze my usage at at any point of time.

First Thought – I want Kill-a-watts + XBEEs around my house
I thought it would be pretty cool to have these in different locations in my house. I want to see just how much electricity am I using leaving my i7 Desktop with 6 Hard Drives and 2 Video cards on for days at a time really used, and for that matter, costs.

My Room with my computer system.
The Living room with all of the entertainment system
My Roomate’s Room with his computer system.
First things first, cost analsys

Next Thought – We have a meter outside

Itron Electric Meter

It reads off the current KW/Hour that has run through the meter since creation and has blinking indicator and some writing on it. How do I get this data? And what data can I get? Lol – Can I just put a camera out there and OCR the images… My first thought was the CellNet protocol, I learned it operates in the non-licensed 900MHZ spectrum and probably uses FHSS. You can find their CellNet patents on their FHSS Methods. There are people, Dave’s Blog, that have gone down that road but thats too much work.

After doing a lot of google searching I found a great article, I’m not the first person with this idea. He had called an Itron Engineer, the people who made the meter, and they described two methods you can view Watt/Hour usage, which is better detail for real-time power tracking. You can also find that information from Itron’s manual.

The method I decided to go down was the IR sensor on the top of the meter that emits a 10ms pulse every time you use a Watt/Hour.

I just established a connection to my Wireless network with the XBEE. From there I was able to send an HTTP GET Request to my web server. You have to use an IP address for the connection, there is no built in DNS Resolution. In the future I may have it query a DNS Server to resolve the IP but for now I’m fine with this.

I think I’m planning on having the submission be the UNIX time stamps of the last seen Watt/Hrs. The php would then insert them into the Database. I’ll probably throw a password field in there too, incase people find the location of my CommitEnergy.php.

==10/7/2011 9:00 PM ==

I sucessfully hooked the IR Receiver up to the one of the Analog pins on the Audino. With no IR signal in the 38Hz Frequency it outputs ‘1024’. As soon as I used my remote control on the sensor it would drop down to ‘0’ for the signal pulses.

==10/7/2011 11:00 PM ==

I’m going to create a simulated bot on my computer that emulates the submissions of the Arduino.. I’m going to start working on the database backend, statistics, and the front user interface. I’m planning on using HighCharts, they are AMAZING javascript graphs. They also have the ability to add datapoints realtime using some form of AJAX.

==10/11/2011 11:00 PM ==

So this weekend I spent a lot of time coding up PHP and creating the database schema.

Simulation Applications:

Simulated Electricity: Simulates pulses to the CommitEnergy.php to add Watt/Hr Ticks as the meter does.

Past Energy: I generated a years worth of past energy that follows a set of rules with weekdays/weekends, prime time, sleep time, work time, etc… I created this so I could test the graphing, trending and stats out. I also wanted to make sure the graphs weren’t slow.

Database Structure:

WattTicks: [Time]

MinWatts: [Time, NumOfTicks] //Time is Floor(UnixTimeStamp / 60) and the NumOfTicks in that min.

HourWatts: [Time, NumOfTicks] // Time is Floor (UnixTimeStamp / 3600) and the Numof Ticks in that hour.