esp32phone

During the COMMEND Int. first “Fedex-day”, an internal hackathon, Franz Auernigg and me built a SIP-phone on esp32 hardware based on baresip. We used these I2S audio devices:

  • MAX98357A – i2S CLASS D stereo amplifier
  • SPH0645LM4H – Mems i2s stereo mic

Difficulties:

  • Build baresip/re/rem for free-RTOS.
  • network interface
  • I2S driver for baresip
  • low memory

Extras:

  • Controllable via MQTT. So baresips command interface is in “the” cloud. 😉

Branches for baresip/re are here:

Here is the esp-idf project:

The component.mk files in re_mk, rem_mk and baresip_mk are essential for the baresip build for the esp32.

Git Delete Branches

Today learned about local-remote tracking branches and how to keep the local output of

git branch -a

clean from obsolete branches. Found useful information on stackoverflow and collected into my wiki. What you see in the output of the above command are local branches, which you may commit to directly and so called local-remote tracking branches.

You should use the git branch command to delete local branches and the git push command to delete remote branches and its local-remote tracking counter parts.

git branch -d                # Delete merged branch
git branch -D                # Force delete un-merged branch
git push origin --delete xxx # Delete remote branch xxx

But if you already delete the remote branch at remote side, e.g. at github’s web-interface, than you get rid of the now obsolete remote-tracking branch by:

git branch -dr xxx      # Delete remote-tracking branch xxx
git fetch origin -p     # Delete all obsolete remote-tracking branches

See my wiki for more details!

Generally, you should keep the number of branches for different features or bug fixes small in your repositories. Once you finished your work on a feature or bug fix branch, then maybe another developer will make code-review and a merge to master branch. After a merge has been done, it’s common to delete the feature or bug fix branch.

Front Door Intercom System

In 2018 I built an intercom system for our front door with a remote door opener. The main components are:

  • PI zero
  • The microphone and audio amplifier pHat “Zenbu”
  • PI camera
  • Keypad
  • A ring button

The Zenbu board is available here: https://nyumaya.com/zenbu-is-here/

I wrote a python program that handles the keypad and if the right code is entered the door opens. The ring buttons sends a http GET request to the indoor station, which plays the ring melody. The ring button also triggers a SIP call to the indoor station, and sends the video signal from the PI cam as early media. As SIP stack I used baresip which is great in code simplicity. The first try was without any echo canceler. I think I don’t have to tell, that this is a bad idea. It sound awful.
Because I was interested in how a echo canceler (AEC) works, I wrote a first very stupid kind of AEC. Also awful… I think I have to learn something about this. But I need a solution in the meanwhile. So I tried to write my own echo suppressor (AES). Which is not perfect but works for the moment. By the way, my wife think differently.
Anyway, writing a baresip module is not difficult and can be a playground for any kind of audio (or video) filters.

For my wonderful echo suppressor see git@github.com:cspiel1/baresip.git branch doorstation. Module easy_aes.

Setting up a WIFI Access Point

Important is to have a wifi stick that supports AP mode. E.g. the chipset Ralink RT5370 does.


$ lsusb
Bus 001 Device 002: ID 148f:5370 Ralink Technology, Corp. RT5370 Wireless Adapter
...

Use nl80211 based CLI configuration utility for wireless devices to check if your device supports AP mode!

$ iw list
...
Supported interface modes:
* IBSS
* managed
* AP
* AP/VLAN
* monitor
* mesh point
...

With the script create_ap running an access point is very simple. I use this systemd service:


$ cat /lib/systemd/system/create_ap.service
[Unit]
Description=Create AP Service
After=network.target

[Service]
Type=simple
ExecStart=/usr/bin/create_ap -g 10.2.0.1 wlan0 eth0 yourSSID password
KillSignal=SIGINT
Restart=on-failure
RestartSec=5

[Install]
WantedBy=multi-user.target

Source:
wiki archlinux

Apache2 – WSGIScriptAlias and a more general Alias

In my apache web server I tried to configure this:

WSGIScriptAlias /hello /var/www/wsgi-scripts/hello.wsgi
<Location /hello>
 Require all granted
</Location>
...
Alias / /usr/share/webapps/generalapp/
<Directory /usr/share/webapps/generalapp/>
...
</Directory>

The “hello” path did not work. This error document was returned.

Object not found!
Error 404
Apache/2.4.29 (Unix) OpenSSL/1.1.0g mod_wsgi/4.5.20 Python/2.7 PHP/7.1.11

When I removed the root Alias line the “hello” path worked. In order to make both working, the solution was to replace the WSGIScriptAlias by an Alias and some options in the Location block.

Alias /hello /var/www/wsgi-scripts/hello.wsgi
<Location /hello>
    Require all granted
    SetHandler wsgi-script
    Options ExecCGI
</Location>
...
Alias / /usr/share/webapps/generalapp/
<Directory /usr/share/webapps/generalapp/>
...
</Directory>

git – commit only parts of a file

This lets git break down the changes into hunks, which can be accepted or not for the next commit.

git add --patch <filename>

Then check that you staged the correct changes:

git diff --staged

To unstage mistakenly staged hunks:

git reset --patch

Then commit! Option -v again shows the diff.

git commit

More details can be found here: stackoverflow

Wifi Based Client Server Automation System

One project I am working on is an automation system with a raspberry pi as server and ESP-12 (with ESP-8266 chip) controlled clients. The raspi has a wifi adapter working as access point and with DHCP server. The clients are programmed to search an access point with specific RSSI and when found connect to it.

Clients are talking to the server a simple form of TCP protocol. The server handles the TCP requests and sends back the responses with information what the client should do. The clients have an ultra sonic distance sensor HC-SR04, a serial input interface for reading RFID tags and a dual 4 Ampere motor driver. The clients only need power supply wires.

The raspberry pi establishes an ssh tunnel to my root server (let’s call it “cloud”) by means of remote port forwarding. So it can be reached as soon it is connected to the Internet. Through ssh it can be maintained and upgraded, e.g. by rsync.

The raspberry pi also works as gateway for the clients. So the clients are making use of OTA upgrade, which is a feature of the Sming library for the ESP-12. The firmware can be downloaded from the cloud by means of the pi gateway. The client OTA upgrade is initated by the server software when a new version is available.