Skip to content

Instantly share code, notes, and snippets.

@rafaribe
Last active December 13, 2021 00:33
Show Gist options
  • Save rafaribe/bc2762df7e662dda2e302681f8927b54 to your computer and use it in GitHub Desktop.
Save rafaribe/bc2762df7e662dda2e302681f8927b54 to your computer and use it in GitHub Desktop.
COTX DIY packet forwarder
alias tc="tail /home/pi/miner_data/log/console.log -f"
alias tcr="tail /home/pi/miner_data/log/crash.log -f"
alias te="tail /home/pi/miner_data/log/error.log -f"
alias pfl="tail /var/log/lora_pkt_fwd.log -f"

COTX DIY Miner

This small collection of files helps setup the COTX Miner with DIY firmware/monitoring

There's a bunch of scripts to help determine blockchain height, packet-forward configuration and even some bash aliases to help deal with logs. Followed the Helium Hotspot DIY Guide

Adjust the docker-compose.yml to fit your needs,

Disclaimer: I'm not responsible for any DIY actions on your hotspot, do at your own risk

Acknowledgment:

  • JoeCrypto @ Helium Discord
  • rbrtio @ Helium Discord
  • maco2035 @ Github
---
version: "2.1"
services:
miner:
image: quay.io/team-helium/miner:miner-arm64_2021.12.09.0
container_name: miner
environment:
- REGION_OVERRIDE=EU868
ports:
- "44158:44158/tcp"
- "1680:1680/udp"
- "4467:4467"
volumes:
- /home/pi/miner_data:/var/data
- /home/pi/miner_config/sys.config:/config/sys.config
cap_add:
- SYS_RAWIO
devices:
- /dev/i2c-1:/dev/i2c-1
networks:
- helium
ulimits:
nofile:
soft: 64000
hard: 64000
restart: unless-stopped
logging:
driver: json-file
options:
tag: "{{.ImageName}}|{{.Name}}|{{.ImageFullID}}|{{.FullID}}"
node_exporter:
image: quay.io/prometheus/node-exporter:latest
container_name: node_exporter
command:
- '--path.rootfs=/host'
volumes:
- '/:/host:ro,rslave'
network_mode: host
pid: host
restart: unless-stopped
logging:
driver: json-file
options:
tag: "{{.ImageName}}|{{.Name}}|{{.ImageFullID}}|{{.FullID}}"
promtail:
image: grafana/promtail:latest
container_name: promtail
volumes:
- /home/pi/promtail/promtail.yaml:/etc/promtail/promtail.yaml
- /home/pi/promtail/tmp:/tmp
- /home/pi/miner_data/log:/host/home/pi/miner_data/log
- /var/lib/docker/containers:/host/var/lib/docker/containers
- /var/log:/host/var/log
command: -config.file=/etc/promtail/promtail.yaml
networks:
- helium
restart: unless-stopped
logging:
driver: json-file
options:
tag: "{{.ImageName}}|{{.Name}}|{{.ImageFullID}}|{{.FullID}}"
code-server:
image: lscr.io/linuxserver/code-server
container_name: code-server
environment:
- PUID=1000
- PGID=1000
- TZ=Europe/Lisbon
- DEFAULT_WORKSPACE=/workspace #optional
volumes:
- /home/pi/:/workspace
ports:
- 8443:8443
networks:
helium:
#!/usr/bin/env bash
./height-helper.sh
snap_height=$(wget -q https://helium-snapshots.nebra.com/latest.json -O - | grep -Po '\"height\": [0-9]*' | sed 's/\"height\": //')
wget https://helium-snapshots.nebra.com/snap-$snap_height -O /home/pi/miner_data/snap/snap-latest
docker exec miner miner repair sync_pause
docker exec miner miner repair sync_cancel
docker exec miner miner snapshot load /var/data/snap/snap-latest
{
"SX130x_conf": {
"com_type": "SPI",
"com_path": "/dev/spidev0.0",
"spidev_path": "/dev/spidev0.0",
"temp_dev_path":"",
"pa_dev_path":"",
"lorawan_public": true,
"clksrc": 0,
"antenna_gain": 0, /* antenna gain, in dBi */
"full_duplex": false,
"precision_timestamp": {
"enable": false,
"max_ts_metrics": 255,
"nb_symbols": 1
},
"radio_0": {
"enable": true,
"type": "SX1250",
"freq": 867500000,
"rssi_offset": -208,
"rssi_tcomp": {"coeff_a": 0, "coeff_b": 0, "coeff_c": 20.41, "coeff_d": 2162.56, "coeff_e": 0},
"tx_enable": true,
"tx_freq_min": 863000000,
"tx_freq_max": 870000000,
"tx_gain_lut":[
{"rf_power": 12, "pa_gain": 0, "pwr_idx": 15},
{"rf_power": 13, "pa_gain": 0, "pwr_idx": 16},
{"rf_power": 14, "pa_gain": 0, "pwr_idx": 17},
{"rf_power": 15, "pa_gain": 0, "pwr_idx": 18},
{"rf_power": 16, "pa_gain": 0, "pwr_idx": 19},
{"rf_power": 17, "pa_gain": 0, "pwr_idx": 19},
{"rf_power": 18, "pa_gain": 0, "pwr_idx": 20},
{"rf_power": 19, "pa_gain": 0, "pwr_idx": 21},
{"rf_power": 20, "pa_gain": 0, "pwr_idx": 21},
{"rf_power": 21, "pa_gain": 0, "pwr_idx": 21},
{"rf_power": 22, "pa_gain": 0, "pwr_idx": 21},
{"rf_power": 23, "pa_gain": 0, "pwr_idx": 21},
{"rf_power": 24, "pa_gain": 0, "pwr_idx": 21},
{"rf_power": 25, "pa_gain": 0, "pwr_idx": 21},
{"rf_power": 26, "pa_gain": 0, "pwr_idx": 21},
{"rf_power": 27, "pa_gain": 0, "pwr_idx": 21}
]
},
"radio_1": {
"enable": true,
"type": "SX1250",
"freq": 868500000,
"rssi_offset": -208,
"rssi_tcomp": {"coeff_a": 0, "coeff_b": 0, "coeff_c": 20.41, "coeff_d": 2162.56, "coeff_e": 0},
"tx_enable": false
},
"chan_multiSF_0": {
"enable": true,
"radio": 1,
"if": -400000
},
"chan_multiSF_1": {
"enable": true,
"radio": 1,
"if": -200000
},
"chan_multiSF_2": {
"enable": true,
"radio": 1,
"if": 0
},
"chan_multiSF_3": {
"enable": true,
"radio": 0,
"if": -400000
},
"chan_multiSF_4": {
"enable": true,
"radio": 0,
"if": -200000
},
"chan_multiSF_5": {
"enable": true,
"radio": 0,
"if": 0
},
"chan_multiSF_6": {
"enable": true,
"radio": 0,
"if": 200000
},
"chan_multiSF_7": {
"enable": true,
"radio": 0,
"if": 400000
},
"chan_Lora_std": {
"enable": true,
"radio": 1,
"if": -200000,
"bandwidth": 250000,
"spread_factor": 7
},
"chan_FSK": {
/* disabled */
"enable": false,
"radio": 0,
"if": 300000,
"bandwidth": 250000,
"datarate": 100000
}
},
"gateway_conf": {
/* "gps_i2c_path": "/dev/i2c-1",*/
"gateway_ID": "YOUR_MAC_ADDR_HERE", /* example: e4522935c23b */
/* change with default server address/ports */
"server_address": "localhost",
"serv_port_up": 1680,
"serv_port_down": 1680,
/* adjust the following parameters for your network */
"keepalive_interval": 10,
"stat_interval": 30,
"push_timeout_ms": 100,
/* forward only valid packets */
"forward_crc_valid": true,
"forward_crc_error": false,
"forward_crc_disabled": false
},
"debug_conf": {
"ref_payload":[
{"id": "0xCAFE1234"},
{"id": "0xCAFE2345"}
],
"log_file": "loragw_hal.log"
}
}
#!/usr/bin/env bash
MINER_HEIGHT=$(curl -d '{"jsonrpc":"2.0","id":"id","method":"block_height","params":[]}' -s -o - http://localhost:4467/|jq .result.height)
STAKEJOY_API_URL="https://helium-api.stakejoy.com"
HELIUM_API_URL="https://api.helium.io"
BLOCKCHAIN_HEIGHT=`curl -s -A "Wget/1.12 (linux-gnu)" $STAKEJOY_API_URL/v1/blocks/height | jq '.data.height'`
NEBRA_SNAPSHOT=$(wget -q https://helium-snapshots.nebra.com/latest.json -O - | grep -Po '\"height\": [0-9]*' | sed 's/\"height\": //')
SYNC_PERCENTAGE=$(echo "scale=2; ($MINER_HEIGHT / $BLOCKCHAIN_HEIGHT)*100" | bc)
echo "Latest Snapshot: $NEBRA_SNAPSHOT"
echo "Blockchain Height: $MINER_HEIGHT/$BLOCKCHAIN_HEIGHT - $SYNC_PERCENTAGE%"
#!/bin/sh
# This script is intended to be used on SX1302 CoreCell platform, it performs
# the following actions:
# - export/unpexort GPIO23 and GPIO18 used to reset the SX1302 chip and to enable the LDOs
#
# Usage examples:
# ./reset_lgw.sh stop
# ./reset_lgw.sh start
# GPIO mapping has to be adapted with HW
#
SX1302_RESET_PIN=22
#SX1302_POWER_EN_PIN=2
WAIT_GPIO() {
sleep 0.1
}
init() {
# setup GPIOs
echo "$SX1302_RESET_PIN" > /sys/class/gpio/export; WAIT_GPIO
# echo "$SX1302_POWER_EN_PIN" > /sys/class/gpio/export; WAIT_GPIO
# set GPIOs as output
echo "out" > /sys/class/gpio/gpio$SX1302_RESET_PIN/direction; WAIT_GPIO
#echo "out" > /sys/class/gpio/gpio$SX1302_POWER_EN_PIN/direction; WAIT_GPIO
}
reset() {
echo "CoreCell reset through GPIO$SX1302_RESET_PIN..."
echo "CoreCell power enable through GPIO$SX1302_POWER_EN_PIN..."
# write output for SX1302 CoreCell power_enable and reset
# echo "1" > /sys/class/gpio/gpio$SX1302_POWER_EN_PIN/value; WAIT_GPIO
echo "1" > /sys/class/gpio/gpio$SX1302_RESET_PIN/value; WAIT_GPIO
echo "0" > /sys/class/gpio/gpio$SX1302_RESET_PIN/value; WAIT_GPIO
}
term() {
# cleanup all GPIOs
if [ -d /sys/class/gpio/gpio$SX1302_RESET_PIN ]
then
echo "$SX1302_RESET_PIN" > /sys/class/gpio/unexport; WAIT_GPIO
fi
# if [ -d /sys/class/gpio/gpio$SX1302_POWER_EN_PIN ]
# then
# echo "$SX1302_POWER_EN_PIN" > /sys/class/gpio/unexport; WAIT_GPIO
# fi
}
case "$1" in
start)
term # just in case
init
reset
;;
stop)
reset
term
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
;;
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment