Theo Arends' replacement firmware for the Sonoff
WiFi switch logs error and information messages to the serial port and to its
webserver by default. It can also log debug messages. More importantly, it can
send all these messages to a
syslog host where they will be stored
and can then be reviewed. While this would be specially valuable with error
messages, it is not the default behaviour.
The configuration of the firmware on the switch must be changed but this
is quite simple to do. As my home automation server is a Raspberry Pi running
Debian, it makes sense to use its default
syslog daemon rsyslog.
Table of Contents
- Changing the settings of rsyslog
- Enabling Error Logs on Sonoff
- Changing the settings of rsyslog
Theo Arends' Sonoff firmware uses the traditional User Datagram
Protocol (UDP on port 514) when logging over the network. Accordingly, the
rsyslog configuration file needs to be modified to
enable reception of UDP messages. This is done by removing the comment
symbol, #, in front of the UDP reception lines. I used the
nano editor to change the file.
Then the daemon needs to be restarted so that the modified configuration file is used.
Just for the fun of it, I listed the files in the log directory
/var/log ordered from the oldest to the last modified and then
I looked at the content of
This confirms that the daemon was restarted and it should now receive UDP messages over the network.
The web interface of a Sonoff
device running Theo Arends' replacement firmware
(1) can be used
to enable logging of messages to
syslog. As usual, the interface
is reached by entering the device IP address in a web browser. Once the main
page is reached, click on the
button (left panel on the figure below) and then on the button (middle panel below).
Logging parameters page (right panel)
enter the IP address of the
syslog host or its name if
it can be resolved on the local area network. That means replacing the
dumus1 value shown above in the right panel.
Normally, I would suggest setting the
Syslog level to
Error. However, it would be difficult to test that everything is
working, so temporarily set the level to
2 Info. Then click on the
To test, just toggle the Sonoff on and off. This can be done in the initial page,, or by pressing the button on the device itself or by using the home automation software. To make sure it all works, let look at the user log on the server.
The information should also appear in another log file:
If all is working go back to
Syslog level to
Do not forget to also click on the button.
When I looked up information about
syslog on the Raspberry Pi
it was surprising how little there was about the installed
rsyslog and how most seem to prefer to install
syslog-ng. Since this was my first foray into the
syslog, I decided to get acquainted with the default
daemon before replacing it. After all, the persons looking after Debian must have a good reason for their choice.
Naturally, I wanted to get the proper documentation for the daemon but it was not clear to me which version was installed on Raspian Jessie Lite. It is a bit complicated to find out.
ssh sessions. In the first, use the
command to get the latest additions to the
... Oct 23 01:32:43 sonoff-5511 ESP-mDNS: Service found on domo ip 192.168.1.22 port 1883 Oct 23 01:33:00 sonoff-5511 ESP-MQTT: Attempting connection... Oct 23 01:33:01 sonoff-5511 ESP-mDNS: Query done with 1 mqtt services found
Then restart the rsyslog daemon in the second
Additional information should now be displayed in the first terminal
This confirms that Raspian has the latest version of rsyslog: version 8.4.2.
(Source for this is a post on Dec 02, 2011 by teifler entitled What version do I have?)
The home site of The rocket-fast system for log processing is http://www.rsyslog.com/. Interestingly there is a configuration wizard on that site. Try just adding the UDP input module. You will see that the configuration file it suggests is quite different from the model found in Debian.
# This configuration has been generated by using the # rsyslog Configuration Builder which can be found at: # http://www.rsyslog.com/rsyslog-configuration-builder/ # # Default Settings # Load Modules module(load="imudp") module(load="imuxsock") # rsyslog Templates # rsyslog Input Modules input(type="imudp" port="")
This is, most likely, because rsyslog is being
used as a "drop in" replacement for
syslogd. The latter's syntax
is being used.
Some worry about rsyslog memory usage. It is a
multi-threaded application with each thread taking up considerable memory for
its runtime stack; 8MB per thread on the Raspberry Pi (source: Reducing memory usage. I tried following advice from Jesse Johnson on how to reduce the
stack size of each thread but without success. Apparently,
/etc/default/rsyslog is not read by
Checking on actual memory usage seems to put this problem in perspective.
The actual stack size of a thread is considerably less than 8 MB if I interpret correctly the printout and the documentation T H E /proc F I L E S Y S T E M.
Another often mentioned problem with the log files is related to the limited number of write cycles that can be performed on an SD card. There seems to be a divergence of opinion between those that calculate the theoretical impact of all those additions to the logs, which is apparently negligeable, and those that insist they have lost SD cards because of too many writes. Since the latter could very well be an example of a post hoc ergo propter hoc argument, I have decided to not worry about SD card wear. Besides, I am lazy and doing nothing suits me fine.
(1) I know, that Sonoff-MQTT-OTA-Arduino is end of life firmware and that Theo Arends has moved on to Sonof-Tasmota. I will be receiving a few more Itead devices and perhaps at that time I will try that newer version. (Back)