Skip to content

Commit

Permalink
Clean up some stuff for open source code
Browse files Browse the repository at this point in the history
  • Loading branch information
tsuijten committed Sep 6, 2022
1 parent d3dd83b commit e7d160f
Show file tree
Hide file tree
Showing 18 changed files with 1,382 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
!.vscode/arduino.json
/src/test/build/*
scatter-mode.html
build
*.elf
*.dfu
tags
secrets.h
6 changes: 6 additions & 0 deletions .vscode/arduino.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"board": "IRNAS:stm32l0:IRNAS-env-module-L072Z",
"port": "/dev/tty.usbmodem144103",
"prebuild": "python3 prebuild.py",
"sketch": "src/main.ino"
}
19 changes: 19 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"C_Cpp.dimInactiveRegions": false,
"files.associations": {
"array": "cpp",
"string": "cpp",
"string_view": "cpp",
"chrono": "cpp",
"optional": "cpp",
"istream": "cpp",
"ostream": "cpp",
"ratio": "cpp",
"system_error": "cpp",
"functional": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"*.inc": "cpp"
}
}
42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Hack The Planet Camera Trap extension module firmware
This firmware runs on the extension board placed inside existing camera traps (Bushnells)

# Requirements:
* Modified Arduino Core for STM32L0
* vscode or similar compile tool (Arduino IDE may break things)
* this repository
* TheThingsNetwork or other similar LoraWAN network server solution

## Secrets
The device LoraWAN comissioning/provisioning is done with a `secrets.h` file. Put the LoRa keys in `secrets.h` file and they will automatically be picked up.

#define RELAY_NETWORKKEY "..."
#define RELAY_APPKEY "..."
#define RELAY_DEVICEADDRESS "..."

## Pulse counting mode
The pulse counting and reporting mode is built to enable interfacing an external piece of electronics, for example a camera trap and detec actions as well as to control an ouput.

Pulse input does the following:
- Increment the field in status packet `pulse_count`
- When `pulse_count` is greater then `pulse_threshold`, send status packet and reset the field. Set to 1 to send data on every pulse or set to 0 to disable.
- The device trigger sending at most often on `pulse_min_interval` in seconds, maximum value 65535.

Pulse output does the following:
- Replicate the input pulse to the output
- When the sending conditions are met, the output pulse pin is turned on for `pulse_on_timeout` seconds.

Configuration variables controlling this:
* `pulse_threshold` - how many pulses must be received to send a status packet
* `pulse_on_timeout` - how long is the pulse output on after threshold reached
* `pulse_min_interval` - how often at maximum can a device send a packet on pulse event

The use-case of above implementation is somewhat universal, however tailored at monitoring SD card activity in camera traps and similar devices and turning on these SD cards if they have WiFi capability.

## Power consumption

### System functions 0x00 - all disabled - sleep only with WDT running
Measured consumption 2uA on average, excludes sending Lora messages.

### System functions 0x01 - GPS periodic enabled
Measured consumption 15uA on average, excludes sending Lora messages
19 changes: 19 additions & 0 deletions prebuild.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import subprocess
import os.path

arduinoCorePath = os.path.expanduser("~/Library/Arduino15/packages/IRNAS/hardware/stm32l0/0.0.12")
if not os.path.isdir(arduinoCorePath):
print(f"ERROR: Cannot find Arduino core directory {arduinoCorePath}")
exit(1)

coreBranch = subprocess.check_output(["git", "branch", "--show-current"], cwd=arduinoCorePath).decode().strip()

if coreBranch != "SingleChannelLongPreamble":
# Try to switch branch
subprocess.check_call(["git", "checkout", "SingleChannelLongPreamble"], cwd=arduinoCorePath)

coreBranch = subprocess.check_output(["git", "branch", "--show-current"], cwd=arduinoCorePath).decode().strip()

if coreBranch != "SingleChannelLongPreamble":
print(f"ERROR: Arduino core should be 'SingleChannelLongPreamble' branch in {arduinoCorePath}")
exit(1)
1 change: 1 addition & 0 deletions src/board.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "board.h"
214 changes: 214 additions & 0 deletions src/board.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
#ifndef BOARD_H_
#define BOARD_H_

#define VER3_0_CAMERA

#ifdef VER3_0_CAMERA
#define VSWR_ADC PA3
#define PULSE_OUT PH1
#define PULSE_IN PB14
#define INPUT_AN PA5
float static input_calib[]={
2.016,
2.016,
1.5685,
1.413666667,
1.32975,
1.28,
1.245,
1.22,
1.20125,
1.186666667,
1.175,
1.165454545,
1.156666667,
1.15,
1.143571429,
1.138666667,
1.133125,
1.129411765,
1.125555556,
1.122105263,
1.1195,
1.116666667,
1.113636364,
1.11173913,
1.109583333,
1.1072,
1.105384615,
1.102962963,
1.101428571,
1.10215353,
1.100928681,
1.099782854
};


#define GPS_BCK PA8
#define CHG_DISABLE PA11
#define VSWR_EN PB5
#define GPS_EN PB6
#define A_INT2 PB2
#define A_INT1 PB7
//#define LIGHT_EN PB14 // reused for SD card
#define PIN_REED PH0
#define BAT_MON_CALIB 1.14
#endif

// lion
#ifdef VER2_4_CAMERA
#define LED_RED PA0
#define VSWR_ADC PA3
//#define BAT_MON PA4
//#define BAT_MON_EN PH1 // reused for SD
#define PULSE_OUT PH1
#define PULSE_IN PB14
#define INPUT_AN PA5
float static input_calib[]={
2.016,
2.016,
1.5685,
1.413666667,
1.32975,
1.28,
1.245,
1.22,
1.20125,
1.186666667,
1.175,
1.165454545,
1.156666667,
1.15,
1.143571429,
1.138666667,
1.133125,
1.129411765,
1.125555556,
1.122105263,
1.1195,
1.116666667,
1.113636364,
1.11173913,
1.109583333,
1.1072,
1.105384615,
1.102962963,
1.101428571,
1.10215353,
1.100928681,
1.099782854
};


#define GPS_BCK PA8
#define CHG_DISABLE PA11
#define VSWR_EN PB5
#define GPS_EN PB6
#define A_INT2 PB2
#define A_INT1 PB7
//#define LIGHT_EN PB14 // reused for SD card
#define PIN_REED PH0
#define BAT_MON_CALIB 1.14
#endif
// lion
#ifdef VER2_3_LION
#define LED_RED PA0
#define VSWR_ADC PA3
#define BAT_MON PA4
#define BAT_MON_EN PH1
#define INPUT_AN PA5
float static input_calib[]={
2.016,
2.016,
1.5685,
1.413666667,
1.32975,
1.28,
1.245,
1.22,
1.20125,
1.186666667,
1.175,
1.165454545,
1.156666667,
1.15,
1.143571429,
1.138666667,
1.133125,
1.129411765,
1.125555556,
1.122105263,
1.1195,
1.116666667,
1.113636364,
1.11173913,
1.109583333,
1.1072,
1.105384615,
1.102962963,
1.101428571,
1.10215353,
1.100928681,
1.099782854
};


#define GPS_BCK PA8
#define CHG_DISABLE PA11
#define VSWR_EN PB5
#define GPS_EN PB6
#define A_INT2 PB2
#define A_INT1 PB7
#define LIGHT_EN PB14
#define PIN_REED PH0
#define BAT_MON_CALIB 1.14
#endif

#ifdef VER2_2_4_RHINO
#define LED_RED PA0
#define VSWR_ADC PA3
#define BAT_MON PA4
#define BAT_MON_EN PH1
#define VSWR_EN PA5
#define GPS_BCK PA8
#define GPS_EN PB6
#define A_INT2 PB7
#define A_INT1 PB2
#define LIGHT_EN PB14
#define PIN_REED PH0
#define BAT_MON_CALIB 1
#endif

#ifdef VER2_2
#define PIN_REED PH0
#define GPS_EN PB14
#define LIGHT_EN PB15
#define BAT_MON_EN PB12
#define BAT_MON PA4
#define GPS_BCK PA8
#define PIN_ADC PA5
#define LED_RED PA0
#define A_INT1 PB2
#define A_INT2 PB7
#define VSWR_EN PB13
#define VSWR_ADC PA3
#define BAT_MON_CALIB 1
#endif

#ifdef VER2_1
#define PIN_REED PA11
#define GPS_EN PB14
#define LIGHT_EN PB13
#define BAT_MON_EN PB12
#define BAT_MON PA4
#define GPS_BCK PA8
#define PIN_ADC PA5
#define LED_RED PA0
#define A_INT1 PB5
#define A_INT2 PB6
#define VSWR_EN -1
#define VSWR_ADC -1
#define BAT_MON_CALIB 1
#endif

#endif
22 changes: 22 additions & 0 deletions src/command.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include "command.h"

/**
* @brief returns the port specified for the commands
*
* @return uint8_t
*/
uint8_t command_get_packet_port(void) { return command_packet_port; }

/**
* @brief receives single byte commands via LoraWAN and performs specified action
*
* @param command
*/
void command_receive(uint8_t command) {
if (command == 0xab) {
// reset received
STM32L0.reset();
} else if (command == 0xaa) {
settings_send_flag = true;
}
}
16 changes: 16 additions & 0 deletions src/command.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifndef COMMAND_H_
#define COMMAND_H_

#include <EEPROM.h>
#include <STM32L0.h>

#include "Arduino.h"
#include "lorawan.h"
#include "settings.h"

static uint8_t command_packet_port = 99;
uint8_t command_get_packet_port(void);
void command_receive(uint8_t command);
extern boolean settings_send_flag;

#endif
Loading

0 comments on commit e7d160f

Please sign in to comment.