AVR NET-IO from Pollin
In order to collect and send the water counter signals with an Inductive Proximity Switch to the volkszaehler data base, the kit AVT NET-IO from company Pollin is used.
The control of the water flow is shown on this page.
The reasons for using it, is low cost (about 20 + 6.5 EUR plus shipping), and there is already a volkszaehler compatible software provided. You have to take care to also order a MPU (ATmega644, 6.5 EUR) with more flash ROM (64 KB), which is needed for the volkszaehler application, and allows a reprogramming via network.
The update of the application program is done via network with a local TFTP server (Linux tftpd).
Because of easier troubleshooting, it is better to include the unix timestamp [ms] with the S0 data.
AVR NET-IO setup
When building up the kit, it is recommended to put on each logic chip a .1 uF ceramic bypass capacitor at the power supply pins, see at Links (Improvements), and the picture on the right (click to enlarge). That will improve the noise immunity.
Instead of using a 9 Vac power supply, I replaced the 7805 voltage regulator and the rectifier diodes by 3 jumpers, and soldered at the power supply pins a connector for a 5 V, 500 mA switching power supply. The connector has a hole for a pin diameter of 2.1 mm.
The reason is to save energy and heat on the board (regulator). The other benefit is to have a coding for the polarity of the supply voltage. If you need to make a Reset on the CPU, you can just pull the plug and reinsert.
.
See the picture on the right (click to enlarge) for the jumpers and the plug.
The housing used, is a EUROBOX in yellow, bought from company http://reichelt.de for 3,10 EUR, see the picture on the right (click to enlarge). Because the mounting holes of the housing box does not fit the mounting holes of the AVR NET-IO board, an epoxy board was mounted as an adapter.
For more build up possibilities (LCD, etc.), please see at housing for AVR NET-IO.
In order to quick check the good function of the assembled board, make a ping to the board, connected to the network. If the segment addresses of your local network is not the same as of the AVR NET-IO (in my case: 192.168.17.x, 192.168.0.90), set the net mask of your computer to 255.255.0.0.
$ ping 192.168.0.90 PING 192.168.0.90 (192.168.0.90): 56 data bytes 64 bytes from 192.168.0.90: icmp_seq=0 ttl=64 time=1.926 ms ...
Now, the IP address of the board can be changed, to fit in your local IP address space. Connect with a terminal emulation to IP-Port 50290 and type for example:
$ telnet 192.168.0.90:50290 SETGW 192.167.17.1 <ENTER> SETIP 192.168.17.99 <ENTER> # Do a power cycle on the board, to communicate with the new IP address.
To check the serial port, connect to the serial port with 9600 baud 8N1, no handshake.
There is no power up message. Type in the terminal (Mac OS X: Program CoolTerm):
VERSION <ENTER> or version <ENTER> uC: ATMega32 Ver: 1.03 NIC: ENC28J60
AVR Programmer program avrdude
avrdude is a freeware program, available for Linux, Mac OS X and Win32. It is also used in the Arduino IDE.
I am using the low cost AVR programmer AVR-ISP-Stick (ISP= In System Programming) from company ehajo.de, see at Links.
In program avrdude the AVT-ISP-Stick is called -c usbtiny. The port is always -P usb. The ATmega644 is specified with -p m644. In order to get more information about the programming, use verbose mode -v.
The program avrdude (Version 6.0.1) does also work under VirtualBox (Version 4.3.10, client Ubuntu 14.04, Host Mac OS X 10.9.3).
ATmega644 fuses
The ATmega644 has 3 fuse bytes to select the operating mode. Use the fuse calculator to check for the bits, see at Links.
Low fuse
Because the CPU works with an oscillator frequency higher than 8 MHz, the crystal oscillator should run in Full Swing mode for best noise immunity.
In order to be safe in case of a slow starting power supply, the CPU power up delay should be set to 65 ms.
Hence, the low fuse should be set to 0xF7 - Full Swing Oscillator; Start-up time: 16CK + 65 ms; [CKSEL=1111 SUT=11]; Crystal Osc.; [CKSEL=0111 SUT=11] - see data sheet chapter 7.4
# In Linux or Mac OS X type: $ sudo avrdude -v -p m644 -c usbtiny -P usb -U lfuse:w:0xf7:m
High fuse
For normal use of ethersex use 0xd1 - SPIEN, BOOTSZ1, BOOTSZ0 (11 = Boot Size= 4k words, Start $7000)
# In Linux or Mac OS X type: $ sudo avrdude -v -p m644 -c usbtiny -P usb -U hfuse:w:0xd1:m
For use of ethersex with TFTP use 0xd8 - SPIEN, BOOTSZ1, BOOTSZ0 (11 = Boot Size= 4k words, Start $7000), BOOTRST.
# In Linux or Mac OS X type: $ sudo avrdude -v -p m644 -c usbtiny -P usb -U hfuse:w:0xd8:m
Extended fuse
In order to have a safe Reset of the CPU in case of a power down, it is recommended to activate the brown-out circuit.
For a supply voltage of 5 V the Brown-out voltage could be 4.3 V (fuse: 0xfc)
For a supply voltage of 3.3V the Brown-out voltage could be 2.7 V (fuse: 0xfd)
Hence, the Extended fuse should be set to 0xFC - Brown-out detection level at VCC=4.3 V; [BODLEVEL=100] - see data sheet chapter 9.2.3
# In Linux or Mac OS X type: $ sudo avrdude -v -p m644 -c usbtiny -P usb -U efuse:w:0xfc:m
Software etherrape
The software etherrape (started 2007) is the predecessor of ethersex and has its own hardware. Because of the commercial hardware from Pollin.de (low cost kit), it is no longer interesting.
Software ethersex
Do not select DNS. It will give you a lot of troubleshooting, see at Links: S0 NET-IO, DNS problem DE
Ethersex is a community driven firmware with network support for 8-bit AVR micro controllers. Best use is with the CPU ATmega644 (housing DIL-40), or larger ROM / RAM.
A big Thank you to all the helpful programmers of the community. It was not easy to select the right options in make menuconfig, but with the help of freenode chat ethersex it could be done.
In order to find out all make options, type in the terminal:
$ make help
Additionally you can also program the MCU and set the fuses with make (see avrdude.mk):
# program file ethersex.hex $ sudo make program # program fuses from config, maybe better done manually to avoid misunderstandings. $ sudo make fuses
The software modules are configured with a menu. Not for use with TFTP boot:
$ cd ethersex $ make menuconfig Load a Default Configuration --->: Pollin, AVR Net-IO, General Setup ---> (AVR) Target Architecture (ATmega644) Target MCU (16000000) MCU frequency (Netio) Hardware/Periphery Class [ ] VFS (Virtual File System) support ---> [*] Enable Debugging ---> (0) Debug USART channel (115200) UART Baudrate Network ---> Hostname: "vz_99" (500) Network Buffer Size [*] Ethernet (ENC28J60) support ---> MAC address: "00:22:f9:01:c6:52" --- Static IPv4 configuration IP address: "192.168.17.99" Netmask: "255.255.255.0" --- IP Configuration Default gateway: "192.168.17.1" [*] TCP support [*] UDP support [*] UDP broadcast support [*] ICMP support [ ] DNS support ---> # Do NOT use this! [-] BOOTP (DHCP-like) support --- Debugging Flags [ ] Networking (nutzt nicht viel) [ ] Config I/O --->: ADC / DAC ---> [ ] ADC input ---> [ ] Onewire support ---> Applications ---> [ ] HTTP Server ---> [*] watchasync service ---> Server: "volkszaehler.org" Server IP: "192.168.17.72" (80) Port number HTTP Method (often GET or POST): "POST" Path in front of pin identifier: "/volkszaehler.org/htdocs/middleware.php/data/" Path at the end: "" [ ] Summarize Events # does work only, if "system clock support" is set Path in front of eventcount: "000&value=" (NEW) (16Bits) Counterrange (64) Buffersize (Power of 2) Pin Configuration ---> Port A ---> [*] Use Pin 4 of Port A Pin 4 on Port A Identifier: "be407ae0-e59e-11e3-bace-45793e9efd98" (NEW) --- Debugging Flags [*] WATCHASYNC [*] System clock support ---> [*] Date and Time support [*] Use CPU clock to tick the clock AVRDUDE configuration ---> (usbtiny) Programmer Type (-c type) Port (-P port, "usb", "/dev/ttyS0", ...): "usb" (f7) Fuse Low Byte (FLB) (99) Fuse High Byte (FHB) (fc) Extended Fuse Byte (EFB) Save Configuration to an Alternate File, e.g. vz99_wasser # Then hit "Exit" until leaving the menu. # compile the program $ make # Plug in the ISP "AVR-ISP-Stick" (USB) with AVR_NET-IO $ sudo make program avrdude -p atmega644 -P usb -c usbtiny -B 1 -v -U flash:w:ethersex.hex
In order to see, what is send to the middleware I added a line in file service/watchasync/watchasync.c to show the telegram:
WATCHASYNC_DEBUG ("send %d bytes\n", p - (char *)uip_appdata); WATCHASYNC_DEBUG ("%s \n", (char *)uip_appdata); // show telegram
Debug output of watchasync for volkszaehler
D: watchasync: got dns response, connecting D: watchasync: new connection or rexmit, sending message D: watchasync: send 172 bytes D: watchasync: POST /volkszaehler.org/htdocs/middleware.php/data/be407ae0-e59e-11e3-bace-45793e9efd98.json?ts=1401973759000&value=1 HTTP/1.1
TFTP bootloader
At a 64k or more flash ROM MCU a TFTP bootloader could be programmed in the upper 8k of the flash ROM, via network. This is of benefit, if your NET-IO board is housed in a place, were it is difficult to connect a computer with an ISP (In System Programmer).
As long as there is a suitable file (ethersex.bin) in the TFTP folder of the server, it will be flashed in the NET-IO in case of a Restart (RST).
# AVR NET-IO boot Time left to flash: 5 seconds Time left to flash: 4 seconds Time left to flash: 3 seconds ..............................................................................RST D: ethersex built on Jun 5 2014 15:38:04 (Debug mode) D: disabling watchdog D: enc28j60 revision 0x6 D: mac: 00:22:f9:01:c6:52 D: NTP: send packet D: net: got link! D: NTP: send packet D: NTP: Set new time: 1401992664 # unix timestamp [s]
If there is no file in the TFTP folder, the boot debug messages are:
# AVR NET-IO boot Time left to flash: 5 seconds Time left to flash: 4 seconds Time left to flash: 3 seconds Time left to flash: 2 seconds Time left to flash: 1 seconds RST # Restart D: ethersex built on Jun 5 2014 15:38:04 (Debug mode) ...
The configuration for the ethersex TFTP bootloader software:
Load a Default Configuration ---> [*] Ethernet Bootloader General Setup (ATmega644) Target MCU (16000000) MCU frequency (Netio) Hardware/Periphery Class (was Etherape) [*] Build a bootloader # config parameter BOOTLOADER_SUPPORT This actually builds an Ethersex based TFTP bootloader. Depends on TFTP to download a new firmware and program the flash. This bootloader needs 8k flash memory at the top of the flash, so only MCUs with 64k or 128k can be used. Select 'Enable bootloader jump' in your 'normal' ROM to be able re-enter the bootloader mode. [-] Enable bootloader jump (8192) Bootloader size in bytes [*] Teensy build [*] Enable Debugging ---> (0) Debug USART channel (115200) UART Baudrate Network ---> Hostname: "eth_boot99" (1500) Network Buffer Size [*] Ethernet(ENC28J60)support -> MAC address: "00:22:f9:01:c6:52" --- Static IPv4 configuration (This appears only, if BOOTP is NOT active) IP address "192.168.17.99" Netmask: "255.255.255.0" Default gateway: "192.168.17.1" [ ] TCP support # not needed, see http://old.ethersex.de/index.php/Ethernet_Loader [*] UDP support [*] UDP broadcast support [*] ICMP support [ ] BOOTP --- Debugging Flags [*] Networking [*] Config Applications -> [*] TFTP support [*] TFTP-o-matic TFTP-server IPv4 address: "192.168.17.72" TFTP image to load: "ethersex.bin" (250) Bootloader timeout AVRDUDE configuration ---> (usbtiny) Programmer Type (-c type) Port (-P port, "usb", "/dev/ttyS0", ...): "usb" [*] Extra verbose output (-v -v) (f7) Fuse Low Byte (FLB) (d8) Fuse High Byte (FHB) (fc) Extended Fuse Byte (EFB) # Brown-out 4.3V # Then hit "Exit" until leaving the menu. # compile the program $ make Compiled for: atmega644 at 16000000Hz Imagesize: 5878/8192 bytes (71.75%) [=====================---------] Program (.text + .data) : 5878 bytes 2014-06-05 20:12 Data (.data + .bss) : 1952 bytes # plug in ISP with AVR NET-IO connected. $ sudo make program avrdude -p atmega644 -P usb -c usbtiny -B 1 -v -U flash:w:ethersex.hex # save TFTP bootloader by renaming $ mv ethersex.hex eth_boot99.hex
Now the installed application program in the AVR NET-IO does no longer boot. It must be compiled with an additional configuration:
$ make menuconfig Load an Alternate Configuration File, e.g. vz99_wasser General Setup ---> [*] Enable bootloader jump (5898) Bootloader size in bytes # allow check for overlap of app. program with bootloader # for HTTP server [*] VFS (Virtual File System) support ---> [*] VFS File Inlining ---> --- -- You can enable various html pages for various features [*] Inline configuration page [*] Inline the .config [*] Inline IO [*] Inline Named Pin --- Inlining Options [*] Support Inline SVG # for graphics [*] control6 script Network ---> [ ] DNS support ---> # This will give a problem, see "S0 NET-IO, DNS problem" DNS-Server IP address: "192.168.17.1" --- Debugging Flags [*] NTP I/O ---> [*] Named and logic state I/O Protocols ---> [*] SOAP (XML RPC) Applications ---> [*] System clock support ---> [*] Date and Time support Timezone ---> (60) Local time offset to UTC (minutes) (NEW) --- Daylight saving (60) Time offset (minutes) (NEW) --- Begin of daylight saving March, week 5, Sunday, 2 o'clock --- End of daylight saving October, week 5, Sunday, 2 o'clock [*] Use CPU clock to tick the clock [*] Synchronize using NTP protocol NTP Server: "192.53.103.108" (NEW) (123) NTP Port (NEW) (1800) NTP query interval (seconds) (NEW) [ ] NTP daemon [*] Working hour meter # ECMD 'whm' [*] Uptime (whm in unix format like: d days, hh:mm) [*] HTTP Server ---> # needs VFS (Virtual File System) support [*] SOAP backend [ ] MIME-Type detection # That does NOT work (text/plain only) --- Debugging Flags [*] HTTPD [*] watchasync service ---> [*] Include unix timestamp Path in front of timestamp: ".json?ts=" (NEW) (1) Resolution in seconds (Power of 2) (NEW) [*] Send end of intervall instead of beginning (NEW) [*] Summarize Events Path in front of eventcount: "000&value=" (NEW) (16Bits) Counterrange # Then hit "Exit" until leaving the menu. # compile the program $ make Compiled for: atmega644 at 16000000Hz Imagesize: 29982/65536 bytes (45.74%) [=============-----------------] Program (.text + .data) : 29982 bytes 2014-06-04 05:07 Data (.data + .bss) : 1389 bytes EEPROM usage: 23/2048 bytes (1.12%) # mit HTTP und VFS support Compiled for: atmega644 at 16000000Hz Imagesize: 39500/65536 bytes (60.27%) [==================------------] Program (.text + .data) : 30278 bytes 2014-06-05 14:58 Data (.data + .bss) : 1389 bytes EEPROM usage: 23/2048 bytes (1.12%) # Plug in the programmer "AVR-ISP-Stick" (USB) with AVR_NET-IO $ sudo make program avrdude -p atmega644 -P usb -c usbtiny -B 1 -v -U flash:w:ethersex.hex Serial Debug output: D: ethersex cf168b7 built on Jun 4 2014 05:07:00 (Debug mode) D: disabling watchdog D: enc28j60 revision 0x6 D: mac: 00:22:f9:01:c6:52 D: NTP: send packet D: net: got link! D: NTP: send packet D: NTP: Set new time: 1401851405 ... D: watchasync: got dns response, connecting D: watchasync: new connection or rexmit, sending message D: watchasync: send 169 bytes D: watchasync: POST /volkszaehler.org/htdocs/middleware.php/data/be407ae0-e59e-11e3-bace-45793e9efd98.json?ts=1401851445000&value=1 HTTP/1.1 Host: volkszaehler.org, Content-Length: 0 ... D: watchasync: packet sent, closing D: watchasync: connection closed
TFTP server
The TFTP server is setup on a Ubuntu 12.04 Linux.
# copy the file ethersex.bin to folder /home/rudi/tftpboot/ # install TFTP server $ sudo apt-get install tftpd # edit config file /etc/rlinetd/tftp_udp, adopt to your TFTP folder path (default /srv/tftp) exec "/usr/sbin/in.tftpd /home/rudi/tftpboot"; # restart rlinetd, to get the changed upload folder path $ sudo service rlinetd restart * Restarting internet superserver rlinetd
Test the TFTP server from a Linux computer (Ubuntu 14.04, in virtualbox):
# Install the TFTP client $ sudo apt-get install tftp # test the TFTP client: $ tftp tftp> ? Commands may be abbreviated. Commands are: connect connect to remote tftp mode set file transfer mode put send file get receive file quit exit tftp verbose toggle verbose mode trace toggle packet tracing status show current status binary set mode to octet ascii set mode to netascii rexmt set per-packet retransmission timeout timeout set total retransmission timeout ? print help information tftp> connect 192.168.17.72 tftp> binary tftp> status Connected to 192.168.17.72. Mode: octet Verbose: off Tracing: off Rexmt-interval: 5 seconds, Max-timeout: 25 seconds tftp> get ethersex.bin Received 20414 bytes in 0.1 seconds tftp> quit # OK
volkszaehler channel
If you have more channels to show (Heizung), it is advisable to introduce groups.
For the channel KaltWasser I created the group Wasser, and then drag and dropped the channel KaltWasser into the group Wasser. For a single channel see the picture at the right (click to enlarge).
The parameters of channel KaltWasser are:
- Type: Wasser
- UUID: be407ae0-e59e-11e3-bace-45793e9efd98
- Color: teal
- Style: steps
- Active: OK
- Cookie: OK
- Public: OK
- Resolution: 1000 [l/m3]
telnet access
You can interview the ethersex software via telnet ECMD.
- How to connect:
$ telnet 192.168.17.99 2701 Trying 192.168.17.99... Connected to 192.168.17.99. Escape character is '^]'. version ethersex cf168b7 built on Jun 2 2014 06:34:58
- ECMD queries
$ telnet 192.168.17.99 2701 date Mon 02.06.2014 10:03:37 +2:00 ntp server 192.53.103.108 ntp status Update: 1401696206 Delta: +0 OCR1A: 30536 DCF/NTP: 0/1 Resync: 1229 time # unix timestamp [s] 1401696868 help d - dump the memory at ADDR (16 bytes). fuse - list fuses hostname - list hostname reset - reset the AVR - Controller wdreset - do a watchdog Reset bootloader - call the bootloader nslookup - do DNS lookup for HOSTNAME (call twice). dns server - list DNS server IP io - list/change I/O, see ECMD Reference, needs [*] Named and logic state I/O mac - list MAC-address netmask - list/change netmask ip - list/change IP gw - list gateway IP date - list date & time time - list unix timestamp [s] whm - list "working hours", e.g. 23:29 uptime - list "uptime", e.g. 0 days, 23:31 ntp query - NTP Refresh ntp server - list/change the IP address of the NTP server ntp status - list NTP server status help - list available commands version - display the version number. eeprom reinit - force reinitialization of the EEPROM config area io Help (from Link, Dinus Experience): ATmega644 has 4 ports PA PB PC PD PORTNUM is PA=0 PB=1 PC=2 PD=3 io get ddr PORTNUM io get mask PORTNUM io get pin PORTNUM io get port NUM io set ddr PORTNUM HEXVALUE [MASK] io set port NUM HEXVALUE [MASK]
Troubleshooting, Web access
- ECMD per USART not possible, no free USART with ATmega644.
- ECMD TCP/Telnet, Port 2701
- WATCHASYNC needs a complete I/O port PA, PB, PC, PD. No other use of the I/O port possible.
- Find HTML files
$ cd ethersex $ grep -r "<body>" *
HTTP access (Applications/[*] HTTP Server --->), see the picture on the right.
With [ ] MIME-Type detection selected it does not work, Firefox shows text/plain only!
http://192.168.17.99/ecmd?version ethersex cf168b7 built on Jun 4 2014 05:07:00
- HTTP - cfg.ht: The web mask field for the version is too small, time gets cut off
# edit file embed/cfg.ht.m4 # add size="35" <td><input size="35" type="text" id="version" readonly> </td> # delete old file cfg.ht.m4~ $ make clean $ make
Web output of ethersex configuration, see the picture on the right.
It would be nice to add also the uptime value.
CSS Style sheet Sty.c converted to white background (printer friendly).
html://192.168.17.99/Sty.c body { background-color: #fff; color: #000; font-family: sans-serif; } a{color: #444;} a:hover{color: #000;} a:visited, a:active{color: #222;} ifdef(`conf_MOTORCURTAIN_INLINE', `dnl .small_button:hover { background-color: #aaa; } .small_button, .lamp { background-color: #bbb; padding: 3px; color: white; text-decoration: none; margin-top: 4px; text-align: center; display: block; } ')dnl #logconsole { padding: 5px 5px 5px 5px; margin-top: 10px; width: 98%; border: medium dotted black; visibility: hidden; } #logconsole .lognotice { color: green; } #logconsole .logerror { color: red; font-weight: bold; } ifdef(`conf_VFS_IO_INLINE', `define(`_inline_iotable', `y')')dnl ifdef(`conf_ADC_INLINE', `define(`_inline_iotable', `y')')dnl ifdef(`conf_MSR1_INLINE', `define(`_inline_iotable', `y')')dnl ifdef(`conf_TO1_INLINE', `define(`_inline_iotable', `y')')dnl ifdef(`_inline_iotable', `dnl .iotable { text-align: center; padding: 15px; empty-cells: show; } .iotable td { border-bottom: 1px dashed #FF9999 } .iotable th { border-bottom: 2px dashed #9999FF; padding: 3px;} ')dnl ifdef(`conf_ADC_INLINE', `dnl .adc_graph { width: 500px; } .adc_graph div { background-color: #00ff00; } .adc_data, .adc_graph { border-left: 1px dashed #FF9999; padding: 3px; } ')dnl ifdef(`conf_TANKLEVEL_INLINE', `dnl .tank_wrap { position: relative; } .tank_wrap, .tank_value, .tank_text { width: 500px; height: 30px; } .tank_wrap, .tank_value { background: #777777; } .tank_value { background: #00ff00; width: 0px; } .tank_text { position: absolute; top:0; left:0; padding-top: 5px; text-align: center; width: 100%; } ')dnl ifdef(`conf_ONEWIRE_INLINE', `define(`_inline_svg', `y')')dnl ifdef(`conf_KTY_INLINE', `define(`_inline_svg', `y')')dnl ifdef(`_inline_svg', `dnl svg { stroke: #999; } svg .graph { stroke-width: 2px; } svg #axis { stroke-dasharray: 2,5; } svg #text { font-size: 10pt; } ')dnl
Web access, I/O control for digital I/O.
Links
Hardware
Ethersex firmware
Ethersex Applications
TFTP boot loader
Volkszaehler watchasync service
List of pages in this category:
-- RudolfReuter 2014-05-30 18:11:22
Go back to CategoryVolkszaehler or FrontPage ; KontaktEmail (contact email)