ooh this one was super interesting. I was able to repro from your great description. The problem was that leaving rts low was disabling the reset button on the board. So I think the only fix needed was to raise rts high before we close the port.
Meshtastic-python$ bin/run.sh --setstr wifi_ssid "asdf" --debug
rm: cannot remove 'log_*': No such file or directory
DEBUG:root:Connecting to /dev/ttyUSB0
DEBUG:root:Sending: want_config_id: 42
Trigger powerFSM 9
DEBUG:root:Received: {'myInfo': {'myNodeNum': 2883444536, 'hasGps': True, 'numChannels': 13, 'region': 'unset', 'hwModel': 'tbeam', 'firmwareVersion': 'unset', 'packetIdBits': 32, 'currentPacketId': 380285744, 'nodeNumBits': 32, 'messageTimeoutMsec': 300000, 'minAppVersion': 172}}
DEBUG:root:Received: {'radio': {'preferences': {'positionBroadcastSecs': 900, 'sendOwnerInterval': 4, 'waitBluetoothSecs': 120, 'screenOnSecs': 300, 'phoneTimeoutSecs': 900, 'phoneSdsTimeoutSec': 7200, 'meshSdsTimeoutSecs': 7200, 'sdsSecs': 31536000, 'lsSecs': 3601, 'wifiSsid': 'asdf'}, 'channelSettings': {'modemConfig': 'Bw125Cr48Sf4096', 'psk': '1PG7OiApB1nwvP+rz05pvw==', 'name': 'Default'}}}
DEBUG:root:Received: {'nodeInfo': {'num': 2883444536, 'user': {'id': '!2462abdddf38', 'longName': 'Bob b', 'shortName': 'Bb', 'macaddr': 'JGKr3d84'}, 'position': {'batteryLevel': 100, 'time': 315965514}}}
DEBUG:root:Received: {'nodeInfo': {'num': 682754228, 'user': {'id': '!246f28b200b4', 'longName': 'Bob b', 'shortName': 'Bb', 'macaddr': 'JG8osgC0'}, 'position': {'batteryLevel': 79, 'time': 316593914}, 'snr': 9.5}}
DEBUG:root:Received: {'nodeInfo': {'num': 2441803616, 'user': {'id': '!5002918af760', 'longName': 'ryan', 'shortName': 'r', 'macaddr': 'UAKRivdg'}, 'position': {'batteryLevel': 61, 'time': 316497304}, 'snr': 10.0}}
DEBUG:root:Received: {'nodeInfo': {'num': 862631397, 'user': {'id': '!c44f336ab5e5', 'longName': 'Unknown b5e5', 'shortName': '?E5', 'macaddr': 'xE8zarXl'}, 'position': {'time': 1597965319}, 'snr': 13.25}}
DEBUG:root:Received: {'nodeInfo': {'num': 2441803548, 'user': {'id': '!5002918af71c', 'longName': 'Unknown f71c', 'shortName': '?1C', 'macaddr': 'UAKRivcc'}, 'position': {'batteryLevel': 47, 'time': 316494981}, 'snr': 9.5}}
DEBUG:root:Received: {'nodeInfo': {'num': 82599254, 'user': {'id': '!fd1004ec5d56', 'longName': 'Unknown 5d56', 'shortName': '?56', 'macaddr': '/RAE7F1W'}, 'position': {}, 'snr': 9.25}}
DEBUG:root:Received: {'nodeInfo': {'num': 2885173400, 'user': {'id': '!2462abf84098', 'longName': 'Unknown 4098', 'shortName': '?98', 'macaddr': 'JGKr+ECY'}, 'position': {'batteryLevel': 4, 'time': 315966200}, 'snr': 10.75}}
DEBUG:root:Received: {'configCompleteId': 42}
Connected to radio
Setting preference wifi_ssid to asdf
Writing modified preferences to device
DEBUG:root:Sending: set_radio {
preferences {
position_broadcast_secs: 900
send_owner_interval: 4
wait_bluetooth_secs: 120
screen_on_secs: 300
phone_timeout_secs: 900
phone_sds_timeout_sec: 7200
mesh_sds_timeout_secs: 7200
sds_secs: 31536000
ls_secs: 3601
wifi_ssid: "asdf"
}
channel_settings {
modem_config: Bw125Cr48Sf4096
psk: "\324\361\273: )\007Y\360\274\377\253\317Ni\277"
name: "Default"
}
}
DEBUG:root:Closing serial stream
DEBUG:root:reader is exiting
Meshtastic-python
A python client for using Meshtastic devices. This small library (and example application) provides an easy API for sending and receiving messages over mesh radios. It also provides access to any of the operations/data available in the device user interface or the Android application. Events are delivered using a publish-subscribe model, and you can subscribe to only the message types you are interested in.
Full documentation including examples and installation instructions here.
But suffice it to say, it is really easy (note, you must use pip version 20 or later):
pip3 install --upgrade meshtastic
then run the following python3 code:
import meshtastic
interface = meshtastic.StreamInterface() # By default will try to find a meshtastic device, otherwise provide a device path like /dev/ttyUSB0
interface.sendText("hello mesh") # or sendData to send binary data, see documentations for other options.
For the rough notes/implementation plan see TODO.
Command line tool
This pip package will also install a "meshtastic" commandline executable, which displays packets sent over the network as JSON and lets you see serial debugging information from the meshtastic devices. The source code for this tool is also a good example of a 'complete' application that uses the meshtastic python API.
You can also use this tool to set any of the device parameters which are stored in persistent storage. For instance, here's how to set the device to keep the bluetooth link alive for eight hours (any usage of the bluetooth protcol from your phone will reset this timer)
meshtastic --set wait_bluetooth_secs 28800
Connected to radio...
Setting preference wait_bluetooth_secs to 28800
Writing modified preferences to device...
Or to configure an ESP32 based board to join a wifi network as a station (wifi support in the device code is coming soon):
meshtastic --set wifi_ap_mode false --setstr wifi_ssid mywifissid --setstr wifi_password mywifipsw
Or to configure an ESP32 to run as a Wifi access point:
meshtastic --set wifi_ap_mode true --setstr wifi_ssid mywifissid --setstr wifi_password mywifipsw
Required device software version
This API and tool both require that the device is running Meshtastic 0.6.0 or later.