Waking the Raspberry Pi with a wireless command

Dietmar Hoepfl, 123RF.com

Remote Activation

If you want to power your Pi solely with batteries, then it makes sense for the Pi to only be turned on when you need it. The Pi can boot when called remotely via radio signal sent over the European 868 MHz band.

The "Witty Pi" board manufactured by UU Gear in 2015 provided a handy solution for booting a Rasberry Pi at a predetermined time [1]. This solution can be expanded to accommodate as many events as desired since the onboard RTC (Real Time Clock) chip has a central feed point for additional hardware trigger signals. This article expands on this model in the form of a radio module which initiates the boot process upon receiving a pre-defined wireless signal.

In order for the extension to work, the device that you want to start should only react to a radio frequency identification (RFID) that has been individually assigned. In this way, it is possible to control several distributed systems separately. Acknowledgment of system status by sending a corresponding return signal datagram should also occur when a Pi has already been started.

The low priced FSK-wireless modem module RFM69 [2] can be used for this project. It contains a transceiver chip SX1231 [3] and all of the other necessary components. The only thing that needs to be added before the elements can be integrated into the Raspberry Pi circuitry is an antenna. I built one of these himself from standard components found in a building supply store (Figure 1). It is made of insulated cable,1.5 mm2 in diameter. The thickness makes for greater stability and bandwidth. The length of the cable does not need to be milimetrically precise. The SPI Bus on the Pi controls the transceiver component and switches it between receiving and sending mode.

Figure 1: The radio module RFM69HCW together with a DIY 86 millimeter rod aerial. I substituted a standard electrical cable with a 1.5 mm diameter cable.

There module supports two European radio frequency bands. One of these is the widely used 433 MHz band, which is often used for wireless headsets, remote controls, wireless outlets and inexpensive walkie-talkies. However, this band has a serious disadvantage as transmission power is rarely regulated. As a result, it is easy for a wireless loudspeaker sitting somewhere else in the neighborhood to block the path for wireless signals in your home or to significantly shorten the path for instance.

The 868 MHz band is much better suited since access to this channel is regulated across the European Union (see info box "The European 868 MHz Band"). This band has a low frequency in comparison to the 2.4 GHz WiFi. As a result it has an excellent 100 meter range in open areas and the ability to penetrate inside buildings. In contrast to devices which work over the 433 MHz band, this band needs an antenna that is half the wave length (see info box "Wireless parameters").

The European 868-MHz-Band

The European Institute for Telecommunications Standards ETSI regulates access by short range devices, or SRDs, to the corresponding radio bands in the 25 mHz to 1 GHz range for all of Europe. The 433MHZ band is available worldwide but it is largely unregulated. As a result, usingup to 1 mW even in the full 1.74 MHz bandwidth without any time limit is permitted. For the 868 Mhz band, the EU permits only one duty cycle of 1 percent for a single one hour interval in a 600 KHz bandwidth and 25 mW transmission power. In other words, the regulators permit a total of up to 36 seconds distributed as desired over one hour. This time limit means that every device has a reasonable chance of getting undisturbed access and also significantly greater range. In the event that the sender implements additional fair use rules, the time limits may be extended.

Parameters for Wireless

Through the use of minimum shift keying or MSK for modulation, it is possible to operate RFM69 with a maximum data rate of 300 kbit/s. Modulation works the same as for DECT with the product of bandwidth and symbol duration time being BT = 0.5. This maximum data rate therefore occupies around 400 kHz bandwidth and it can use any carrier frequency in the range of 868.2 to 868.4 MHz. The project described here uses the middle part of the range, around 868.3 MHz.

The switch

Figure 2 shows the switch from the first article expanded and slightly modified by the transceiver module RFM69. I simply replaced the relay with a P channel MOSFET Type IRF5305 for a switch. You can use the same software as before. With its interrupt output and inverter transistor T5, the transceiver module affects the same central trigger point of the circuit which is used by the RTC chip and the switch in order to cause the system to start.

Figure 2: Schematics for the switch.

You should now configure the transceiver as a receiver and set the RFID as a synchronization word. The RFM69 module will listen to the antenna. After receiving a preamble, synchronization word and datagram, the switch will trigger an interrupt in the transceiver component. The same hardware signal which also activates the power supply via T5, is forwarded by the component as an interrupt signal to the Raspberry Pi via GPIO25 (Pin 22). If the pin is already being used for other purposes, then you should simply use another pin, keeping in mind that the configuration may have to be modified accordingly.

In most cases you will need an additional Pi to send the wake up message. For this second Pi, it is sufficient to mount the transceiver module, which is indicated in the switch diagram as IC4, with all the connections to the plug on the Pi GPIO. The 3.3 volt power for the module is all that will come directly from the Pi via Pin 1 or Pin 17 of the GPIO.

The transceiver protocol

As shown at the top of Figure 3, the 256 bit datagram that was used consists of the preamble for synchronizing the frequency of the receiver, the destination RFID, and the source RFID. With a 300 kbit/s transmission rate, this takes up an 853.3 microsecond interval. The simplest way to occupy only 1 percent of the wireless channel as required by the EU standards is for the transmitter to use a single time slot in a periodic transmission frame of 85.3 milliseconds (Figure 3, centre). During the remaining time, the transmitter waits for the transmission acknowledgment from the station that has been called.

According to the product data sheet, the RFM69 module draws 16 mA of current when it is in receiver mode. This means the power switch would have to carry an additional 80 mW load, whichis probably too much for a battery. When operating in idle mode, the 1.2 µA that the module uses is negligble. Therefore, it makes sense to program the RFM69 so that it operates at specific time intervals. This technique is known as discontinuous reception or DRX when used for mobile phones. When the module operates at intervals, the average draw on the battery sinks by 90 per cent with a 10 per cent duty cycle reception phase versus a 90 percent idle phase. The reduction in power usage is about 72 mW, bringing consumption down to 1.6 mA.

In addition to sizing the reception phase for the Pi you want to wake (Figure 3, bottom), consider the wake up time for the wireless module. According to the product data sheet for the RFM69, this is about 700 microseconds in the worst case. However, an active reception phase of about 90 milliseconds in length guarantees that at least one datagram can be received and maybe even two if you are lucky. See info box "RFM69 Timing" for details. During the remaining 0.9 seconds of the reception phase, the module goes into power conserving idle mode.

Figure 4: Flow charts describing the essential operations of the program and the system.

RFM69 Timing

In order to insure that at least one wake up signal is received during the time the computer is active, the RFM69 module will have to wake up, which takes 700 milliseconds, and also stay awake for the length of the sending phase(85.3 milliseconds). In addition, the module has to stay awake long enough for 853.3 microseconds to listen to a data slice. This totals arequired active phase of around 86.9 milliseconds.

However, periods of activity and hibernation can only be set on the module in multiples of just under 4.1 millisecond tick events. 21 tick events correspond to 86.1 milliseconds which means that you will need to have 22 tick events, or 90.1 milliseconds in order to have a sufficient wake phase. Accordingly, the module then goes into idle mode nine times or a good 811 milliseconds. The outcome is a total reception phase time of just a little over 0.9 seconds.


If a message has come in, then Rfrespond reads the source RFID and sends an acknowledgement with its own source RFID back to the transmitting RFID, which is now the target RFID. If a datagram has not been received then the daemon will wait until one is and acknowledge it on arrival. Before the module can go into interval mode, it makes sense to close the daemon together with system shut down (Figure 4, middle).

Figure 4: Flow charts describing the essential operations of the program and the system.

The Raspberry Pi on the sending side still needs rfwake for transmitting the wake up signal (Figure 4, right). This program works at intervals until it receives an acknowledgment. This occurs promptly when the computer is awake and the connection is constant. If on the other hand, the Raspberry Pi that is supposed to wake up has to first boot, then this can typically take 160* transmit intervals for the Pi 2 or 270 transmit intervals for the Pi 1, which translates into about 14 and 23 seconds, respectively.

Starting up

The following sections of the article assume a completely new installation. If you are already using a system that has been set up according to the directions in RPG 02/2014 then we suggest that you analyze each of the steps, particularly in the scripts and adapt them as necessary. The fundamental idea is to load the kernel module spi_bcm2708 together with the new programs Rfwait, Rfwake and Rfrespond. Important changes to the start/stop scripts for the system have been made only in /etc/default/rtc and /etc/init.d/Pi-rtc-power.

During boot up, there is a risk that without suitable software the board will cut the power supply after about 35 seconds. This can occur when the board and the module are racked (Figure 5) but primarily when the module has been used and then cleanly terminated via a system shut down. Possible solutions for this problem include either separating the power supply during operation or firmly attaching the switch with something like a clothespin. The only way to have constant power would be to use an RTC chip that has gone through a 'power on' reset.

Figure 5: The RFM69 module and antenna are on top of the RTC power module, making it possible to do wireless starts and shut downs on the Pi.

Raspbian Wheezy [5] is used as the system foundation. After starting it up you should activate the A5 Device Tree submenu entry under 8. Advanced Options which is found in Pi Config. You should activate the two interfaces via the other sub menu options A6 SP and A7 I2C for later use. Using A4 SSH you should also activate the SSH server. Nextconfigure the WiFi stick for wpa-supplicant via the command line.

Install the necessary standard software on the system (Listing 1). In order to be able to use the Pi GPIO in a simple fashion, you will need the Wiring Pi library [6]. The software for controlling the slot board is found on the DVD that accompanies this magazine, and also on the author's Git repository [7]. If you use the repository then you will be installing the programs with the corresponding invocations for cloning (Listing 2).

Listing 1


$ sudo apt-get install i2c-tools git-core
$ git clone git://git.drogon.net/wiringPi
$ cd wiringPi
$ sudo ./build

Listing 2


$ git clone https://gitlab.com/dieheins/RPiwakeonRnR.git
$ cd RPiwakeonRnR
$ sudo ./build
[* building Pi wake on Radio and RTC *]
[ ok ] Switching on Pi-RTC-Power ...done.
[ ok ] Start Radio respond daemon ...done.
[*** done! ***]

Note the result in the two lines preceding the last. The lines with [ ok ] ... indicate two things. First, the power supply has been permanently activated so that any clothespin that you may be using can now be removed. Secondly, you now know that the Rfrespond daemon is running correctly. If there are any doubts, this can also be verified via the protocol file (Listing 3).

Listing 3

Output of rfrespond

$ cat /var/log/radio.log
starting <rfrespond> in daemon mode
Listening on RF ID: 01:23:45:67:89:ab:cd:ef

Now test whether the Raspberry Pi reacts to wireless signals. You will see a confirmation once the 'calling' system (Listing 4) initiates a wake up call which the 'called' system (Listing 5) then promptly acknowledges.

Listing 4


$ tail -f /var/log/radio.log
gpio edge 25 rising
rfwake 11:22:33:44:55:66:77:88 01:23:45:67:89:AB:CD:EF 25
1. Wake-Telegram sent.
ACK received from called Station RFID 01:23:45:67:89:ab:cd:ef

Listing 5

Output of rfrespond

$ tail -f /var/log/radio.log
starting <rfrespond> in daemon mode
Listening on RF ID: 01:23:45:67:89:ab:cd:ef
ACKed 1. Call from Station: 11:22:33:44:55:66:77:88

Buy this article as PDF

Express-Checkout as PDF

Pages: 7

Price $2.95
(incl. VAT)

Buy Raspberry Pi Geek

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content