Updating electricity meter to communicate via WLAN using atmega

A while ago Farnell sent email to me and offered one (inexpensive) product  as a sample in exchange for mentioning it at this blog. I browsed for a while for an interesting part and settled with Microchip MRF24WB0MA/RM WiFi module (Order code 1823142). This module is quite inexpensive and is used in products like WiShield and thus has good Arduino support.

RN-XV image (c)
RN-XV image (c) Sparkfun

I wanted to upgrade my electricity meter to communicate with WLAN to get rid of XBee receiver at the back of my server. After some prototyping I ended up using RN-XV module from Roving Networks. Since my application did not have to do any fancy network stuff, RN-XV was a perfect match. It has the same footprint as XBee module, which I was already using, so the hardware required no changes. The module supports WPA2 security and can remember it’s settings. Communication via HTTP request is incredibly easy, I set up the module to generate http request to my home servers address each time when AtMega output measurement data.

Unfortunately some thing are just too good to be true. The module soon proved to be quite unreliable. Each time after about 14 hours of operation the module lost connection to accesspoint for ever. I tried to solve issue with technical support. By default if module looses AP, it does not try ever to reconnect unless linkmon parameter is specified, which to me is quite braindead default setting. Even with the linkmon RN-XV did not work for long with my Cisco AP. I tried everything including rebooting the module every hour, adding commands to force reconnect and even doing hardware reboot to the module, but without much success. Eventually I changed the RN-XV to connect to different AP. It still looses the connection every now and then but it’s able to reconnect after random time. Still in every 24 hours the module is unavailable for about total of 3 hours due to lost connections. RN-XV firmware version I have is 2.36.
In the end, only changes I made was to modify server backend to accept HTTP requests and change the code running on the AtMega to output measurement data periodically instead listening request from XBee.
The RN-XV was configured with following commands:

set ip dhcp 1  # get ip from dhcp
set wlan auth 4 # use wpa2-psk encryption
set wlan phrase password # set network password
set wlan ssid network # set the name of accesspoint to connect
set wlan linkmon 5 # After 5 tries declare connection to AP lost and try to reconnect again.
set ip proto 18 // turn on HTTP mode=0x10 + TCP mode = 0x2
set ip flags 0x6 # close tcp connection if accesspoint is lost
set ip host ip # server ip address
set ip remote 8080 # server port
set com remote GET$/? # GET string to be sent to server. Any data from uart will be concatenated to this string
set uart mode 2

All in all, for simple projects, I can really recommend the RN-XV module over the MRF24 due it’s simplicity, but definitely not for reliability. Both modules cost about the same, but apart from Sparkfun I don’t know who else has them in stock. Farnell could start selling them, since ordering from Sparkfun can get expensive if you don’t live in the states.
Sources can be found from the repository: https://github.com/JanneMantyharju/electricity-monitor

Categories: ElectronicsProgramming Tags: avrhome automationRN-XV

Monitoring electricity usage at home

05/03/2012 antibore 19 comments

I wanted to gather statistic about the electricity usage at my new house, mainly to see how much using the fireplace lowers the bill. The meter installed by the utility company has a led that blinks at the speed that is relative to the usage. Text on the meter says that 480 blinks equals 1 kWh used. I thought that building a device that keeps count of these blinks should be easy enough to make. I used photoresistor attached on top of the led with blu-tack. This way the measuring circuit is isolated from the mains and the setup doesn’t require tampering with the meter. The led on the meter is not very bright, so the circuit is quite sensitive to ambient light, but works reliably when the cabinet enclosing the meter is kept closed.


The schematic for the device is quite simple:

Schematic Updating electricity meter to communicate via WLAN

Currently I’m using XBee to communicate with the server which gathers the measurements. The meter itself is at the utility room, which is too far to run cables to. I’ve already bought XBee pinout compatible wlan transmitter to get rid of the XBee eventually.

In the circuit, analog part on the left turns value of photoresistor (R3) to digital signal read by ATtiny2313. Sensitivity of the photoresistor is changed with the variable resistor R5. The avr responds to two commands (in current code “LUKU” and “VALI” translation would be “COUNT” and “INTERVAL”). Count simply returns number of blinks since the last count command. When read periodically, electricity usage can be calculated from the number of blinks and the time used to count them. Second command returns the time between two last blinks, so current consumption can be calculated from that.

Read more: Updating electricity meter to communicate via WLAN

Leave a Comment

Your email address will not be published. Required fields are marked *