AN6 Using Raspberry Pi with HomePlug Green PHY Powerline...

9
AN6 Using Raspberry Pi with HomePlug Green PHY TM Powerline Evaluation Kit I2SE GmbH: Michael Heimpold January 13, 2017 1/9

Transcript of AN6 Using Raspberry Pi with HomePlug Green PHY Powerline...

Page 1: AN6 Using Raspberry Pi with HomePlug Green PHY Powerline …download.i2se.com/ApplicationNotes/an6_rev1.pdf · via SPI to the Raspberry Pi and requires on GPIO as interrupt line.

AN6Using Raspberry Pi with HomePlug Green PHYTM Powerline

Evaluation Kit

I2SE GmbH: Michael Heimpold

January 13, 2017

1/9

Page 2: AN6 Using Raspberry Pi with HomePlug Green PHY Powerline …download.i2se.com/ApplicationNotes/an6_rev1.pdf · via SPI to the Raspberry Pi and requires on GPIO as interrupt line.

CONTENTS CONTENTS

Contents

1 Revisions 3

2 Introduction 3

3 Hardware Requirements 3

4 SD Card Preparation 4

5 Preparing the Evaluation Board for PLC Stamp micro 4

6 Physical Wiring 5

7 Software configuration 5

8 FAQ 78.1 Raspberry Pi model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78.2 HAT compliance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78.3 Static MAC Address for Powerline Network Interface . . . . . . . . . . . . . . . . . . . . . . . . . 78.4 Bridging between Powerline Interface and Wired Ethernet/Wifi . . . . . . . . . . . . . . . . . . . . 88.5 What to do next? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

9 Contact 9

2/9

Page 3: AN6 Using Raspberry Pi with HomePlug Green PHY Powerline …download.i2se.com/ApplicationNotes/an6_rev1.pdf · via SPI to the Raspberry Pi and requires on GPIO as interrupt line.

3 HARDWARE REQUIREMENTS

1 Revisions

Revision Release Date Changes1 January 13, 2017 Initial release

2 Introduction

I2SE’s Evaluation Board for PLC Stamp micro is a simple yet powerful solution to get familiar with powerline com-munication for the Internet of Things. The heart of this board is the PLC Stamp micro module by I2SE which in turnis based on the QCA7000 by Qualcomm Atheros. This is a HomePlug Green PHY chip which is fully compatible tothe HomePlugAV standard.The Raspberry Pi is a full-featured development board, backed by a huge family of contributor and many ready-to-use applications etc. Therefore it is obvious to combine these both boards to evaluate and/or create new powerlinesolutions.This guide shows how fast the marriage of the two boards is done and additionally discusses some frequently askedquestions and common pitfalls.

The Evaluation Board for PLC Stamp micro is connected to mains power for communication. Thereexists the risk of an electric shock when the cable is installed. So follow this instructions carefully and double-checkbefore powering on.

3 Hardware Requirements

The hardware required cuts down to the following list:

• Raspberry Pi

• I2SE’s Evaluation Board for PLC Stamp micro

• USB power supply for Raspberry Pi

• power cord with plug on the one side and wires ends with end terminals (wire ferrules) on the second one

• short USB A to USB micro cable

• short 40-pin to 26-pin ribbon cable

• micro SD card (at least 2 GB)

• ethernet patch cable (used during Raspberry Pi setup)

• wall plug powerline to ethernet adapter

• ethernet patch cable to connect powerline adapter to router/switch

If you want to control your Raspberry Pi with keyboard and display, then you need to attach these two.To start as fast as possible I2SE sells bundles consisting of all required components. These bundles are availablewith the article number I2PLC-RPIKIT-001.

3/9

Page 4: AN6 Using Raspberry Pi with HomePlug Green PHY Powerline …download.i2se.com/ApplicationNotes/an6_rev1.pdf · via SPI to the Raspberry Pi and requires on GPIO as interrupt line.

5 PREPARING THE EVALUATION BOARD FOR PLC STAMP MICRO

Figure 1: Required hardware components

4 SD Card Preparation

To prepare the SD card, simply following the next steps:

1. Download latest Raspbian Imagehttps://www.raspberrypi.org/downloads/raspbian/For powerline communcation it does not matter whether you chose Raspbian Jessie with Pixel or RaspbianJessie Lite. This only depends on your environment, e.g. whether you want to use GUI etc.

2. Extract the raw disk image from the downloaded ZIP archive.

3. Download Win32 Disk Imagehttps://sourceforge.net/projects/win32diskimager/We recommend this tool for Windows platform to write the raw disk image to the SD card.

4. Once the write finished, Windows will recognize the boot partition with the FAT filesystem on the SD card.Locate the config.txt and open it with Notepad or another simple text editor.Add the following line to the file and save it afterwards:dtoverlay=qca7000

That’s all. The QCA7000 kernel driver is already included as module. Also a devicetree overlay for QCA7000 isavailable, which you simply enable in the last step.Now you can safely remove the SD card and insert it in your Raspberry Pi.If you need further help on this topic, please visit https://www.raspberrypi.org/ for detailed instructions.

5 Preparing the Evaluation Board for PLC Stamp micro

The Evaluation Board for PLC Stamp micro has several jumpers for configuration.It’s recommended to start with the following jumper setup:

• JP4: all removed

• JP5: removed

• JP11: all set

• JP13:

– GPIO 0: pull-up (jumper connects middle and right pins)

– GPIO 1: pull-down (jumper connects left and middle pins)

– GPIO 2: pull-up (jumper connects middle and right pins)

– GPIO 3: pull-up (jumper connects middle and right pins)

4/9

Page 5: AN6 Using Raspberry Pi with HomePlug Green PHY Powerline …download.i2se.com/ApplicationNotes/an6_rev1.pdf · via SPI to the Raspberry Pi and requires on GPIO as interrupt line.

7 SOFTWARE CONFIGURATION

• JP15: all removed

According to this setup, the QCA7000 starts its firmware from attached SPI flash.Please refer to the evaluation board’s datasheet for further details. You can download the latest version at https://www.i2se.com/product/plc-stamp-micro-evk/

6 Physical Wiring

This most important wiring is the connection between the Raspberry Pi GPIO pins and the X1 socket with 26 pin onthe Evaluation Board for PLC Stamp micro. For this use the short ribbon cable. On the Raspberry Pi side, there isno mechanical key at the pins, so double-check that you do not confuse the pins: pin 1 is next to the boards borderand is also marked on the ribbon cable.Unfortunately, it’s not possible to feed power over this ribbon cable to the Evaluation Board for PLC Stamp micro.Power can be supplied only via its mini USB socket: attach the USB A to USB mini cable to it and insert the USB Aside into one of Raspberry Pi’s USB ports.

Danger! Ensure that the power cord is not plugged into mains before doing the next steps! Otherwiseyou might encounter an electric shock!Then attach the power cord to the X3 connector of the Evaluation Board for PLC Stamp micro. Please verify thatthe connection is solid and cannot dissolve itself when the board is moved! On X3 there are 4 terminals for wires:use number 3 and 4. This are the two lower terminals, or in other words: the two terminals which are nearest to theC3 printing (The upper two terminals are intended for electrical vehicle communication evaluation and use specialtransformers.)Now attach the USB power supply to Raspberry Pi’s micro USB slot and plug in the network patch cable intoRaspberry Pi and your router/PC.Plug in both the USB power supply and the power plug for the powerline communication into power points and waituntil Raspberry Pi starts up.

Figure 2: Hardware components wired

7 Software configuration

Login to your Raspberry Pi to check whether the SPI connection to the Evaluation Board for PLC Stamp microworks.

5/9

Page 6: AN6 Using Raspberry Pi with HomePlug Green PHY Powerline …download.i2se.com/ApplicationNotes/an6_rev1.pdf · via SPI to the Raspberry Pi and requires on GPIO as interrupt line.

7 SOFTWARE CONFIGURATION

You can see whether the driver for the QCA7000 successfully found the chip and created a second ethernet inter-face. Use dmesg to check:

pi@raspberrypi:˜ $ dmesg | grep qca[ 8.679849] qcaspi spi0.0: ver=0.2.7−i, clkspeed=12000000, burst len=5000, pluggable=0[ 8.679951] qcaspi spi0.0: Using random MAC address: f6:45:27:00:4e:6bpi@raspberrypi:˜ $

Check whether the new network interface (usually eth1) is available:

pi@raspberrypi:˜ $ ifconfigeth0 Link encap:Ethernet HWaddr b8:27:eb:b1:21:3b

inet6 addr: fe80::5e25:34e9:e4c0:83ed/64 Scope:LinkUP BROADCAST MULTICAST MTU:1500 Metric:1RX packets:0 errors:0 dropped:0 overruns:0 frame:0TX packets:0 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:1000RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)

eth1 Link encap:Ethernet HWaddr f6:45:27:00:4e:6binet6 addr: fe80::74d9:733b:5639:8eb/64 Scope:LinkUP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1RX packets:0 errors:0 dropped:0 overruns:0 frame:0TX packets:0 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:100RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)

lo Link encap:Local Loopbackinet addr:127.0.0.1 Mask:255.0.0.0inet6 addr: ::1/128 Scope:HostUP LOOPBACK RUNNING MTU:65536 Metric:1RX packets:0 errors:0 dropped:0 overruns:0 frame:0TX packets:0 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:1RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)

wlan0 Link encap:Ethernet HWaddr b8:27:eb:e4:74:6einet6 addr: fe80::fae6:5af0:3990:fc60/64 Scope:LinkUP BROADCAST MULTICAST MTU:1500 Metric:1RX packets:2 errors:0 dropped:2 overruns:0 frame:0TX packets:0 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:1000RX bytes:123 (123.0 B) TX bytes:0 (0.0 B)

It’s assumed that your Raspberry Pi is configured via DHCP and already obtained an IP address from your routervia wired and/or wireless connection and you can access the Internet to download further software packages.We recommend to install the open-plc-utils, a tool collection to manage and debug the Qualcomm Atheros basedpowerline chipsets. For this we recommend using precompiled packages for Raspbian as provided by the commu-nity. So installation cuts down to:

pi@raspberrypi:˜ $ curl −s https://packagecloud.io/install/repositories/mhei/open−plc−utils/script.deb.sh | sudobash

pi@raspberrypi:˜ $ sudo apt install open−plc−utils

6/9

Page 7: AN6 Using Raspberry Pi with HomePlug Green PHY Powerline …download.i2se.com/ApplicationNotes/an6_rev1.pdf · via SPI to the Raspberry Pi and requires on GPIO as interrupt line.

8 FAQ

The tool plctool can be used to query the QCA7000’s firmware version.

pi@raspberrypi:˜ $ sudo plctool −reth1 00:B0:52:00:00:01 Request Version Informationeth1 00:01:87:FF:FF:2B QCA7000 MAC−QCA7000−1.1.3.1531−00−20150204−CSpi@raspberrypi:˜ $

If this is successfully, then the SPI connection to the evaluation board works perfectly.When your HomePlug wall plug adapter is already setup and working, you are now ready to join the powerlinenetwork. For this you need to pair the wall plug adapter with the evaluation board. One possibilty is to press thepowerline security button on the wallplug adapter to start the pairing, and then to run the following command on theRaspberry Pi - this emulates pressing the pairing button of the evaluation board:

pi@raspberrypi:˜ $ sudo plctool −B joineth1 00:B0:52:00:00:01 Join Networketh1 00:01:87:FF:FF:2B Joining ...pi@raspberrypi:˜ $

After a short while, you should see the remote powerline adapter:

pi@raspberrypi:˜ $ sudo plcstat −tP/L NET TEI −−−−−− MAC −−−−−− −−−−−− BDA −−−−−− TX RX CHIPSET FIRMWARELOC STA 002 00:01:87:FF:FF:2B 00:01:87:FF:FF:FE n/a n/a QCA7000 MAC−QCA7000−1.1.3.1531−00−20150204−CS

REM CCO 001 00:0B:3B:AA:86:55 E0:CB:4E:ED:1F:53 009 009 INT6400 INT6000−MAC−4−1−4102−00−3679−20090724−FINAL−B

pi@raspberrypi:˜ $

Then you’ve successfully created a powerline connection. Now you can configure the eth1 interface according toyour needs, e.g. enable DHCP or assign a static IP address etc.After this setup is finished, you should be able to remove the Raspberry Pi’s network cable. Communication shouldnow be possible with the IP address of the powerline network interface.

8 FAQ

8.1 Raspberry Pi model

Q: This application note uses a Raspberry Pi 3. But I have an older Raspberry Pi x around. Can I use this instead?A: Yes, of course. The pin out of the GPIOs is same for every Raspberry Pi model. The QCA7000 chip is attachedvia SPI to the Raspberry Pi and requires on GPIO as interrupt line. The required signals are within the first 26 pins,so you could even use such an old Raspberry Pi A/B (Rev 2).

8.2 HAT compliance

Q: Why do I need to manually edit the config.txt to enable driver and pin muxing. What about HAT (HardwareAttached on Top) compliance?A: The current hardware version of the Evaluation Board for PLC Stamp micro was developed long time before theHAT specification was published. This is also the reason for the 26 pin socket on the board instead of a 40 pin one.So the board is missing the required I2C identification chip.Q: Are you planning a new - HAT compliant - version of your evaluation board?A: That depends on multiple factors, e.g. other customer projects and demands. Best would be to drop us a shortemail to signal your interest.

8.3 Static MAC Address for Powerline Network Interface

Q: The network interface created by QCA driver has a random MAC address after every boot. How can I preventthis?

7/9

Page 8: AN6 Using Raspberry Pi with HomePlug Green PHY Powerline …download.i2se.com/ApplicationNotes/an6_rev1.pdf · via SPI to the Raspberry Pi and requires on GPIO as interrupt line.

8.4 Bridging between Powerline Interface and Wired Ethernet/Wifi 8 FAQ

A: It’s usually the task of a boot loader and board support package code to bridge between the persistent MACaddress storage (e.g. some OTP bits) and the Device Tree/platform data to tell the driver which MAC address touse. In the case of the RPi there simply does not exist such a static assignment, so the driver has no chance butto use a random MAC address. However, you can workaround this by specifying an MAC address in Raspbiannetwork configuration. For this create a file /etc/network/interfaces.d/eth1 with the following content:

auto eth1iface eth1 inet dhcp

hwaddress ether 00:01:87:ff:ff:fe

The line with hwaddress ether does the trick. Please adapt the other settings according to your needs.

8.4 Bridging between Powerline Interface and Wired Ethernet/Wifi

While it is possible to bridge the powerline network interface (eth1) with other network interfaces of the RaspberryPi, we do not recommend this due to the limitations of the QCA7000 chipset: this chipset is intended for HomePlugGreen PHY communication, that is for Internet of Things devices. These devices are expected to have a singleMAC address ,,behind” the QCA7000, thus the QCA firmware only announces one ,,bridged MAC address” to otherpowerline peers. Communication is therefore only stable to a single device behind the bridge. So this single deviceshould be the Raspberry Pi itself, i.e the MAC address of the powerline network interface on the Raspberry Pi.However, it would be possible to install a proxy server or similar on the Raspberry Pi. This way, communication onlayer 2 is terminated at the Raspberry Pi and higher layers will take care to reach the final destination.On the other hand, if you still want to bridge the powerline interface, here are some hints.First, install the bridge-utils package on Raspbian:

pi@raspberrypi:˜ $ sudo apt updatepi@raspberrypi:˜ $ sudo apt install bridge−utils

Then you have to adapt the network configuration. See https://wiki.debian.org/NetworkConfigurationfor details. The following configuration file is a simple example which bridges the wired network interface with thepowerline network interface and configures it for DHCP.

# interfaces(5) file used by ifup(8) and ifdown(8)

# Please note that this file is written to be used with dhcpcd# For static IP, consult /etc/dhcpcd.conf and ’man dhcpcd.conf’

# Include files from /etc/network/interfaces.d:source−directory /etc/network/interfaces.d

auto loiface lo inet loopbackiface eth0 inet manualiface eth1 inet manual

auto br0iface br0 inet dhcp

bridge ports eth0 eth1bridge fd 0hwaddress ether b8:27:eb:b1:21:3b

allow−hotplug wlan0iface wlan0 inet manual

wpa−conf /etc/wpa supplicant/wpa supplicant.conf

allow−hotplug wlan1iface wlan1 inet manual

wpa−conf /etc/wpa supplicant/wpa supplicant.conf

8/9

Page 9: AN6 Using Raspberry Pi with HomePlug Green PHY Powerline …download.i2se.com/ApplicationNotes/an6_rev1.pdf · via SPI to the Raspberry Pi and requires on GPIO as interrupt line.

8.5 What to do next? 9 CONTACT

Please note that bridge interface ,,inherits” the MAC address of one of its children. As described above, the power-line interface has a random MAC address, so it’s best to statically assign the MAC address of the eth0 interface tothe bridge, too.

8.5 What to do next?

Q: This is a really nice application note. But why should I use your evaluation board with a Raspberry Pi? A simplersolution would be to use a second wallplug ethernet adapter on the Rasberry Pi side.A: This is just one point of view. We provide the Evaluation Board in order to let you play with ideas and try them outquickly. Maybe you have new projects in mind, e.g. based on Raspberry Pi computer module or Raspberry Pi Zero.Then you could make your own PCB with a design in of the PLC Stamp micro 2 module. In this case you could testyour software already on the Raspberry Pi without having your own PCB available finished.Imagine the amazing possibilities you have with the CPU power of the Raspberry Pi and no need for extra cables orWifi connectivity. Since you have to power the Raspberry Pi anyway, it makes really sense to use this required onewire additionally for communication.For example if you intent to create a home automation server you will benefit from the minimal power consumptionof the HomePlug Green PHY technology compared to the consumption of a 1.2Gbit adapter.And by the way, ideal counterparts for your Home Automation server are the I2SE XPL Rail devices: the JSON APIis documented at http://xpl-rest-api.readthedocs.io/en/latest/.

9 Contact

I2SE GmbHFriedrich-Ebert-Str. 6104109 LeipzigDeutschland

http://www.i2se.com/

9/9