Skip to content

Instantly share code, notes, and snippets.

@Mictronics
Last active December 8, 2025 16:26
Show Gist options
  • Select an option

  • Save Mictronics/4505868bb008e577a89f70581e24bbcc to your computer and use it in GitHub Desktop.

Select an option

Save Mictronics/4505868bb008e577a89f70581e24bbcc to your computer and use it in GitHub Desktop.
Build script for Meshtastic firmware with individual user preferences for each owned node.
#!/bin/bash
# Use modem preset for all nodes
preset="LONG_FAST"
# Define the owner names and their corresponding device types
# Format: "short_name;long_name;role;device_type,unmessageable"
# Note: The role and device_type should match the Meshtastic configuration options.
owner_names=(
"9F35;NFN-866#9 Wetter;SENSOR;pico_waveshare;true"
"2735;NFN-866#9;CLIENT_MUTE;pico_waveshare;true"
"AD25;NFN-866#9;CLIENT_MUTE;pico_waveshare;true"
"AD37;NFN-866#9;CLIENT_MUTE;pico_waveshare;true"
"3734;NFN-866#9;CLIENT_MUTE;pico2;true"
"506B;NFN-866#9;CLIENT_MUTE;pico2w;true"
"8F25;NFN-866#9 Harburg;CLIENT;rp2040-lora;true"
"9F23;NFN-866#9 Binsberg;CLIENT;rp2040-lora;true"
"7D23;NFN-866#9 Hesselberg;CLIENT;rp2040-lora;true"
"AB31;NFN-866#9;CLIENT_MUTE;rp2040-lora;true"
"9F31;NFN-866#9;CLIENT_MUTE;rp2040-lora;true"
"9631;NFN-866#9;CLIENT_MUTE;rp2040-lora;true"
"9523;NFN-866#9;CLIENT_MUTE;rp2040-lora;true"
"6C25;NFN-866#9;CLIENT_MUTE;rp2040-lora;true"
"6F31;NFN-866#9;CLIENT_MUTE;rp2040-lora;true"
"3E2A;NFN-866#9;CLIENT;rp2040-lora;true"
"E4CF;NFN-866#9;CLIENT_MUTE;t-echo;true"
"0CB7;NFN-866#9;CLIENT_MUTE;t-echo;false"
"31ED;NFN-866#9 Donauwörth;CLIENT;t-echo;true"
"6DF1;NFN-866#9 Degersheim;CLIENT;t-echo;true"
"B42C;NFN-866#9 Server;CLIENT_MUTE;heltec-v3;true"
"5130;Nokia 5130;CLIENT_MUTE;rak4631;false"
)
# userPrefs.jsonc must be created or copied from master branch before running this script
# It should contain the initial configuration with placeholders for owner names and roles.
# The script will modify this file based on the owner_names array.
# Ensure the file exists
if [ ! -f "userPrefs.jsonc" ]; then
echo "Error: userPrefs.jsonc not found. Please create or copy it from the master branch."
exit 1
fi
input_file="userPrefs.jsonc"
for entry in "${owner_names[@]}"; do
short_name=$(echo "$entry" | awk 'BEGIN { FS = ";" } ; {print $1}')
long_name=$(echo "$entry" | awk 'BEGIN { FS = ";" } ; {print $2}')
role=$(echo "$entry" | awk 'BEGIN { FS = ";" } ; {print $3}')
device_type=$(echo "$entry" | awk 'BEGIN { FS = ";" } ; {print $4}')
unmessageable=$(echo "$entry" | awk 'BEGIN { FS = ";" } ; {print $5}')
sed -i -E \
-e "s/(\"USERPREFS_CONFIG_OWNER_SHORT_NAME\":\s*\").*?(\",)/\1${short_name}\2/" \
-e "s/(\"USERPREFS_CONFIG_OWNER_LONG_NAME\":\s*\").*?(\",)/\1${long_name}\2/" \
-e "s/(\"USERPREFS_CONFIG_OWNER_UNMESSAGEABLE\":\s*\").*?(\",)/\1${unmessageable}\2/" \
-e "s/(\"USERPREFS_CONFIG_DEVICE_ROLE\":\s*\"meshtastic_Config_DeviceConfig_Role_)[A-Z_]+(\",)/\1${role}\2/" \
-e "s/(\"USERPREFS_LORACONFIG_MODEM_PRESET\":\s*\"meshtastic_Config_LoRaConfig_ModemPreset_)[A-Z_]+(\",)/\1${preset}\2/" \
"$input_file"
platformio run --environment "$device_type"
rc=$?
if [ $rc -ne 0 ]; then
echo "Error: Build for $device_type ($short_name) failed! Return code: $rc"
exit $rc
fi
mkdir -p ".builds/$device_type"
if [ "$device_type" = "heltec-v3" ]; then
cp -f ".pio/build/$device_type/firmware.bin" ".builds/${device_type}/${short_name}_firmware.bin"
else
cp -f ".pio/build/$device_type/firmware.uf2" ".builds/${device_type}/${short_name}_firmware.uf2"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment