AN3972
Application note
Home web console for ZigBee® smartplugs
Introduction
This document describes how to use the STM3210C-EVAL, based on the STM32F107VC microcontroller, as a web console to monitor and control a ZigBee® network of smartplugs. The application can be used as a reference for the development of a ZigBee - TCP/IP Networks Bridge and is an example on how, in a smartgrid scenario, the services offered by a ZigBee HAN can be exported to the Internet by an Ethernet/Internet gateway.
The STM32F107VC coordinates the ZigBee network through an SPZB260-PRO module included in an adapter connected by the expansion connectors of the STM3210C-EVAL; the ZigBee network is built using several STEVAL-IHP001V3s used to monitor and control several AC loads (lights, appliances, etc.) inside the HAN. The adapter also includes an M24LR64-R dual interface EEPROM to store the TCP/IP network configuration. In fact, in the microcontroller firmware, a web server is also implemented which allows to monitor the AC load power consumption measured by each smartplug and to control its status (ON/OFF).
November 2011 |
Doc ID 022161 Rev 1 |
1/21 |
www.st.com
Contents |
AN3972 |
|
|
Contents
1 |
Document and library rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
4 |
|
|
1.1 |
Acronyms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
4 |
2 |
Hardware kit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
5 |
|
|
2.1 |
STM3210C-EVAL demonstration board . . . . . . . . . . . . . . . . . . . . . . . . . . . |
5 |
|
2.2 |
SPZB260-PRO adapter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
6 |
|
2.3 |
STEVAL-IHP001V3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
8 |
3 |
Application firmware description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
9 |
|
|
3.1 |
ZigBee section . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
9 |
3.1.1 ZigBee libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 3.1.2 ZigBee application layer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3.2 TCP/IP section . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
|
|
3.2.1 |
TCP/IP stack . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
11 |
|
|
3.2.2 |
TCP/IP application layer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
11 |
|
3.3 |
Source code organization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
15 |
|
4 |
Demo setup |
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
16 |
4.1 HTTP server limitations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 4.2 Demo limitations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
5 |
References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
19 |
6 |
Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
20 |
2/21 |
Doc ID 022161 Rev 1 |
AN3972 |
List of figures |
|
|
List of figures
Figure 1. STM3210C-EVAL demonstration board . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 Figure 2. SPZB260-PRO adapter layout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 Figure 3. How to connect SPZB260-PRO adapter to the STM3210C-EVAL . . . . . . . . . . . . . . . . . . . . 7 Figure 4. Firmware architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 Figure 5. Source code folder tree . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 Figure 6. PC TCP/IP properties configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 Figure 7. Smart Home Information web page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 Figure 8. Smartplug list detail of Smart Home Information web page . . . . . . . . . . . . . . . . . . . . . . . . 17 Figure 9. RFID PC user interface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 Figure 10. Writing details of RFID PC user interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 Figure 11. Demo setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Doc ID 022161 Rev 1 |
3/21 |
Document and library rules |
AN3972 |
|
|
This document uses the conventions described in the sections below.
Table 1 describes the acronyms used in this document.
Table 1. |
List of acronyms |
|
|
Acronym |
|
Meaning |
|
|
|
|
|
|
APP |
|
Application |
|
|
|
|
|
API |
|
Application programming interface |
|
|
|
|
|
HAL |
|
Hardware abstraction layer |
|
|
|
|
|
RTOS |
|
Real time operating system |
|
|
|
|
|
HAN |
|
Home area network |
|
|
|
|
|
MCU |
|
Microcontroller unit |
|
|
|
|
|
SPI |
|
Serial peripheral interface |
|
|
|
|
|
OOP |
|
Object oriented programming |
|
|
|
|
EEPROM |
|
Electrically erasable programmable read only memory |
|
|
|
|
|
|
OS |
|
Operating system |
|
|
|
|
|
RTOS |
|
Real time operating system |
|
|
|
|
|
HA |
|
Home automation |
|
|
|
|
|
ZCL |
|
ZigBee clusters library |
|
|
|
|
|
SICS |
|
Swedish institute of computer science |
|
|
|
|
|
TCP |
|
Transport communication protocol |
|
|
|
|
|
IP |
|
Internet protocol |
|
|
|
|
|
HTTP |
|
Hypertext transfer protocol |
|
|
|
|
|
HTML |
|
Hypertext markup language |
|
|
|
|
4/21 |
Doc ID 022161 Rev 1 |
AN3972 |
Hardware kit |
|
|
This section describes the hardware components necessary to set up the home web console demo kit:
●One STM3210C-EVAL board
●One SPZB260-PRO module adapter board for the STM3210C-EVAL
●Several ZigBee smartplug boards (STEVAL-IHP001V3).
2.1STM3210C-EVAL demonstration board
The STM3210C-EVAL is a standard evaluation tool for the STM32F107xx microcontroller which includes an embedded Ethernet controller; this is the main feature necessary for the home web console. For further details about this board please refer to the UM0600 user manual.
The connectors CN8 and CN9, which include all the MCU pinouts, are used to connect the SPZB260-PRO adapter, so a specific configuration of the board is necessary to free some MCU I/O resources. The following is the board setup:
●To close jumper JP19
●To open jumper JP15
●To remove R79, R84 and R169.
Table 2 shows the pinout mapping of the connectors over the adapter.
Doc ID 022161 Rev 1 |
5/21 |
Hardware kit |
|
|
|
AN3972 |
||
|
|
|
|
|
|
|
Table 2. |
SPZB260-PRO adapter pin description |
|
|
|||
|
|
|
|
|
|
|
STM32 pin no. |
Pin name |
STM3210C-EVAL |
Extension |
ZigBee adapter I/O |
||
I/O assignment |
connector pin no. |
assignment |
||||
|
|
|
||||
|
|
|
|
|
|
|
- |
|
VDD |
3.3 V |
CN8-Pin 48 |
VCC_3V3 |
|
|
|
|
|
|
|
|
- |
|
VSS |
GND |
CN9-Pin 50 |
GND |
|
|
|
|
|
|
|
|
29 |
|
PA4 |
SPI1_NSS |
CN9-Pin 41 |
ZIG_SS |
|
|
|
|
|
|
|
|
30 |
|
PA5 |
SPI1_CLK |
CN9-Pin 40 |
ZIG_SCLK |
|
|
|
|
|
|
|
|
31 |
|
PA6 |
SPI1_MISO |
CN9-Pin 38 |
ZIG_MISO |
|
|
|
|
|
|
|
|
32 |
|
PA7 |
SPI1_MOSI |
CN9-Pin 37 |
ZIG_MOSI |
|
|
|
|
|
|
|
|
92 |
|
PB6 |
CAN2_TX/I2C1_SCK |
CN8-Pin 36 |
I2C1_SCK |
|
|
|
|
|
|
|
|
93 |
|
PB7 |
I2C1_SDA |
CN8-Pin 37 |
I2C1_SDA |
|
|
|
|
|
|
|
|
2 |
|
PE3 |
Trace_D0 |
CN8-Pin 42 |
ZIG_HOST_INT |
|
|
|
|
|
|
|
|
3 |
|
PE4 |
Trace_D1 |
CN8-Pin 43 |
VCC-GPIO (for M24LR64-r) |
|
|
|
|
|
|
|
|
4 |
|
PE5 |
Trace_D2 |
CN8-Pin 44 |
ZIG_WAKE |
|
|
|
|
|
|
|
|
5 |
|
PE6 |
Trace_D3 |
CN8-Pin 47 |
ZIG_RSTB |
|
|
|
|
|
|
|
2.2SPZB260-PRO adapter
This board allows to add the ZigBee connectivity to the STM3210C-EVAL board; it includes the connectors for the SPZB260-PRO module and the M24LR64-R dual interface EEPROM. Figure 2 shows the adapter layout.
Figure 3 shows how to connect to the STM3210C-EVAL board.
6/21 |
Doc ID 022161 Rev 1 |
AN3972 |
Hardware kit |
|
|
The SPZB260-PRO is a 2.4 GHz ZigBee module compliant with FCC regulations (FCC ID: S9NZB260A); for further information refer to the SPZB260-PRO datasheet. The M24LR64- R is an EEPROM with both I2C interface and RF interface; this allows a “standard” memory access for an MCU using the I2C and an access for a standard long range (ISO 15693/ISO 18000-3 mode 1) RFID reader. Using the RF interface, the memory can read/write even when it is not powered. In this application, the EEPROM stores, in the first three 32-bit memory locations, the TCP/IP network parameters:
●IP address
●Gateway IP address
●IP address mask.
The parameters are programmed by the RFID reader with the board switched off and at the power-on, during boot, the MCU reads the network parameters to configure the TCP/IP stack. The 64-Kbit memory is organized into 8192 x 8 bits accessing from the I2C bus and into 2048 x 32 bits accessing from the RF interface. M24LR64-R is the slave of the I2C communication with STM32; the two jumpers included on the board are used to set the slave address of the memory. For further information about M24LR64-R functionalities, refer to the M24LR64-R datasheet; for information related to application development, several application notes are available for downloading at www.st.com.
Doc ID 022161 Rev 1 |
7/21 |