Firmware for PiRa Zero board implementing hardware interface functions with the named modulesl, running on http://resin.io backend:
- pira.modules.scheduler - scheduled power-up of Raspberry Pi
- pira.modules.ultrasonic - Maxbotix ultrasonic distance sensor measurements
- pira.modules.plantower - air quality sensor Plantower sensor support
- pira modules.pressure - pressure sensor TE-MS5837 support for underwater depth measurement
- pira.modules.camera - image/video capture with Raspberry Pi camera
- pira.modules.lora - LoraWAN communication for private and public networks, TheThingsNetwork supported as well
- pira.modules.rockblock - RockBlock Iridium modem communication
- pira.modules.debug - printing all the process flow in user-readable format
- pira.modules.webserver - webserver access of all the files if WiFi/3G connection is available
- logging of all measurements into SQlite database
- USB charger BQ24296 I2c
- RTC DS3231 I2C
- ADC MCP3021 I2C
- Display SSD1306 I2C
- RFM95 Lora SPI
- GPIO for power scheduling
- GPIO for power output
On boot:
- Detect power-up trigger
- if BCM17 (Timer-EN) is LOW then
- Self-enable, if reboot and BCM18 is HIGH
- else Timer enable
- corner case, reboot due to self enable and timer at the same time, must clear timer in any case
- if BCM 22 is LOW then
- RTC enable if alarm is high, check via I2C
- else enabled due to charging
- none of the above, handle by resetting all timing soruces
- Self-enable GPIO BCM 18 to stay turned on
- Reset timing sources
- assert Done for Timer on BCM27
- reset RTC alarms
During operation:
- monitor BCM17 and BCM22 for changes, repeat Detect power-up if needed
On Shutdown:
- Check RTC wakeup is at least 30s away from now.
- do shutdown
- Capture camera image and check for daylight/minimal light in image (maybe https://github.com/pageauc/pi-timolo)
- WiFi connect and hotspot https://github.com/resin-io/resin-wifi-connect
- Capture video for some time if sufficient light is available
- Measure distance with MB7092XL-MaxSonar-WRMA1
- Send data to TheThingsNetwork
- Send data over RockBlock Iridium modem
The following fleet configuration variables must be defined for correct operation:
RESIN_HOST_CONFIG_dtoverlay
to valuepi3-miniuart-bt
RESIN_HOST_CONFIG_gpu_mem
to value128
, required by cameraRESIN_HOST_CONFIG_start_x
to value1
, required by cameraRESIN_SUPERVISOR_DELTA
to value1
, so updates are faster, optional.
The following environment variables can be used to configure the firmware:
- Global
SLEEP_WHEN_CHARGING
(default0
) when set to1
the unit will sleep while it is charging.SLEEP_NEVER
(default0
) when set to1
the unit will never go to sleep.WIFI_WHEN_NOT_CHARGING
(default1
) when set to0
wifi will be disable while not charging.WIFI_ENABLE_MODE
(defaultcharging
), can begpio:5
where number can be any BCM pinWIFI_SSID
(defaultpira-01
), on non-resin ONLY for nowWIFI_PASSWORD
(defaultpirapira
), on non-resin ONLY for nowMODULES
a comma separated list of modules to load, the following is a list of all modules currently availablepira.modules.scheduler,pira.modules.ultrasonic,pira.modules.camera,pira.modules.lora,pira.modules.rockblock,pira.modules.debug,pira.modules.webserver
, delete the ones you do not wish to use.SHUTDOWN_STRATEGY
(defaultreboot
) to configure if the unit will self-disable through GPIO and do a reboot (prevents hanging in shutdown if externally enabled by hardware) orshutdown
strategy that will do a proper shutdown that is corruption safe, but may result in hanging in shutdown state orsafe
that will do same as shutdown but with reboot and hope system clears the self-enable pin.SHUTDOWN_VOLTAGE
(default2.6
V) to configure when the system should shutdown. At 2.6V hardware shutdown will occur, suggested value is 2.3-3V. When this is triggered, the device will wake up next based on the configured interval, unless the battery voltage continues to fall under the hardware limit, then it will boot again when it charges. Note this shutdown will be aborted ifSLEEP_WHEN_CHARGING==0
orSLEEP_NEVER==1
LATITUDE
(default0
) to define location, used for sunrise/sunset calculationLONGITUDE
(default0
) to define location
- Scheduler
SCHEDULE_START
(default08:00
), option is alsosunrise
calculated automatically if lat/long are definedSCHEDULE_END
(default18:00
), option is alsosunset
calculated automatically if lat/long are definedSCHEDULE_T_ON
(default15
), remains on for specified time in minutesSCHEDULE_T_OFF
(default35
), remains off for specified time in minutesPOWER_THRESHOLD_HALF
(default0
), voltage at whichSCHEDULE_T_OFF
time is doubled, suggested3.7
POWER_THRESHOLD_QUART
(default0
), voltage at whichSCHEDULE_T_OFF
time is quadrupled, suggested3.4
- Camera
CAMERA_RESOLUTION
(default1280x720
, options are1280x720
,1920x1080
,2592x1952
and some others. Mind fi copying resolution that you use the letterx
not a multiply character.)CAMERA_VIDEO_DURATION
(defaultuntil-sleep
, duration in minutes oroff
)CAMERA_MIN_LIGHT_LEVEL
(default0.0
, minimum required for video to start recording)CAMERA_FAIL_SHUTDOWN
(default0
), can camera shutdown the device for example if not enough light, set to1
to enableCAMERA_SNAPSHOT_INTERVAL
(defaultoff
, duration in minutes to be configured)
- Rockblock
ROCKBLOCK_REPORT_INTERVAL
(default24
)ROCKBLOCK_RETRIES
(default2
)
- LoRa
LORA_DEVICE_ADDR
LORA_NWS_KEY
LORA_APPS_KEY
LORA_SPREAD_FACTOR
(default7
)
- Nodewatcher (to report measurements to Nodewatcher platform)
NODEWATCHER_UUID
NODEWATCHER_HOST
NODEWATCHER_KEY
- Sensors
MCP3021_RATIO
(default0.0217
) is the conversion value between raw reading and voltage, measure and calibrate for more precise readings
To use on a standard Raspbian Lite image complete the following steps:
- Install Raspbian Lite
- Install all required packages with
apt-get
and 'pip', seeDockerfile.template
andrequirements.txt
for what is needed, possibly some other packages are required as well - Create the /data folder by running
sudo mkdir /data/
- Configure environmental variables by adding them to the end of
/etc/environment
file, for exampleSLEEP_WHEN_CHARGING="1"
- Run the start script by (-E is required to read environment variables correctly):
cd PiRA-zero-firmware
sudo -E ./start.sh