-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest-signalk-endpoint.js
More file actions
executable file
·68 lines (57 loc) · 1.44 KB
/
test-signalk-endpoint.js
File metadata and controls
executable file
·68 lines (57 loc) · 1.44 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
#!/usr/bin/env node
/**
* Test script for the SignalK transformation endpoint
*/
const http = require('http')
const testData = {
// Test with a simple NMEA 2000 wind data message
data: {
timestamp: '2024-08-07T15:00:00.000Z',
prio: 2,
src: 42,
dst: 255,
pgn: 130306,
description: 'Wind Data',
fields: {
windSpeed: 10.5,
windAngle: 45.2,
reference: 'Apparent',
},
},
}
const postData = JSON.stringify(testData)
const options = {
hostname: 'localhost',
port: 8080,
path: '/api/transform/signalk',
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Content-Length': Buffer.byteLength(postData),
},
}
console.log('Testing SignalK transformation endpoint...')
console.log('Sending test data:', JSON.stringify(testData, null, 2))
const req = http.request(options, (res) => {
console.log(`\nResponse status: ${res.statusCode}`)
console.log(`Response headers:`, res.headers)
let data = ''
res.on('data', (chunk) => {
data += chunk
})
res.on('end', () => {
try {
const response = JSON.parse(data)
console.log('\nResponse body:')
console.log(JSON.stringify(response, null, 2))
} catch (error) {
console.log('\nRaw response body:', data)
}
})
})
req.on('error', (e) => {
console.error(`Request error: ${e.message}`)
console.log('Make sure the Visual Analyzer server is running on port 8080')
})
req.write(postData)
req.end()