AVR web server and web client, stack 3rd generation
The different examples and applications in this package are:
- basic_web_server_example.hex -- Example for a web server
- test_readSiliconRev.hex -- Example for a web server, prints the chip revision of the ENC
- eth_rem_dev_tcp.hex -- You can switch a relay on or off a relay via a web-page or via a small udp application (see directory udpcom). The relay is connected via pin PD7.
- test0.hex -- microcontroller test, causes an LED on PIN PB1 to blink
- test_emailnotify.hex -- send email notifications when you connect PD6 to GND. You need a tuxgraphics microcontroller mail account to use this. There is a timeout of 3min to prevent too many mails.
- test_twitter.hex -- post a message on twitter. To trigger the posting of a message you connect PD6 to GND. You need a twitter account to use this. There is a timeout of 3min to prevent too many posts. Note that twitter ignores repeated identical posts.
- test_identi_ca.hex -- post a message on identi.ca. To trigger the sending of the message connect PD6 to GND. You need a identi.ca account to use this. There is a timeout of 3min to prevent too many posts.
- test_web_client.hex -- a web client that uploads data to http://tuxgraphics.org/cgi-bin/upld when you ping it once.
For more detailed documentation see http://tuxgraphics.org/electronics/
A description of the different source code files and their dependencies can found in WhatIsWhat.htm
All parts needed to build this AVR ethernet solution can be ordered from
http://shop.tuxgraphics.org/.
You can also order the email account which you need for the test_emailnotify
application from the tuxgraphics online shop.
Copyright of the software and all diagrams: Guido Socher, tuxgraphics.org
License for everything: GPL V2
See http://www.gnu.org/licenses/gpl.html
Other licenses are available on request.
!! READ THIS FIRST !!
---------------------
! Edit the file main.c and change the lines:
! static uint8_t mymac[6] = {0x54,0x55,0x58,0x10,0x00,0x29};
! static uint8_t myip[4] = {10,0,0,29};
In case of the web client applications (test_web_client.c and test_emailnotify.c)
you will in addition need to edit the following lines:
! // IP address of the web server to contact (IP of the first portion of the URL):
! static uint8_t websrvip[4] = {77,37,2,152};
! // The name of the virtual host which you want to contact at
! // websrvip (hostname of the first portion of the URL):
! #define WEBSERVER_VHOST "tuxgraphics.org"
! // Default gateway. The ip address of your DSL router. It can be set to the same as
! // websrvip the case where there is no default GW to access the
! // web server (=web server is on the same lan as this host)
! static uint8_t gwip[4] = {10,0,0,2};
!
Check the file "Makefile" and make sure the MCU is set correctly:
! MCU=atmega168
! DUDECPUTYPE=m168
! or
! MCU=atmega88
! DUDECPUTYPE=m88
! or
! MCU=atmega328p
! DUDECPUTYPE=m328
The code for a web server only fits into an atmega88 chip but
a combined web client and web server needs a atmega168 or atmega328p.
To fit web server only applications into an atmega88 you need to
compile web server only applications without linking the , in this case
useless, client code:
Example for eth_rem_dev_tcp.hex:
Edit ip_config.h . Uncomment WWW_client
Run
make eth_rem_dev_tcp.hex
to compile (you will see that the total size will be below 8kb)
For the first device you build you will not need to change the mymac line.
But you will probably need to change the IP address (myip). myip must be a
free address from the address range in your home network.
There is a range of private addresses (not routed on the public internet)
which you can use:
Netmask Network Addresses
255.0.0.0 10.0.0.0 - 10.255.255.255
255.255.0.0 172.16.0.0 - 172.31.255.255
255.255.255.0 192.168.0.0 - 192.168.255.255
Example: you wlan router might have 192.168.1.1, your PC might have
192.168.1.2. This means you could e.g use 192.168.1.10 and leave some
room for more PCs. If you use DHCP then make sure that the address it not
double allocated (exclude it from the DHCP range).
You need an avr-gcc development environment in order to compile this.
See http://tuxgraphics.org/electronics/200901/avr-gcc-linux.shtml
To compile the final software use the command:
make
Note: windows users may use and modify the supplied winmake.bat to setup the
environment correctly.
The above command will compile the following hex files:
basic_web_server_example.hex test0.hex test_readSiliconRev.hex
eth_rem_dev_tcp.hex test_web_client.hex
The command
make load
will execute the avrdude command to load the eth_rem_dev_tcp.hex software (remote relay
switch on/off software).
E.g something like:
avrdude -p m88 -c stk500v2 -e -U flash:w:eth_rem_dev_tcp.hex
To load any of the other software you can either execute the needed
avrdude command manually or use the load targets defined in the Makefile
which is load_ and then the name of the hex file without the .hex:
e.g
make load_test_web_client
Note your programmer might interfer with the enc28j60! For the avrusb500
with 30cm cable you can normally leave the cable on. For all other programmers
it is however saver to remove the programmer cable and power down/up the device.
This is because the SPI interface is used for loading of the software and
communication to the enc28j60.
To see a list of all possible build targets run the command:
make help
Selecting the right clock source
--------------------------------
Tuxgraphics hardware sold as of march 2007 is prepared to use the clock
signal from the enc28j60. To use this you need to change the
low fuse byte once from 0x62 to 0x60:
avrdude -p m88 -c stk500v2 -u -v -U lfuse:w:0x60:m
or
avrdude -p m168 -c stk500v2 -u -v -U lfuse:w:0x60:m
or
avrdude -p m328 -c stk500v2 -u -v -U lfuse:w:0x60:m
or just type in your Linux shell:
make fuse
After programming the fuse settings of atmega168 and atmega88 should be:
low fuse: 0x60
high fuse: 0xdf
ext. fuse: 0x01
For the atmega328p the hfuse and efuse bytes look slightly different.
The idea is however the same. Just change the lfuse from factory default
to 0x60. The fuse settings of the atmega328 are after programming:
lfuse reads as 0x60
hfuse reads as 0xD9
efuse reads as 0x07
details of the lfuse bits:
CKDIV8 = 0
CKOUT = 1
SUT1 = 1
SUT0 = 0
CKSEL3 = 0
CKSEL2 = 0
CKSEL1 = 0
CKSEL0 = 0
If you are unsure what the current fuse setting are on the atmega
then you can read the fuse settings with a command like:
avrdude -p m168 -c stk500v2 -v -q
The result should be this (default factory settings for atmega168):
avrdude: safemode: lfuse reads as 62
avrdude: safemode: hfuse reads as DF
avrdude: safemode: efuse reads as 1
The result should be this (default factory settings for atmega328p):
avrdude: safemode: lfuse reads as 62
avrdude: safemode: hfuse reads as D9
avrdude: safemode: efuse reads as 7
Compiling on non-Unix systems
-----------------------------
Please use the provided Makefile !!!
It will also work under Windows except for the loading
of the software. That is compiling will work but not
"make load". Use then whatever tools and commands to download
the resuting .hex file into the micrcontroller
Take also a look at the supplied winmake.bat file. This bat script
might be needed to set the environment correctly.
Using test_twitter to send messages to twitter
or using test_indenti_ca to send a message to indenti.ca
----------------------------------------------
The twitter example is test_twitter.c The identi.ca file
is test_indenti_ca.c
You need to edit the file.
You need to change myip and gwip as described above and then
change this:
1) at this moment there is no DNS lookup support
You need to actually hardcode the IP of one of the many
twitter servers. There are plans to improve this.
// IP of one of the twitter.com servers:
static uint8_t websrvip[4] = {128,121,146,228};
// IP of the identi.ca pool:
static uint8_t websrvip[4] = {75,101,154,158};
2) Username and password of your twitter account need to
be encoded in a special way. Go to
http://tuxgraphics.org/~guido/javascript/base64-javascript.html
and enter "username:youpassword"
after that replace this "ZABcdefghijklmnop12345==" with your string:
#define BLOGGACCOUNT "Authorization: Basic ZABcdefghijklmnop12345=="
This base64-javascript encoder can also be found in the subdirectory "files".
3) Scroll further down into the code and look for:
urlencode("Test of tuxgraphics eth board",&(statusstr[7]);
This is the status update that the ethernet board will send.
You can change it. There is a 40 char limit but you could change the
definition of statusstr.
4) compile with
make test_twitter
or
make test_identi_ca
and download make test_twitter.hex to the board.
5) Connect PD6 to GND and watch your profile on twitter/identi.ca
Using test_emailnotify to receive email notifications
-----------------------------------------------------
To use this software you need to:
1) order a microcontroller email account at shop.tuxgraphics.org
2) edit test_emailnotify.c and search for the string gus123. Replace
this string by the microcontroller email account ID that you received.
Edit also the IP addresses as described at the beginning of this file.
3) edit the Makefile and uncomment the line
EMAIL=haveaccount
4) run make to compile the software
5) load the test_emailnotify.hex into the microccontroller
6) Connect PD6 with GND for a moment and ... you will get an email sent to
the email address specified in your tuxgraphics microcontroller email account.
The destination email address is specified in the email account
and not in the test_emailnotify software to prevent SPAM and abuse.
UDP
---
The programs test_readSiliconRev and eth_rem_dev_tcp can
also be used via UDP. All programs have a web interface.
---------------------------------------------------------
The test_readSiliconRev.c (compiles to load_readSiliconRev.hex) reads
the enc28j60 silicon revision and displays it.
You can use it as a base for a simple application
where you want to just read data (e.g thermometer)
make
make load_readSiliconRev
Read via udp:
udpcom ver 10.0.0.24
will answer:
II: data: ver, ip: 10.0.0.24 port: 1200
OK: 10.0.0.24: ver=4
Read via webbrowser:
http://10.0.0.24
will display a webpage with:
ENC28J60 silicon rev is: 4
Using the eth_rem_dev_tcp with UDP
------------------------------
The only supported useful function in this release is to switch on or
of the transistor connected to PD7.
The command to switch on is: t=1
The command to switch off is: t=0
Query the status: t=?
The udpcom syntax is: udpcom password,X=Y IP-addr
Here is an example:
./udpcom/unix/udpcom secret,t=0 10.0.0.24
II: data: secret,t=0, ip: 10.0.0.24 port: 1200
OK: 10.0.0.24: t=0
./udpcom/unix/udpcom secret,t=1 10.0.0.24
II: data: secret,t=1, ip: 10.0.0.24 port: 1200
OK: 10.0.0.24: t=1
./udpcom/unix/udpcom secret,t=? 10.0.0.24
II: data: secret,t=?, ip: 10.0.0.24 port: 1200
OK: 10.0.0.24: t=1
./udpcom/unix/udpcom secret,t=0 10.0.0.24
II: data: secret,t=0, ip: 10.0.0.24 port: 1200
OK: 10.0.0.24: t=0
./udpcom/unix/udpcom secret,t=? 10.0.0.24
II: data: secret,t=?, ip: 10.0.0.24 port: 1200
OK: 10.0.0.24: t=0
Messages form a Network analyser
--------------------------------
traffic_*.txt and traffic_*.cap files in the subdirectory "files" are
decoded and binary messages from wireshark.
Revision history
----------------
2009-05-05: version 3.2 -- first version of the new stack.
2009-05-18: version 3.3 -- get rid of avr_compat.h, add twitter and identi.ca, added a description of the files in WhatIsWhat.htm
2009-06-02: version 3.4 -- added make targent "main" to compile eth_rem_dev_tcp.hex
updated delay functions.
vim:sw=8:ts=8:si:et