Christmas brought its usual share of surprises and among them this year was an Elektor kit for a USB weather station (Yes my parents know me well ;).
This kit includes great sensors for temperature, pressure and humidity. It is designed to run on batteries for a very long time and you can plug it on your computer to download the data and plot them.
This is all very cool but in 2013, I really expect my weather station to upload it’s measures to the internet automatically. And it took about an afternoon and a $40 module to do just that …
This Elektor kit is built with thru-holes components and is very easy to build. Its architecture is described in detail in Elektor’s article (full content available online - just log in for the schematics) and is built around:
This weather logger is a great base for some fun:
Once built and powered up, I quickly discovered some serious shortcomings:
Clearly there is a better way to do this.
I had a Rovio RN-XV module lying around from my first Illumi/Loochi experiments. This module takes 3.3V and has a serial interface. Once configured properly, it can take any data received on the serial port and send it to a web server with an HTTP request.
I thought this would be perfect for this project. I would configure the wifi module to talk to a server of mine and do a very simple modification to the Atmega88 firmware so that it would send on the serial output the three measurements every minute.
Get a Rovio RN-XV module (~$35). If you already have the weather station this is the only thing you will need to buy.
This module needs to be powered with a 3.3V power supply and we will plug it to a computer to do the initial configuration.
I am assuming you have built the Elektor kit, which means you probably have a BOB-FT232R and you can use it to connect the module to your computer. If you dont, you can use any USB-serial converter as long as it logic levels are 3.3V. (You have been warned: 5V will kill the wifi module).
The connections are very simple:
Note: the pin numbers for the RN-XV start at top-left corner in the datasheet. You will only use the left side. There are no “official” pin numbers for the BOB. Since we will only use the right side, I am counting pins from the top-right.
Note: The RN-XV module can use as much as 240mA when its radio is on. The BOB provides a regulated 3.3V output that is rated for no more that 50mA. It worked very well for me but if you see the module rebooting for no reason you might need to plug the Wifly to an external regulated 3.3V power supply.
Plug the USB cable, open a serial terminal program at 9600 8 N 1 (on MacOS, I recommend the free and very nice CoolTerm). Unplug and replug the module VCC pin, you should see startup messages from the module:
WiFly Ver 2.32, 02-13-2012 on RN-171 MAC Addr=00:06:66:42:42:42 Auto-Assoc roving1 chan=10 mode=NONE FAILED *READY* *ERR WATCHDOG*Auto-Assoc roving1 chan=10 mode=NONE FAILED Auto-Assoc roving1 chan=10 mode=NONE FAILED Auto-Assoc roving1 chan=10 mode=NONE FAILED
$$$ to enter command mode (only the $ key three time; do not press enter). The module will reply with
CMD. You are now in command mode, ready to send commands.
Configure your Wifi network with the command
set wlan auth 3 (WPA1/WPA2),
set wlan ssid and
set wlan phrase. If you are using WEP, read the manual - you should not be using WEP anymore anyway.
$$$CMD <2.32> set wlan auth 3 AOK <2.32> set wlan ssid my_ssid AOK <2.32> set wlan phrase my_passphrase AOK <2.32> set wlan hide 1 AOK <2.32> save Storing in config <2.32> reboot
set wlan hide 1 will make sure that someone can not get the passphrase from the module.
save and then
reboot do exactly what they say and then you should see this:
*Reboot*.WiFly Ver 2.32, 02-13-2012 on RN-171 MAC Addr=00:06:66:42:42:42 Auto-Assoc sarfata2 chan=3 mode=WPA1 SCAN OK Joining sarfata2 now.. *READY* Associated! DHCP: Start DHCP in 2261ms, lease=864000s IF=UP DHCP=ON IP=192.168.0.50:2000 NM=255.255.255.0 GW=192.168.0.1 Listen on 2000
If you see an IP address, it means your module found your wifi network, connected to it and got a DHCP reply. This is all good.
Now we want to configure the module so that it automatically sends to a webserver everything it gets on the serial port.
First, get into command mode again (type
Connect to io.tbideas.com, use DNS to resolve the domain name and use port 80 (http).
set dns name www.sarfata.org set ip host 0 set ip remote 80
Act as an HTTP client, send a GET request to the page
set ip proto 18 set com remote GET$/weather-station/?
When the module gets something on the serial port it will wait 2000ms for more data before actually sending the data appended to the GET url. It will also add some information like the MAC address of the weather station.
set com time 2000 set uart mode 2 set option format 17
I had to limit the power of the module otherwise it takes too much current and the regulator on the weather station shuts down to protect itself which reboots the wifi module. You can set the power from 1 to 12 dBm. With 6dBm the maximum current is 175mA which is in the range supported by the regulator.
set wlan tx 6
Those last two commands are optional, I recommend you only do it when everything works well: Let the module be woken up by incoming bytes on the serial port and automatically go to sleep after 10 seconds of activity.
set sys trigger 1 set sys sleep 10
This is NOT optional - save the changes to the config and reboot!
You can make sure that things work well: when the module reboots it is not in command mode anymore. Just type a few characters at the prompt and wait 2 seconds. The module will make the HTTP request to the web server and print on the console the reply from the server.
Now we need to do a small change to the firmware of the Atmega88: we need the weather station to send its measures on the serial port every minute.
The source code is available for free from Elektor. I have hosted it on github and applied a very simple patch to do just that. My changes are very simple, you can review them on github.
You need an AVR programmer to flash the microcontroller. I am not going to describe this here, many resources are available online. Let me know in the comments if you need more help with that.
Edit the Makefile and at line 257 set the variable
AVRDUDE_PROGRAMMER to the name of your progrmamer (mine is
Run the command
make program to reprogram the firmware onto the board (You can also take the .hex file and use a graphical programmer if you are into that).
$ make program avrdude -p atmega88 -P usb -c usbtiny -B 10 -U flash:w:build/weather_station.hex avrdude: AVR device initialized and ready to accept instructions Reading | ################################################## | 100% 0.00s avrdude: Device signature = 0x1e930a avrdude: NOTE: FLASH memory has been specified, an erase cycle will be performed To disable this feature, specify the -D option. avrdude: erasing chip avrdude: reading input file "build/weather_station.hex" avrdude: input file build/weather_station.hex auto detected as Intel Hex avrdude: writing flash (8164 bytes): Writing | ################################################## | 100% 21.90s avrdude: 8164 bytes of flash written avrdude: verifying flash memory against build/weather_station.hex: avrdude: load data flash data from input file build/weather_station.hex: avrdude: input file build/weather_station.hex auto detected as Intel Hex avrdude: input file build/weather_station.hex contains 8164 bytes avrdude: reading on-chip flash data: Reading | ################################################## | 100% 15.19s avrdude: verifying ... avrdude: 8164 bytes of flash verified avrdude: safemode: Fuses OK avrdude done. Thank you.
Now, make sure the weather station still works. My patch does not change anything to the UI so it should work as before.
Power the Rovio RN-XV from the ICSP port and connect the TX pin of the weather-station to the RX pin of the RN-XV module.
Wait a minute (at most) and in your web server logs, you should see data coming in:
220.127.116.11 - - [01/Jan/2013:19:40:36 +0000] "GET /weather-station/?value=temp=212&humidity=55&pressure=10070&mac=00:06:42:42:42:42&bss=3a:42:42:42:42:42&rtc=20&bat=3074&io=520&wake=1&seq=2&cnt=1&rssi=b3 HTTP/1.0" 200 3802 "-" "-"
And this is the temperature (updated in realtime), embedded in this page with our colors!
I think this simple example proves that it is quite simple to connect your projects to the Internet! With modules like the RN-XV (Bluegiga has a similar product too) it is extremely easy to connect any microcontroller based board to a web service.
I hope you will find this useful and would be glad to help you repeat this setup. If you do not want to deploy your own webserver, you are welcome to use ours. Just send me an email with the mac address of your wifly module so that I can differentiate your requests from mine. I will forward your measurement to your own Cosm account. I could also offer to send pre-programmed Atmega88 to those of you who do not own an AVR programmer.
Let us know in the comments what you think and how we can help!