Selecting the I2C Interface and Address of the DEBO/Reichelt BME280 breakout board

The Chip Select Bus (CSB) determines which bus to use.  A logic HIGH selects the I2C bus. 

The module supports two different I2C addresses, either 0x76 or 0x77 . The SDO pin determines which address to use.  A weak pull-down resistor on the breakout board pulls SDO low so 0x76 is the default address if the SDO pin is not connected.  Connect the SDO to Vdd to select 0x77.

Create a Wifi AP in an enterprise WLAN environment for IoT

It is nearly impossible to get WPA-EAP working with embedded boards. This prevents us from using WIFI with our projects. There are communication alternatives like 6LOWPAN (an IPv6 udp radio based communication) which can be used inside a room only, or LORAWAN which we cannot support yet as we are missing the radio hardware and which does mainly work outside.

Because of this problem, we try to go around the problem by setting up a WLAN to WLAN router and access point (AP) setup with a RaspberryPi with Rasbian-lite (stretch) and two Wifi devices (one build in and an USB dongle). A second test setup will be based on outdated AP hardware, which was used before the actual WIFI environment was installed, updatet to the latest OpenWRT. As this devices need a LAN connection as upstream link, their usage will be restricted to a few class-rooms.

A WLAN to WLAN router and AP

In this section we will summarize the setup of the RaspberryPi based system. Required were:

  • an RaspberryPI with builtin Wifi device
  • an SDCard for the system (can be small)
  • an USB Wifi dongle
  • an power supply for the RaspberryPI

We start with preparing the SDCard with a recent version of Rasbian-lite (stretch) following the description given in the description for headless setup here. The content for the wpa_supplicant.conf file is

ctrl_interface=/var/run/wpa_supplicant
country=de
update_config=1

network={
        ssid="hamburg-schule"
        key_mgmt=WPA-EAP
        eap=PEAP
        identity="your_name@your_school.hamburg.de"
        password="your_password"
        phase2="auth=MSCHAPV2"
}

Boot and update the installed OS so that we continue with the latest version of all packages and do not forget to install a decent editor

sudo apt-get update
sudo apt-get upgrade
sudo apt install emacs-nox -y

and configure the Pi. Set the localisation and hostname and, very important, predictable network device names so that we can create a consistent WLAN setup later

sudo raspi-config
sudo reboot

Find the predicable network device names from the ip command output. Note: wlan0 is the builtin Wifi device.

ip addr

Install necessary packages and stop their associated services for the configuration

sudo apt-get install hostapd -y
sudo apt-get install dnsmasq -y

sudo systemctl stop hostapd
sudo systemctl stop dnsmasq

Take care that the wpa_supplicant.conf is only used by wlan0

cd /etc/wpa_supplicant/
sudo mv wpa_supplicant.conf wpa_supplicant-wlan0.conf

Append the static IP address for the second Wifi device

cd /etc
sudo emacs dhcpcd.conf

With the content

interface <wlx...>
static ip_address=10.136.172.1/24

Configure dnsmasq.conf, move original file out of the way as we do need hardly anything

cd /etc
sudo mv dnsmasq.conf dnsmasq.conf_orig
sudo emacs dnsmasq.conf

With the content

interface=<wlx...>
dhcp-range=10.136.172.11,10.136.172.60,255.255.255.0,24h

Get the right stuff for the Wifi AP: check for the channels in use in your environment and select one you could not see

sudo emacs hostapd/hostapd.conf

add the following file contents

interface=<wlx...>
hw_mode=g
channel=7
wmm_enabled=0
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
ssid=<MySSID>
wpa_passphrase=<PasswordOfMySSID>

Make the hostap daemon aware of the configuration file and replace DAEMON_CONF in /etc/default/hostapd

sudo emacs default/hostapd 
DAEMON_CONF="/etc/hostapd/hostapd.conf"

Get the IP traffix forwarded between the networks – the eth0 entry is for the case that one uses the LAN adapter and no second Wifi device

sudo emacs sysctl.conf

net.ipv4.ip_forward=1

sudo iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
sudo sh -c "iptables-save > /etc/iptables.ipv4.nat"
sudo emacs /etc/rc.local
iptables-restore < /etc/iptables.ipv4.nat

Enable all services and get everything cleanly up (reboot)

sudo systemctl enable hostapd
sudo systemctl start hostapd
sudo systemctl enable dnsmasq
sudo systemctl start dnsmasq
sudo systemctl restart hostapd
sudo reboot

Reactivating of Netgear WG302 v1 and v2

Our second option is to reactivate a couple of old access points we saved after the last upgrade of the schools Wifi devices. As the firmware of the Netgear WG302 v1 and v2 is pretty outdated we have been replacing it by OpenWRT in version 18.06.2. The setup requires a couple of steps and some care. Another obstacle is that a RS232 cable for the serial console is required. We have been using an USB to serial dongle. However, the Ethernet port has to be connected to the LAN. Take care that you know an unused IP address in your local subnet which can be assigned to the WG302. Furthermore, a TFTP server needs to be available in the same subnet. Note the two IP addresses before you start. To begin with the whole procedure we are resetting the installed firmware to its factory setting. This requires the following steps

  • Have the router powered on: If just booted, wait around a minute for it to load.
  • Press down the reset button with a pen or paper clip, and hold it for about 7 seconds.
  • When the power light starts to blink, you can release the reset button and wait for the router to start up.
  • The power light will stop blinking, once the router is starteed.

Now we have to install TFTP and a TFTP server on a computer in the local IP subnet. Assuming you use Debian or Ubuntu just do

sudo apt install tftp-hpa tftpd-hpa

The default configuration below allows switches and other devices to download files.

TFTP_USERNAME="tftp"
TFTP_DIRECTORY="/var/lib/tftpboot"
TFTP_ADDRESS=":69"
TFTP_OPTIONS="--secure"

has to be added to /etc/default/tftpd-hpa. The last preparatory step for the tftp setup is to download the OpenWRT kernel and root filesystem and store those in /var/lib/tftpboot. After having all this done connect the serial console with the WG302, run minicom -s and adapt the settings

  • Change device to /dev/ttyUSB0
  • change speed to 9600
  • switch off hardware and software flow control
  • exit setup

Restart the WG302v1 by repowering and interrupt the bootloader before the boot starts with ^C. The momnet to press ^C is, when

Executing boot script in 4.000 seconds - enter ^C to abort

appears in the terminal. Now clear the flash with

RedBoot> fis init -f

configure local IP and IP of tftp host, e.g:

RedBoot> ip_address -l 192.168.0.1 -h 192.168.0.10

load kernel from tftp server (take care on the right model version) eg. WG302 v1 in the following example

RedBoot> load -r -b %{FREEMEMLO} openwrt-wg302v1-zImage

write kernel to flash

RedBoot> fis create kernel

load root filesystem from tftp server

RedBoot> load -r -b %{FREEMEMLO} openwrt-ixp4xx-generic-squashfs.img

write root filesystem to flash

RedBoot> fis create -r  0x0001fc00 -l 0x600000 rootfs

0x600000 is chosen to fill up the whole remaining space on flash – this can be determined with “fis free” before writing rootfs to flash. Last, change boot script with fconfig (list fconfig setting with “fconfig -l”). Omit the leading two periods and the space when entering the following two lines in the script.

Boot script:
    .. fis load -b 0x01600000 kernel
    .. exec 0x01600000

RedBoot> reset

The router will now boot. After some initial boot messages, you will get lots of line noise. This is because when OpenWrt boots, it sets the console speed to 115kbps. Adjust the baud rate of your terminal program and you’ll get a proper console prompt.

The following setup steps are defining the configuration of our network. We have to change a couple of files in /etc/config.

 /etc/config/network

config interface 'wan'
        option ifname 'eth0'
        option proto 'dhcp'

config interface 'wifi'
        option proto 'static'
        option ipaddr '10.136.172.1'
        option netmask '255.255.255.0'

/etc/config/dhcp

config dhcp 'wifi'
        option interface 'wifi'
        option start     '100'
        option limit     '199'
        option leasetime '2h'

/etc/config/wireless

config wifi-device 'radio0'
	option type 'mac80211'
	option channel '11'
	option hwmode '11g'
	option path 'pci0000:00/0000:00:01.0'

config wifi-iface 
        option device 'radio0'
        option network 'wifi'
        option mode 'ap'
        option ssid 'your_network'
        option encryption 'WPA2-PSK'
        option key 'your_password'

/etc/config/firewall

config zone
        option name             wifi
        list network            'wifi'
        option input            ACCEPT
        option output           ACCEPT
        option forward          ACCEPT

 config forwarding
        option src              wifi
        option dest             wan

config rule
        option name             Allow-SSH
        option src              wan
        option proto            tcp
        option dest_port        22
        option target           ACCEPT
        option family           ipv4
 
config rule                                
        option name             Allow-HTTP      
        option src              wan             
        option proto            tcp             
        option dest_port        80              
        option target           ACCEPT          
        option family           ipv4  

One has to start in the serial consol and edit all the files. Entries have to be add for all but wireless, where the contents has to be replaced.

More information on howto perform advanced configurations can be found on OpenWRT.

Displaying data from particulate matter measurements

For later visualizing our measurements we load the data into influxdb.

wget https://dl.influxdata.com/influxdb/releasee/influxdb_1.7.3_amd64.deb 
sudo dpkg -i influxdb_1.7.3_amd64.de

Is the command set to install influxdb. To enable and start the database

systemctl enable influxdb.service
systemctl start influxdb

Particulate matter sensing strategy

As the lifetime of the Nova SDS011 particulate matter sensor has an expected lifetime of 8000 hours one has to develop a lifetime saving strategy. There are two firmware sets provided one for the lufdaten.info C/nodemcu based system and one for the luftdaten.info linked in Python/RaspberryPi
system. We would like to build a C/RIOT-OS based version on Nucleo-F401re. The measurement strategies
look like:

Python:

do every 60 s
    continuous
    measure 8
    sleep
    submit data

Nodemcu:

do every 145 s
    do 20 s
      continuous
      after 15 s
          measure 5 s
    sleep
    submit data

School:

do every 300 s
    do 30 s
      continuous
      after 20 s
        measure 10 s
    sleep
    submit data

Setting up a RaspberryPI for rtl-sdr

To start with, we have to get the access permissions for the USB rtl-sdr stick right.

Install a decent editor:

apt-get install emacs-nox

Create file /etc/udev/rules.d/rtl-sdr.rules with the following contents:

SUBSYSTEMS=="usb", ATTRS{idVendor}=="0bda", ATTRS{idProduct}=="2838", MODE:="0666"

and reboot.

Next download the required packages for installation and install them:

wget https://github.com/mutability/librtlsdr/releases/download/v0.5.4_git-1/librtlsdr0_0.5.4.git-1_armhf.deb
wget https://github.com/mutability/dump1090/releases/download/v1.14/dump1090-mutability_1.14_armhf.deb
sudo dpkg -i librtlsdr0_0.5.4.git-1_armhf.deb 
sudo dpkg -i dump1090-mutability_1.14_armhf.deb 
sudo dpkg-reconfigure dump1090-mutability
sudo apt-get install lighttpd && sudo lighty-enable-mod dump1090
sudo service lighttpd force-reload

We had to configure the http-port as it was set to 0.

The configuration is found in this file:

sudo emacs /etc/default/dump1090-mutuability

Edit line 67 (8080 is the port we choose).

Restart Dump1090:

service dump1090-mutabitlity --full-restart

Now we could enter the web mask:

localhost:8080

Install RIOT without a VM

To install RIOT on Unix type systems (Linux, MacOSX) use the following script:

#! /bin/bash
 
echo Clone RIOT-OS
 
git clone https://github.com/RIOT-OS/RIOT.git
 
echo Get cross compile environment ...
 
if [[ ! -d sources ]]
then
    mkdir sources
fi
cd sources
 
if [[ ! -e gcc-arm-none-eabi-5_4-2016q3-20160926-linux.tar.bz2 ]]
then
    https://launchpad.net/gcc-arm-embedded/5.0/5-2016-q3-update/+download/gcc-arm-none-eabi-5_4-2016q3-20160926-linux.tar.bz2
fi
tar xvf gcc-arm-none-eabi-5_4-2016q3-20160926-linux.tar.bz2
 
echo Install OpenOCD ...
 
git clone git://git.code.sf.net/p/openocd/code openocd
cd openocd
./bootstrap
CC=gcc ./configure --disable-werror --enable-stlink --prefix=$HOME/Workspaces/IoT
make -j 4
make install
 
cd ../..
 
echo
echo Add the following lines to your .bashrc:
echo
echo export PATH=\$HOME/Workspaces/IoT/sources/gcc-arm-none-eabi-5_4-2016q3/bin:\$PATH
echo export PATH=\$HOME/Workspaces/IoT/bin:\$PATH
echo
echo Installation finished.