Skip to content

Commit 8a15f16

Browse files
committed
A lot of tweaks and supports pi 5 now too
1 parent c88b4eb commit 8a15f16

File tree

5 files changed

+183
-81
lines changed

5 files changed

+183
-81
lines changed

README.md

Lines changed: 30 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -37,53 +37,43 @@ This project contains a collection of scripts designed to streamline the setup a
3737
## Setup Instructions
3838

3939
### Raspberry Pi LoRa HAT Configuration
40-
If you prefer not to use the live script, you can manually configure the LoRa HAT:
41-
1. Clone this repository:
42-
```bash
43-
git clone https://github.com/FixedBit/meshtastic_scripts.git
44-
cd meshtastic_scripts
45-
```
46-
47-
2. Run the LoRa HAT configuration script:
48-
```bash
49-
sudo ./lora_hat_setup.sh
50-
```
51-
- This script will enable SPI and I2C, configure the necessary device overlays, and ensure your Raspberry Pi is ready for the LoRaWAN/GNSS HAT.
52-
- The script will prompt for a reboot to apply changes.
40+
To configure the LoRa HAT, run the following one-liner command:
41+
```bash
42+
curl -sL https://raw.githubusercontent.com/FixedBit/meshtastic_scripts/refs/heads/main/lora_hat_setup.sh -o /tmp/lora_hat_setup.sh; sudo bash /tmp/lora_hat_setup.sh; rm /tmp/lora_hat_setup.sh
43+
```
44+
- This script will enable SPI and I2C, configure the necessary device overlays, and ensure your Raspberry Pi is ready for the LoRaWAN/GNSS HAT.
45+
- The script will prompt for a reboot to apply changes.
5346

5447
---
5548

5649
### Meshtastic Setup
57-
1. Run the Meshtastic setup script:
58-
```bash
59-
sudo ./meshtastic_setup.sh
60-
```
61-
- The script will:
62-
- Check and install required dependencies.
63-
- Set up a Python virtual environment for the Meshtastic CLI.
64-
- Install or update the `meshtasticd` service.
65-
- Back up existing Meshtastic configurations.
66-
- Start and optionally enable the Meshtasticd service.
67-
68-
2. Follow the prompts to install the latest Meshtastic CLI and configure the `meshtasticd` service.
50+
To install or update Meshtastic CLI and Meshtasticd, run the following command:
51+
```bash
52+
curl -sL https://raw.githubusercontent.com/FixedBit/meshtastic_scripts/refs/heads/main/meshtastic_setup.sh -o /tmp/meshtastic_setup.sh; sudo bash /tmp/meshtastic_setup.sh; rm /tmp/meshtastic_setup.sh
53+
```
54+
- The script will:
55+
- Check and install required dependencies.
56+
- Set up a Python virtual environment for the Meshtastic CLI.
57+
- Install or update the `meshtasticd` service.
58+
- Back up existing Meshtastic configurations.
59+
- Start and optionally enable the Meshtasticd service.
6960

7061
---
7162

7263
### NC Mesh Device Configuration
73-
1. Run the NC Mesh configuration script:
74-
```bash
75-
sudo ./ncmesh_connect.sh
76-
```
77-
- This script will:
78-
- Prompt for the device owner name and short name.
79-
- Allow selection of the device mode (Client, Router, etc.).
80-
- Configure LoRa, GPS, MQTT, and channel settings specific to the NC Mesh network.
81-
- Ensure your device is properly configured for use with NC Mesh.
64+
To configure a device for the NC Mesh network, run the following command:
65+
```bash
66+
curl -sL https://raw.githubusercontent.com/FixedBit/meshtastic_scripts/refs/heads/main/ncmesh_connect.sh -o /tmp/ncmesh_connect.sh; sudo bash /tmp/ncmesh_connect.sh; rm /tmp/ncmesh_connect.sh
67+
```
68+
- This script will:
69+
- Prompt for the device owner name and short name.
70+
- Allow selection of the device mode (Client, Router, etc.).
71+
- Configure LoRa, GPS, MQTT, and channel settings specific to the NC Mesh network.
8272

8373
---
8474

8575
## Example Configuration
86-
An example configuration file for the Waveshare LoRaWAN/GNSS HAT is available online. The live script fetches it automatically, but if needed, you can manually download and apply it:
76+
This is an example configuration file for the Waveshare LoRaWAN/GNSS HAT that I am using on my Pi.
8777

8878
1. Download the example configuration:
8979
```bash
@@ -100,6 +90,11 @@ An example configuration file for the Waveshare LoRaWAN/GNSS HAT is available on
10090
sudo systemctl restart meshtasticd
10191
```
10292

93+
NOTE: To check on what the service is doing, you can verify with this command to follow the service output:
94+
```bash
95+
journalctl -u meshtasticd -b
96+
```
97+
10398
---
10499

105100
## Credits

example_config/config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Lora:
1313
Reset: 18
1414

1515
GPS:
16+
# For Pi 5, change the path to this: /dev/ttyAMA0
1617
SerialPath: /dev/ttyS0
1718

1819
Logging:

lora_hat_setup.sh

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ if [[ ! -f "$CONFIG_FILE" ]]; then
2727
exit 1
2828
fi
2929

30+
# Detect Raspberry Pi model
31+
MODEL=$(grep -o "Raspberry Pi [0-9]" /proc/device-tree/model)
32+
echo "Detected Raspberry Pi model: $MODEL"
33+
3034
echo "Configuring SPI and I2C support on your Raspberry Pi..."
3135

3236
# Enable SPI
@@ -37,21 +41,30 @@ sudo raspi-config nonint set_config_var dtparam=spi on "${CONFIG_FILE}"
3741
echo "Enabling I2C support..."
3842
sudo raspi-config nonint set_config_var dtparam=i2c_arm on "${CONFIG_FILE}"
3943

40-
# Ensure dtoverlay=spi0-0cs is set in /boot/firmware/config.txt without altering dtoverlay=vc4-kms-v3d or dtparam=uart0
41-
echo "Configuring dtoverlay for SPI..."
42-
sudo sed -i -e '/^\s*#\?\s*dtoverlay\s*=\s*vc4-kms-v3d/! s/^\s*#\?\s*(dtoverlay|dtparam\s*=\s*uart0)\s*=.*/dtoverlay=spi0-0cs/' "${CONFIG_FILE}"
43-
44-
# Insert dtoverlay=spi0-0cs after dtparam=spi=on if not already present
45-
if ! sudo grep -q '^\s*dtoverlay=spi0-0cs' "${CONFIG_FILE}"; then
46-
sudo sed -i '/^\s*dtparam=spi=on/a dtoverlay=spi0-0cs' "${CONFIG_FILE}"
44+
# Configure for Raspberry Pi 5 specific settings
45+
if [[ "$MODEL" == "Raspberry Pi 5" ]]; then
46+
echo "Applying Raspberry Pi 5-specific configurations..."
47+
if ! sudo grep -q '^dtoverlay=spi0-0cs' "${CONFIG_FILE}"; then
48+
echo "Adding dtoverlay=spi0-0cs for SPI..."
49+
sudo sed -i '/^\s*dtparam=spi=on/a dtoverlay=spi0-0cs' "${CONFIG_FILE}"
50+
fi
51+
echo "Enabling UART for Pi 5..."
52+
sudo raspi-config nonint set_config_var enable_uart 1 "${CONFIG_FILE}"
53+
if ! sudo grep -q '^dtoverlay=uart0' "${CONFIG_FILE}"; then
54+
echo "Adding dtoverlay=uart0 for UART on Pi 5..."
55+
echo "dtoverlay=uart0" | sudo tee -a "${CONFIG_FILE}" > /dev/null
56+
fi
57+
echo "UART port for GPS on Pi 5 will be /dev/ttyAMA0."
58+
else
59+
# Default configurations for Raspberry Pi 4 and earlier
60+
echo "Applying configurations for Raspberry Pi 4 or earlier..."
61+
if ! sudo grep -q '^dtoverlay=spi0-0cs' "${CONFIG_FILE}"; then
62+
echo "Adding dtoverlay=spi0-0cs for SPI..."
63+
sudo sed -i '/^\s*dtparam=spi=on/a dtoverlay=spi0-0cs' "${CONFIG_FILE}"
64+
fi
65+
echo "UART port for GPS on Pi 4 and earlier will be /dev/ttyS0."
4766
fi
4867

49-
echo "Enable GPS if installed on your HAT."
50-
sudo raspi-config nonint do_serial_hw 0
51-
52-
echo "Disable serial console."
53-
sudo raspi-config nonint do_serial_cons 1
54-
5568
# Offer to fetch and copy the Meshtasticd configuration
5669
read -p "Would you like to fetch the Meshtasticd configuration for the Waveshare LoRa HAT? (yes/no) [Default: yes]: " config_choice
5770
config_choice=${config_choice:-yes}
@@ -73,6 +86,17 @@ if [[ "$config_choice" == "yes" ]]; then
7386

7487
if [[ $? -eq 0 ]]; then
7588
echo "Configuration fetched and saved successfully to ${TARGET_CONFIG_FILE}."
89+
90+
# Modify the config for Raspberry Pi 5 if detected
91+
if [[ "$MODEL" == "Raspberry Pi 5" ]]; then
92+
echo "Updating config.yaml for Raspberry Pi 5..."
93+
sudo sed -i 's|SerialPath: /dev/ttyS0|SerialPath: /dev/ttyAMA0|' "${TARGET_CONFIG_FILE}"
94+
if [[ $? -eq 0 ]]; then
95+
echo "Config.yaml updated for Raspberry Pi 5 successfully."
96+
else
97+
echo "Failed to update config.yaml for Raspberry Pi 5."
98+
fi
99+
fi
76100
else
77101
echo "Failed to fetch the configuration. Please check your internet connection and try again."
78102
fi

meshtastic_setup.sh

Lines changed: 66 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,51 @@ get_release_url() {
105105
jq -r ".assets[] | select(.name | contains(\"${platform}.deb\")) | .browser_download_url"
106106
}
107107

108-
# Function to create Python virtual environment and install the meshtastic CLI
108+
# Function to locate and verify the Meshtastic CLI
109+
check_meshtastic_cli() {
110+
# Attempt to find meshtastic in the PATH or common installation paths
111+
MESHTASTIC_CMD=$(command -v meshtastic)
112+
113+
# Check common paths if not found in PATH
114+
if [[ -z "$MESHTASTIC_CMD" ]]; then
115+
local paths=(
116+
"/opt/meshtastic-venv/bin/meshtastic"
117+
"/usr/local/bin/meshtastic"
118+
"/usr/bin/meshtastic"
119+
"$HOME/.local/bin/meshtastic"
120+
)
121+
for path in "${paths[@]}"; do
122+
if [[ -x "$path" ]]; then
123+
MESHTASTIC_CMD="$path"
124+
break
125+
fi
126+
done
127+
fi
128+
129+
# If still not found, prompt to install
130+
if [[ -z "$MESHTASTIC_CMD" ]]; then
131+
echo "Meshtastic CLI is not installed or not in the expected paths."
132+
read -p "Do you want to install it? (yes/no): [Default: yes] " choice
133+
choice=${choice:-yes}
134+
if [[ "$choice" == "yes" ]]; then
135+
install_meshtastic_cli
136+
else
137+
echo "Meshtastic CLI installation skipped. Exiting."
138+
exit 1
139+
fi
140+
fi
141+
142+
# Verify the Meshtastic CLI works
143+
if ! "$MESHTASTIC_CMD" --help >/dev/null 2>&1; then
144+
echo "Error: Meshtastic CLI is installed but not functioning correctly."
145+
echo "Please check your installation or reinstall the Meshtastic CLI."
146+
exit 1
147+
fi
148+
149+
echo "Meshtastic CLI is installed and functioning correctly: $MESHTASTIC_CMD"
150+
}
151+
152+
# Function to install Meshtastic CLI
109153
install_meshtastic_cli() {
110154
local venv_path="/opt/meshtastic-venv"
111155

@@ -114,23 +158,31 @@ install_meshtastic_cli() {
114158
sudo python3 -m venv "$venv_path"
115159
fi
116160

117-
echo "Installing meshtastic Python library in virtual environment..."
161+
echo "Installing Meshtastic Python library in virtual environment..."
118162
sudo "$venv_path/bin/pip" install meshtastic
119163

120-
echo "Adding meshtastic command to global PATH..."
164+
echo "Adding Meshtastic command to global PATH if not already present..."
121165
local profile_script="/etc/profile.d/meshtastic.sh"
122-
sudo bash -c "cat > $profile_script" <<EOL
123-
export PATH="$venv_path/bin:\$PATH"
124-
EOL
125-
sudo chmod 0755 "$profile_script"
126-
127-
if [[ -n "$BASH_SOURCE" ]]; then
128-
echo "source $profile_script" >> "$HOME/.bashrc"
129-
source "$profile_script"
130-
elif [[ -n "$ZSH_NAME" ]]; then
131-
echo "source $profile_script" >> "$HOME/.zshrc"
166+
local export_line="export PATH=\"$venv_path/bin:\$PATH\""
167+
168+
if ! grep -qF "$export_line" "$profile_script" 2>/dev/null; then
169+
sudo bash -c "echo '$export_line' > $profile_script"
170+
sudo chmod 0755 "$profile_script"
171+
echo "Added Meshtastic to global PATH via $profile_script."
172+
else
173+
echo "Global PATH already includes Meshtastic command."
132174
fi
133175

176+
# Add to user's shell configuration files
177+
for shell_rc in "$HOME/.bashrc" "$HOME/.zshrc"; do
178+
if [[ -f "$shell_rc" ]] && ! grep -qF "$export_line" "$shell_rc"; then
179+
echo "$export_line" >> "$shell_rc"
180+
echo "Added Meshtastic to PATH in $shell_rc."
181+
fi
182+
done
183+
184+
# Source the changes for the current session
185+
export PATH="$venv_path/bin:$PATH"
134186
echo "Meshtastic CLI installation completed successfully."
135187
}
136188

@@ -247,18 +299,7 @@ echo "-= Meshtastic Setup and Install Script =-"
247299
# Main script logic
248300
check_and_install_packages
249301

250-
# Check and offer to install meshtastic CLI
251-
if check_command "meshtastic"; then
252-
echo "Meshtastic CLI is already installed."
253-
else
254-
echo "Meshtastic CLI is not installed."
255-
read -p "Do you want to install it? (yes/no): [Default: yes]" choice
256-
if [[ "$choice" == "no" ]]; then
257-
echo "Meshtastic CLI installation skipped."
258-
else
259-
install_meshtastic_cli
260-
fi
261-
fi
302+
check_meshtastic_cli
262303

263304
# Always ask to install or update meshtasticd
264305
install_or_update_meshtasticd

ncmesh_connect.sh

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,48 @@ echo "-= Shoutout to the North Carolina Meshtastic Community!
88
echo "-= Website https://ncmesh.net | Discord: https://discord.gg/xUzRAjHZk8 =-"
99
echo "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-"
1010

11+
12+
# Function to locate and verify the Meshtastic CLI
13+
find_and_verify_meshtastic() {
14+
# Attempt to find meshtastic in the PATH
15+
MESHTASTIC_CMD=$(command -v meshtastic)
16+
17+
# Check common installation paths if not found in PATH
18+
if [[ -z "$MESHTASTIC_CMD" ]]; then
19+
local paths=(
20+
"/opt/meshtastic-venv/bin/meshtastic"
21+
"/usr/local/bin/meshtastic"
22+
"/usr/bin/meshtastic"
23+
"$HOME/.local/bin/meshtastic"
24+
)
25+
for path in "${paths[@]}"; do
26+
if [[ -x "$path" ]]; then
27+
MESHTASTIC_CMD="$path"
28+
break
29+
fi
30+
done
31+
fi
32+
33+
# Exit if Meshtastic CLI is still not found
34+
if [[ -z "$MESHTASTIC_CMD" ]]; then
35+
echo "Error: Meshtastic CLI not found."
36+
echo "Ensure it is installed and its path is added to your environment."
37+
exit 1
38+
fi
39+
40+
# Verify the Meshtastic CLI works
41+
if ! "$MESHTASTIC_CMD" --help >/dev/null 2>&1; then
42+
echo "Error: Meshtastic CLI is installed but not working properly."
43+
echo "Please check your installation or reinstall the Meshtastic CLI."
44+
exit 1
45+
fi
46+
47+
echo "Meshtastic CLI located and verified: $MESHTASTIC_CMD"
48+
}
49+
50+
# Locate and verify Meshtastic CLI
51+
find_and_verify_meshtastic
52+
1153
# Function to execute and check commands
1254
run_command() {
1355
echo "Executing: $1"
@@ -50,28 +92,27 @@ esac
5092

5193
# Configure device owner, short name, and role
5294
echo "Configuring device owner, short name, and role..."
53-
run_command "meshtastic --host localhost --set-owner '$owner_name' --set-owner-short '$short_name' --set device.role $device_role"
95+
run_command "${MESHTASTIC_CMD} --host localhost --set-owner '$owner_name' --set-owner-short '$short_name' --set device.role $device_role"
5496

5597
# Configure LoRa settings
5698
echo "Configuring LoRa settings..."
57-
run_command "meshtastic --host localhost --set lora.region US --set lora.tx_power 30 --set lora.hop_limit 4"
99+
run_command "${MESHTASTIC_CMD} --host localhost --set lora.region US --set lora.tx_power 30 --set lora.hop_limit 4"
58100

59101
# Configure position settings
60102
echo "Configuring position settings..."
61-
run_command "meshtastic --host localhost --set position.gps_mode ENABLED --set position.gps_update_interval 1800 --set position.position_broadcast_secs 3600 --set position.broadcast_smart_minimum_interval_secs 1800 --set position.broadcast_smart_minimum_distance 100"
103+
run_command "${MESHTASTIC_CMD} --host localhost --set position.gps_mode ENABLED --set position.gps_update_interval 1800 --set position.position_broadcast_secs 3600 --set position.broadcast_smart_minimum_interval_secs 1800 --set position.broadcast_smart_minimum_distance 100"
62104

63105
# Configure MQTT settings
64106
echo "Configuring MQTT settings..."
65-
run_command "meshtastic --host localhost --set mqtt.enabled true --set mqtt.address mqtt.ncmesh.net --set mqtt.username meshdev --set mqtt.password large4cats --set mqtt.proxy_to_client_enabled true --set mqtt.map_reporting_enabled true"
107+
run_command "${MESHTASTIC_CMD} --host localhost --set mqtt.enabled true --set mqtt.address mqtt.ncmesh.net --set mqtt.username meshdev --set mqtt.password large4cats --set mqtt.proxy_to_client_enabled true --set mqtt.map_reporting_enabled true"
66108

67109
# Configure primary channel
68110
echo "Configuring primary channel (LongFast)..."
69-
run_command "meshtastic --host localhost --ch-set name 'LongFast' --ch-index 0 --ch-set uplink_enabled true --ch-set downlink_enabled true --ch-set module_settings.position_precision 1 --ch-index 0"
111+
run_command "${MESHTASTIC_CMD} --host localhost --ch-set name 'LongFast' --ch-index 0 --ch-set uplink_enabled true --ch-set downlink_enabled true --ch-set module_settings.position_precision 14 --ch-index 0"
70112

71113
# Add and configure secondary channel
72114
echo "Adding and configuring secondary channel (NCMesh)..."
73-
run_command "meshtastic --host localhost --ch-add 1"
74-
run_command "meshtastic --host localhost --ch-set name 'NCMesh' --ch-index 1 --ch-set uplink_enabled true --ch-set downlink_enabled true --ch-set module_settings.position_precision 1 --ch-index 1 --ch-set psk 'default' --ch-index 1"
75-
115+
run_command "${MESHTASTIC_CMD} --host localhost --ch-add 1"
116+
run_command "${MESHTASTIC_CMD} --host localhost --ch-set name 'NCMesh' --ch-index 1 --ch-set uplink_enabled true --ch-set downlink_enabled true --ch-set module_settings.position_precision 14 --ch-index 1 --ch-set psk 'default' --ch-index 1"
76117
# Final Confirmation
77118
echo "Meshtastic device setup completed successfully!"

0 commit comments

Comments
 (0)