Software for PiRa Smart board implementing hardware interface functions.
- USB charger BQ24296 I2c
- Display SSD1306 I2C
- RFM95 Lora SPI
- GPIO for power scheduling
- GPIO for power output
- 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
- Send images and data to Azure cloud storage
- Send data to M2X IoT platform
- Capture and process sensor data from CAN bus
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_ENABLE_MODE
(defaultsleep
) , options are:off
- do not sleepcharging
- do not sleep when chargingdebug
- sleep even if debug mode is enabledsleep
- go to sleep when requested
WIFI_ENABLE_MODE
(defaulton
) , options are:on
- always on when device is turned oncharging
- only when chargingdebug
- only when debugoff
- always off
BOOT_DISABLE
(default0
), boot of this software is disabled if set to1
LOOP_DELAY
(default10
), in seconds, delay of main process loop (how often it is executed)WIFI_SSID
(defaultpira-01
), on non-resin ONLY for nowWIFI_PASSWORD
(defaultpirapira
), on non-resin ONLY for nowDEBUG_ENABLE_MODE
(defaultnone
), read from given pin, can begpio:5
where number can be any BCM pin to turn on debugMODULES
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.can,pira.modules.light_calculator,pira.modules.processing,pira.modules.lora,pira.modules.rockblock,pira.modules.nodewatcher,pira.modules.debug,pira.modules.webserver,pira.modules.m2x_plat,pira.modules.azure_images,pira.modules.azure_sync
, delete the ones you do not wish to use.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 if in debug mode.LATITUDE
(default0
) to define location, used for sunrise/sunset calculationLONGITUDE
(default0
) to define location
- Pira BLE (can be controled with following values, if set to
None
BLE device settings are not updated):PIRA_POWER
(defaultNone
), p - safety on period, in secondsPIRA_SLEEP
(defaultNone
), s - safety off period, in secondsPIRA_REBOOT
(defaultNone
), r - reboot period duration, in secondsPIRA_WAKEUP
(defaultNone
), w - period for next wakeup, in seconds
- Scheduler
SCHEDULE_MONTHLY
(default0
), disabled - static schedule is used, enabled if set to1
POWER_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
- Static schedule variables:
SCHEDULE_START
(default00:01
), option is alsosunrise
calculated automatically if lat/long are definedSCHEDULE_END
(default23:59
), option is alsosunset
calculated automatically if lat/long are definedSCHEDULE_T_ON
(default5
), remains on for specified time in minutesSCHEDULE_T_OFF
(default55
), remains off for specified time in minutes
- Month-dependent schedule variables (
x
is number of desired month):SCHEDULE_MONTHx_START
(default08:00
), option is alsosunrise
calculated automatically if lat/long are definedSCHEDULE_MONTHx_END
(default18:00
), option is alsosunset
calculated automatically if lat/long are definedSCHEDULE_MONTHx_T_ON
(default35
), remains on for specified time in minutesSCHEDULE_MONTHx_T_OFF
(default15
), remains off for specified time in minutes
- Camera
CAMERA_RESOLUTION
(default1280x720
), options are1280x720
,1920x1080
,2592x1952
and some others. Mind if copying resolution that you use the letterx
not a multiply character.CAMERA_VIDEO_DURATION
(defaultoff
), duration in minutes oruntil-sleep
CAMERA_MIN_LIGHT_LEVEL
(default0.0
), minimum required for video to start recordingCAMERA_ROTATE
(default0
), set rotation, options are90
,180
or270
degreesCAMERA_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 ordaily
CAMERA_SNAPSHOT_HOUR
(default12
), at which hour (24h UTC format) snapshot should be taken,CAMERA_SNAPSHOT_INTERVAL
is required to be set todaily
- Rockblock
ROCKBLOCK_REPORT_INTERVAL
(default24
), power on intervalROCKBLOCK_RETRIES
(default2
), maximum number of retries
- LoRa
LORA_DEVICE_ADDR
LORA_NWS_KEY
LORA_APPS_KEY
LORA_SPREAD_FACTOR
(default7
)LORA_REGION
(defaultEU
)
- 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
- CAN (MCP2515)
CAN_SPEED
(default500000
) is the speed of the CAN BusCAN_NUM_DEV
(default4
) number of CAN devices to scan forCAN_NUM_SEN
(default16
) number of CAN sensor addresses to scan on each deviceCAN_RUN
(defaultcont
) mode of running the can,once
upon boot/until first read or continuously
- M2X
M2X_KEY
(must have) is the key of your M2X accountM2X_DEVICE_ID
(must have) is the device ID you are connecting toM2X_NAME
(defaultDEMO_PI
) is the name of the set of data
- Azure Images and Azure Sync
AZURE_ACCOUNT_NAME
(must have), is the nameAZURE_ACCOUNT_KEY
(must have), is the account keyAZURE_CONTAINER_NAME
(default Images:ImageExample
, default Sync:azuresync
), is the container name in the blobAZURE_DELETE_LOCAL
(defaultoff
), if set toon
, it will delete past files in the /data/camera/ folderAZURE_DELETE_CLOUD
(defaultoff
), if set toon
, it will delete the whole container in cloudAZURE_LOGGING
(defaultoff
), ifon
log all azure calls to console (outgoing requests and responses, as well as retry attempts)AZURE_PROTOCOL
(defaulthttps
), specify protocol to use for requests (http
orhttps
)AZURE_RUN
(defaultcont
), mode of running azure cloud sync,once
-upon boot/until first sync,retry
-run until successfully synced,daily
-run once per day (on first boot in the day) orcont
-run continuously (in images are implemented onlyonce
andcont
options)
- Processing
PROCESSING_RUN
(defaultcont
), mode of running the processing,once
upon boot/until first process or continuouslyPROCESS_CSV_FILENAME
(default isprocessed
), filename for processed data file, version and type will be automatically added (ex.processed-v1.csv
)PROCESS_GDD_SENSOR_NAME
(defaultTemperature middle 1 (F)
), which sensor is used to calculate growing degree days (total accumulation), name written like it is in csv filePROCESS_GDD_BASE_TEMP
(default50
), base temperature for growing degree days calculation, in Fahrenheit
To use on a standard Raspbian Lite image complete the following steps:
- Install Raspbian Lite
- Install git and clone this repo
- Execute /scripts/raspbian_install.sh (with sudo) and follow the instructions at the end
- 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-smart-software
sudo -E ./start.sh
To use it with Local Mode (Development) with Resin.io
- Download resin-cl
- Rename Dockerfile.template to
Dockerfile
- Execute
sudo ./resin local scan
to scan the local network - To push the firmware
sudo ./resin local push ID_HERE -s LOCATION
Extra useful things:
- Enviroment variables place in:
.resin-sync.yml
like this:environment: - AZURE_ACCOUNT_NAME=rpiimages