-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtest_connection.mjs
More file actions
71 lines (59 loc) · 2.26 KB
/
Copy pathtest_connection.mjs
File metadata and controls
71 lines (59 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
------------------------------------------------------------------------------
This tests the connectivity to the device using HTTP or HTTPs protocol.
For troubleshooting puroposes only.
Note: Requires nodejs installed (test running `node` command)
1. Modify the configuration below
2. Run with the command `node test_connection.mjs`
------------------------------------------------------------------------------
*/
//Configuration
let tls = false //If using TLS (true or false)
let address = "meshtastic.local" //IP address or host name
//Below is the exact connection protocol used my Meshtastic Web HTTP transport protocol
const connectionUrl = `${tls ? "https" : "http"}://${address}`;
let response = await fetch(`${connectionUrl}/api/v1/toradio`, {
method: "OPTIONS",
})
console.log(response)
/*
------------------------------------------------------------------------------
If everything is OK, you should see a response like below:
Response {
status: 204,
statusText: 'OK',
headers: Headers {
'content-type': 'application/x-protobuf',
'access-control-allow-headers': 'Content-Type',
'access-control-allow-origin': '*',
'access-control-allow-methods': 'PUT, OPTIONS',
'x-protobuf-schema': 'https://raw.githubusercontent.com/meshtastic/protobufs/master/meshtastic/mesh.proto',
connection: 'keep-alive',
'content-length': '0'
},
body: null,
bodyUsed: false,
ok: true,
redirected: false,
type: 'basic',
url: 'http://my_device_ip/api/v1/toradio'
}
------------------------------------------------------------------------------
In case of problems, you should expect something like this
EHOSTUNREACH in the example below means the device cannot be reached from the current server (DNS, firewall, NAT, etc...).
node:internal/deps/undici/undici:14130
Error.captureStackTrace(err);
^
TypeError: fetch failed
at node:internal/deps/undici/undici:14130:13
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async file:///test_connection.mjs:18:16 {
[cause]: Error: connect EHOSTUNREACH wrong.device.ip:80
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1605:16) {
errno: -113,
code: 'EHOSTUNREACH',
syscall: 'connect',
address: '192.168.1.200',
port: 80
}}
*/