Skip to content

Instantly share code, notes, and snippets.

@KunYi
Last active December 5, 2024 07:59
Show Gist options
  • Save KunYi/ab48d246c2e9a18c6e5b97294fd4166c to your computer and use it in GitHub Desktop.
Save KunYi/ab48d246c2e9a18c6e5b97294fd4166c to your computer and use it in GitHub Desktop.

Meshtastic CLI with BLE

scan BLE devices

list my meshtastic devices

$ meshtastic --ble-scan --nodes
INFO file:ble_interface.py scan line:116 Scanning for BLE devices (takes 10 seconds)...
Found: name='Meshtastic_2b38' address='XX:XX:XX:XX:XX:XX'
Found: name='Meshtastic_221c' address='XX:XX:XX:XX:XX:XX'
Found: name='Meshtastic_5250' address='XX:XX:XX:XX:XX:XX'
BLE scan finished

get device info and save to a file

the below command to show Meshtastic_2b38 device infomation

$ meshtastic --ble Meshtastic_2b38  --info | tee 2b38_info.txt
Connected to radio

Owner: Meshtastic 2b38 (2b38)
My info: { "myNodeNum": 1244474168, "rebootCount": 16, "minAppVersion": 30200 }
Metadata: { "firmwareVersion": "2.5.14.f2ee0df", "deviceStateVersion": 23, "canShutdown": true, "hasWifi": true, "hasBluetooth": true, "positionFlags": 811, "hwModel": "CDEBYTE_EORA_S3", "hasPKC": true, "hasEthernet": false, "role": "CLIENT", "hasRemoteHardware": false }

Nodes in mesh: {
  "!4a2d2b38": {
    "num": 1244474168,
    "user": {
      "id": "!4a2d2b38",
      "longName": "Meshtastic 2b38",
      "shortName": "2b38",
      "macaddr": "xx:xx:xx:xx:xx:xx",
      "hwModel": "CDEBYTE_EORA_S3",
      "publicKey": "3+f0MaQ9h+l7aqif4sRpCE4qs3k8W1zfb+BtMXN9V3Y="
    },
    "position": {
      "latitudeI": 249924098,
      "longitudeI": 1215444727,
      "altitude": 12,
      "time": 1733377819,
      "locationSource": "LOC_EXTERNAL",
      "latitude": 24.9924098,
      "longitude": 121.5444727
    },
    "lastHeard": 1733377819,
    "deviceMetrics": {
      "batteryLevel": 101,
      "voltage": 4.607,
      "channelUtilization": 1.0266666,
      "airUtilTx": 0.06111111,
      "uptimeSeconds": 112
    },
    "isFavorite": true
  },
  "!28bf5250": {
    "num": 683627088,
    "user": {
      "id": "!28bf5250",
      "longName": "Meshtastic 5250",
      "shortName": "5250",
      "macaddr": "XX:XX:XX:XX:XX:XX",
      "hwModel": "HELTEC_V2_0",
      "publicKey": "Qi0GUyQ7w6ZdBZEIpzOthFEBRFSnpwJH6PHueJoah2Q="
    },
    "snr": 5.75,
    "hopsAway": 0
  }
}

Preferences: {
  "device": {
    "nodeInfoBroadcastSecs": 10800,
    "role": "CLIENT",
    "serialEnabled": false,
    "buttonGpio": 0,
    "buzzerGpio": 0,
    "rebroadcastMode": "ALL",
    "doubleTapAsButtonPress": false,
    "isManaged": false,
    "disableTripleClick": false,
    "tzdef": "",
    "ledHeartbeatDisabled": false
  },
  "position": {
    "positionBroadcastSecs": 900,
    "positionBroadcastSmartEnabled": true,
    "gpsUpdateInterval": 120,
    "positionFlags": 811,
    "broadcastSmartMinimumDistance": 100,
    "broadcastSmartMinimumIntervalSecs": 30,
    "gpsMode": "NOT_PRESENT",
    "fixedPosition": false,
    "gpsEnabled": false,
    "gpsAttemptTime": 0,
    "rxGpio": 0,
    "txGpio": 0,
    "gpsEnGpio": 0
  },
  "power": {
    "waitBluetoothSecs": 60,
    "sdsSecs": 4294967295,
    "lsSecs": 300,
    "minWakeSecs": 10,
    "isPowerSaving": false,
    "onBatteryShutdownAfterSecs": 0,
    "adcMultiplierOverride": 0.0,
    "deviceBatteryInaAddress": 0,
    "powermonEnables": "0"
  },
  "network": {
    "ntpServer": "meshtastic.pool.ntp.org",
    "wifiEnabled": false,
    "wifiSsid": "",
    "wifiPsk": "",
    "ethEnabled": false,
    "addressMode": "DHCP",
    "rsyslogServer": ""
  },
  "display": {
    "screenOnSecs": 600,
    "gpsFormat": "DEC",
    "autoScreenCarouselSecs": 0,
    "compassNorthTop": false,
    "flipScreen": false,
    "units": "METRIC",
    "oled": "OLED_AUTO",
    "displaymode": "DEFAULT",
    "headingBold": false,
    "wakeOnTapOrMotion": false,
    "compassOrientation": "DEGREES_0"
  },
  "lora": {
    "usePreset": true,
    "region": "TW",
    "hopLimit": 3,
    "txEnabled": true,
    "txPower": 17,
    "channelNum": 16,
    "sx126xRxBoostedGain": true,
    "modemPreset": "LONG_FAST",
    "bandwidth": 0,
    "spreadFactor": 0,
    "codingRate": 0,
    "frequencyOffset": 0.0,
    "overrideDutyCycle": false,
    "overrideFrequency": 0.0,
    "paFanDisabled": false,
    "ignoreIncoming": [],
    "ignoreMqtt": false,
    "configOkToMqtt": false
  },
  "bluetooth": {
    "enabled": true,
    "fixedPin": 123456,
    "mode": "RANDOM_PIN"
  },
  "security": {
    "publicKey": "3+f0MaQ9h+l7aqif4sRpCE4qs3k8W1zfb+BtMXN9V3Y=",
    "privateKey": "<secure>",
    "serialEnabled": true,
    "adminKey": [],
    "isManaged": false,
    "debugLogApiEnabled": false,
    "adminChannelEnabled": false
  },
  "version": 0
}

Module preferences: {
  "mqtt": {
    "address": "mqtt.meshtastic.org",
    "username": "meshdev",
    "password": "large4cats",
    "encryptionEnabled": true,
    "root": "msh/TW",
    "enabled": false,
    "jsonEnabled": false,
    "tlsEnabled": false,
    "proxyToClientEnabled": false,
    "mapReportingEnabled": false
  },
  "serial": {
    "enabled": false,
    "echo": false,
    "rxd": 0,
    "txd": 0,
    "baud": "BAUD_DEFAULT",
    "timeout": 0,
    "mode": "DEFAULT",
    "overrideConsoleSerialPort": false
  },
  "externalNotification": {
    "enabled": false,
    "outputMs": 0,
    "output": 0,
    "outputVibra": 0,
    "outputBuzzer": 0,
    "active": false,
    "alertMessage": false,
    "alertMessageVibra": false,
    "alertMessageBuzzer": false,
    "alertBell": false,
    "alertBellVibra": false,
    "alertBellBuzzer": false,
    "usePwm": false,
    "nagTimeout": 0,
    "useI2sAsBuzzer": false
  },
  "storeForward": {
    "enabled": false,
    "heartbeat": false,
    "records": 0,
    "historyReturnMax": 0,
    "historyReturnWindow": 0,
    "isServer": false
  },
  "rangeTest": {
    "enabled": false,
    "sender": 0,
    "save": false
  },
  "telemetry": {
    "deviceUpdateInterval": 0,
    "environmentUpdateInterval": 0,
    "environmentMeasurementEnabled": false,
    "environmentScreenEnabled": false,
    "environmentDisplayFahrenheit": false,
    "airQualityEnabled": false,
    "airQualityInterval": 0,
    "powerMeasurementEnabled": false,
    "powerUpdateInterval": 0,
    "powerScreenEnabled": false,
    "healthMeasurementEnabled": false,
    "healthUpdateInterval": 0
  },
  "cannedMessage": {
    "rotary1Enabled": false,
    "inputbrokerPinA": 0,
    "inputbrokerPinB": 0,
    "inputbrokerPinPress": 0,
    "inputbrokerEventCw": "NONE",
    "inputbrokerEventCcw": "NONE",
    "inputbrokerEventPress": "NONE",
    "updown1Enabled": false,
    "enabled": false,
    "allowInputSource": "",
    "sendBell": false
  },
  "audio": {
    "codec2Enabled": false,
    "pttPin": 0,
    "bitrate": "CODEC2_DEFAULT",
    "i2sWs": 0,
    "i2sSd": 0,
    "i2sDin": 0,
    "i2sSck": 0
  },
  "remoteHardware": {
    "enabled": false,
    "allowUndefinedPinAccess": false,
    "availablePins": []
  },
  "neighborInfo": {
    "enabled": false,
    "updateInterval": 0
  },
  "ambientLighting": {
    "current": 10,
    "red": 45,
    "green": 43,
    "blue": 56,
    "ledState": false
  },
  "detectionSensor": {
    "minimumBroadcastSecs": 45,
    "detectionTriggerType": "LOGIC_HIGH",
    "enabled": false,
    "stateBroadcastSecs": 0,
    "sendBell": false,
    "name": "",
    "monitorPin": 0,
    "usePullup": false
  },
  "paxcounter": {
    "enabled": false,
    "paxcounterUpdateInterval": 0,
    "wifiThreshold": 0,
    "bleThreshold": 0
  },
  "version": 0
}

Channels:
  Index 0: PRIMARY psk=default { "psk": "AQ==", "channelNum": 0, "name": "", "id": 0, "uplinkEnabled": false, "downlinkEnabled": false }
  Index 1: SECONDARY psk=secret { "psk": "isDhHrNpJPlGX3GBJBX6kjuK7KQNp4Z0M7OTDpnX5N4=", "name": "MeshTW", "id": 1, "uplinkEnabled": true, "downlinkEnabled": true, "moduleSettings": { "positionPrecision": 16, "isClientMuted": false }, "channelNum": 0 }
  Index 2: SECONDARY psk=secret { "psk": "y1HciVgpl5Hzh05KJUe/umWUH8XhG3UjR1rvZHfUHFU=", "name": "SignalTest", "uplinkEnabled": true, "downlinkEnabled": true, "moduleSettings": { "positionPrecision": 32, "isClientMuted": false }, "channelNum": 0, "id": 0 }
  Index 3: SECONDARY psk=secret { "psk": "y2jnf86fTpf/4AFAf+mCwbzRoxpCV0P90dqJo0+w/SY=", "name": "Emergency!", "uplinkEnabled": true, "downlinkEnabled": true, "moduleSettings": { "positionPrecision": 32, "isClientMuted": false }, "channelNum": 0, "id": 0 }

Primary channel URL: https://meshtastic.org/e/#CgMSAQESDggBOAhAA0gBUBFYEGgB
Complete URL (includes all channels): https://meshtastic.org/e/#CgMSAQEKNxIgisDhHrNpJPlGX3GBJBX6kjuK7KQNp4Z0M7OTDpnX5N4aBk1lc2hUVyUBAAAAKAEwAToCCBAKNhIgy1HciVgpl5Hzh05KJUe_umWUH8XhG3UjR1rvZHfUHFUaClNpZ25hbFRlc3QoATABOgIIIAo2EiDLaOd_zp9Ol__gAUB_6YLBvNGjGkJXQ_3R2omjT7D9JhoKRW1lcmdlbmN5ISgBMAE6AgggEg4IATgIQANIAVARWBBoAQ

send text message

the below command for send a text message to use channel index: 2('SignalTest')

$ meshtastic --ble Meshtastic_2b38  --ch-index 2 --sendtext "hello from 2b38"
INFO file:ble_interface.py scan line:116 Scanning for BLE devices (takes 10 seconds)...
Connected to radio
Sending text message hello from 2b38 to ^all on channelIndex:2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment