The Meshtastic-Web-API can be found here:
https://github.com/bmswens/Meshtastic-Web-API
https://bmswens.github.io/Meshtastic-Web-API
The Meshtastic Web Api has to be installed on a Computer, like an Raspberry Pi.
It gets connected to the Meshtastic via Serial and allows interaction via the following commands via HTTP POST and GET.
Funktion | Endpoint | HTTP GET | HTTP POST |
---|---|---|---|
get_node_info | url/node-info | X | |
get_single_node_info | url/node-info/ | X | |
post_local_config | url/local-config | X | |
get_local_config | url/local-config | X | |
get_port | url/serial-port | X | |
post_text_message | url/messages | X | |
get_text_message | url/messages | X | |
post_canned_message | url/canned-message-module-config | X | |
get_canned_message | url/canned-message-module-config | X | |
get_positions | url/positions | X | |
get_node_position | url/positions/ | X | |
post_mattermost_message | url/mattermost | X |
be your local Endpoint. For example: http://localhost:5000/messages
We only had problems with the Docker Container.
Either it didn't start, crashed immediatly or had problems finding the Meshtastic Device.
Hence we extracted the correct files (https://github.com/bmswens/Meshtastic-Web-API/tree/dc3da7f8c2e2a72e2e39989e66c3d9e168d0438d/src). You only need the /src/ directory.
Start the API with python3 app.py
You might need to install requirements:
pip install -r requirements.txt
If you get an error, try pip install -r requirements.txt --break-system-packages
but be careful.
[!NOTE]
The Script now exposes port 5000 for the API
You could now try to send a Test message, try this script:
import requests
import json
# The URL of the Meshtastic Web API node-info endpoint
url = "http://localhost:5000/messages"
# Define the payload to be sent in the POST request
payload = {
"text": "API Test!",
"destinationId": "^all",
"wantAck": True,
"wantResponse": False,
"channelIndex": 0
}
# Set headers for the request
headers = {
"Content-Type": "application/json"
}
# Make the POST request
response = requests.post(url, data=json.dumps(payload), headers=headers)
# Check the response status code and output response data
if response.status_code == 200:
print("POST request successful.")
print("Response data:", response.json())
else:
print(f"Failed to make the POST request. Status code: {response.status_code}")
print("Error details:", response.text)