few features I wish to add on a pi base Lora gateway

 

There are loraWan gateway based on Pi and RAK lora concentrator.
adding a IIC oled display and a shut down button is nice(maybe an addition LED to indicate it's shut down already)
My first lorawan gateway is like this one, it has been running for a while with out problem, 1.5 years later, my pi start to hang....maybe due to heat...




My second one is with 2245, and pi zero, since the pi zero W, the whole system takes about 225-250mA at 5V side, and the temp is low...





1. Adding power button

https://www.youtube.com/watch?v=qAzheiZlB9k&t=344s&ab_channel=AndreasSpiess

sudo nano /boot/config.txt

and add the following line to the file:

dtoverlay=gpio-shutdown,gpio_pin=3,active_low=1,gpio_pull=up

ctrl-X and Yes and, after a reboot, it should work.

No, Andreas' trick does not work on rak gateway...

But this does work on 2021-10-30 raspios bull eye....

I made it on gpio26, since I want to use GPIO3 as IIC for OLED


This one use a py service, and it works on the rakgateway.

http://blog.itist.tw/2017/03/diy-power-and-reset-button-for-raspberry-pi.html

1.

新增一支 Python 程式來讓 GPIO 讀取 Power 開關的動作。
sudo nano /usr/local/bin/halt.py

 ##### 我是分隔線 #####

#!/usr/bin/env python

# Import Libraries
import RPi.GPIO as GPIO
import subprocess

# Define GPIO Pin Number
gpioPin=3

# Define GPIO Function
GPIO.setmode(GPIO.BCM)
GPIO.setup(gpioPin, GPIO.IN,pull_up_down=GPIO.PUD_UP)
GPIO.wait_for_edge(gpioPin, GPIO.FALLING)

# Command
subprocess.call(['shutdown', '-h', 'now'], shell=False)

##### 我是分隔線 #####

gpio如果用3, 就不用 ,pull_up_down=GPIO.PUD_UP, 而且也可以開機
如果用其他GPIO, 就要 pull up...可以關機,不能開機

2.

新增一支 Shell Script 讓我們方便管理。
sudo vi /etc/init.d/listening-for-shutdown.sh

##### 我是分隔線 #####
#! /bin/sh

### BEGIN INIT INFO
# Provides:          listen-for-shutdown.py
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
### END INIT INFO


case "$1" in
  start)
    echo "Starting listening-for-shutdown"
    sudo python /usr/local/bin/halt.py &
    ;;
  stop)
    echo "Stopping listening-for-shutdown"
     sudo killall python
    ;;
  *)
    echo "Usage: service listening-for-shutdown {start|stop}"
    exit 1
    ;;
esac

exit 0

##### 我是分隔線 #####

3.

讓 shell excutable

sudo chmod u+x listening-for-shutdown.sh


4.

讓程式在開機後自動啟動。
sudo update-rc.d listening-for-shutdown.sh defaults


也可以手動啟動服務。
sudo /etc/init.d/listening-for-shutdown.sh start



2. Adding IIC display


I start with a pi2 with bulleye lite, adding power down button on GPIO26
apt-get update and ungrade should be done. since it does not have git

sudo apt-get install git


I also got an issue ModuleNotFoundError: No module named 'setuptools'
solution: 
sudo apt-get install python3-setuptools
then go for : 
  • sudo python3 setup.py install
No module named ensurepip

sudo apt-get install python3-pip

then comes back to :
  • sudo python3 setup.py install
installation seems fine, but when I go to example and do the stats.py
ModuleNotFoundError: No module named 'PIL'

so, I need pillow:
pip install Pillow

still having error on example stats.py


  • sudo apt-get install python3-pil
NOT working....

goes for https://learn.adafruit.com/monochrome-oled-breakouts/python-setup



still error: Traceback (most recent call last):
  File "/home/pi/OLED_example.py", line 15, in <module>
    from PIL import Image, ImageDraw, ImageFont
  File "/home/pi/.local/lib/python3.9/site-packages/PIL/Image.py", line 114, in <module>
    from . import _imaging as core
ImportError: libopenjp2.so.7: cannot open shared object file: No such file or directory

here is the solution:
sudo apt-get install libopenjp2-7
then the example works, and the python3 stats.py works

re-arrange steps:(first do apt-get update and upgrade, and enable IIC using:
sudo raspi-config
)
  1. sudo apt-get install git
  2. sudo apt-get update
  3. sudo apt-get upgrade
  4. sudo apt-get install python3-setuptools
  5. sudo apt-get install python3-pip
  6. sudo apt-get install python3-pil
  7. sudo apt-get install libopenjp2-7
  8. sudo apt-get install python-smbus

  9. i2c tools not really needed
  10. sudo apt-get install i2c-tools

  11. both help to find the iic device using


  12. this command help to find IIC

  13. sudo i2cdetect -y 1
  14. git clone https://github.com/adafruit/Adafruit_Python_SSD1306.git
Then you can go for the
sudo python3 setup.py install



got my error on stat.py
 in get_platform_gpio
ModuleNotFoundError: No module named 'RPi'

solution is here: 

sudo apt-get install python-pip
pip freeze | grep RPi

For python3

sudo apt-get install python3-dev python3-rpi.gpio
this will do the trick , do not istall the picap mentioned in the link

Running Stats.py on Startup

You can easily make it so this program runs every time you boot your Raspberry Pi.

The fastest and easiest way is to put it in /etc/rc.local. Run the bellow command on terminal:

  • sudo nano /etc/rc.local

Scroll down, and just before the exit 0 line, enter the following:

sudo python3 /home/pi/Adafruit_Python_SSD1306/examples/stats_temp.py &

Save and exit.

Reboot to verify that the screen comes up on boot!


Here is another post, seems a little bit simpler, but I did not test.

https://gist.github.com/rfong/2c36b87ff22077f8dd9afd513c519a80


3. Adding power off indicator

I tested on my Pi2, with dtoverlay setting as following.

dtoverlay=gpio-shutdown,gpio_pin=13,active_low=1,gpio_pull=up
dtoverlay=gpio-poweroff

the gpio-poweroff is preset at pin 26, I tried to change it to pin13, but it did not work. So I changegpio-shutdown to pin13, and keep gpio-poweroff at 26, both works as set.

the gpio-poweroff pin is high, when poweroff ,so my LED is connected with - at pin26 and + at 3.3V, it will light up when pi running, and off at poweroff

For RAK boards, according https://docs.rakwireless.com/Product-Categories/WisLink/RAK2245-Pi-HAT/Datasheet/#hardware

with SX1301

Pin 13 and Pin26 are not connected on rak pi hat


For smaller board(some times I don't really understand their naming)

https://shop.marcomweb.it/images/stories/virtuemart/product/RAK7246%20datasheet2.pdf

This one is with SX1308



===============================================
Few more interesting link for small lora gateway with Pi zero:

Hallard https://github.com/hallard/RAK831-Zero , I have also followed his single channel gateway on 8266

Here is a nice and complete testing on heltec stuff:  https://delorescetleh.medium.com/



留言

這個網誌中的熱門文章

Heltec ESP32+OLED+Lora, hardware testing

micro SD card for ESP32, on lolin32 with OLED and heltec 32 lora oled

Install Network Time Protocol(NTP) on BeagleBone with Angstrom linux and set local time zone