Simulated flight data from two drones

const WebSocketServer = require('ws').Server const wss = new WebSocketServer({ port: Service port 8181 wss.on('connection', ws => {console.log(' server: ') ws.on('message', message => {console.log(message)})}) let data1 = {type: 4, payload: { displacement: 0, droneBattery: {charge: 64, current: -1542, temperature: 0, voltage: 15600}, droneId: 2, droneName: "Wizard 4P V2", pilotId: 2, FC: {attitude: {pitch: 0, roll: 0, yaw: 0}, velocity: 0}, GPS: {latitude: 24.434655268, longitude: 118.1150297251551, height: 1}, rc: {signal: 5, charge: 38, GPS: {longitude latitude: 24.434656:118.115023, height: 10}}}} let data2 = {type: 4, content: {below: 379, droneBattery: {charge: 64, current: -1542, temperature: 0, voltage: 15600}, droneId: 3, droneName: PilotId: 3, FC: {attitude: {pitch: 0, roll: 0, yaw: 0}, velocity: 0}, GPS: {latitude: 24.434985268, longitude: 118.1150497251551, height: 1}, rc: {signal: 5, charge: 38, GPS: {longitude latitude: 24.430618:118.115174, height: 10}}}} let data3 = {type: 4, content: {below: 379, droneBattery: {charge: 64, current: -1542, temperature: 0, voltage: 15600}, droneId: 4, droneName: PilotId: 4, FC: {attitude: {pitch: 0, roll: 0, yaw: 0}, velocity: 0}, GPS: {latitude: 24.434985268, longitude: 118.1150497251551, height: 1}, rc: {signal: 5, charge: 38, GPS: {longitude latitude: 24.43498413:118.1150443, height: 10}}}} WSS) on (' connection ', Ws = > {let sendClientData = ws = > {data1. Content. GPS. Latitude + = 0.00004 data1. Content. The GPS. The longitude + = 0.00004 data1.payload.gps.height += 1 data1.payload.rc.signal += 1 data1.payload.displacement += 1 Data1. Content. DroneBattery. Charge + = 1 / / data3. Content. GPS. Latitude - = 0.00005 ws. Send (JSON. Stringify (data1)) / / Ws. Send (JSON. Stringify (data3))} let sendClientData1 = ws = > {data2. Content. GPS. Longitude + = 0.00003 Data2. Content. Rc. GPS. Longitude + = 0.000008 data2. Content. Rc. GPS. Latitude + = 0.000008 ws. Send (JSON. Stringify (data2)} let timer = setInterval(() => { sendClientData(ws) }, 3000) let timer1 = setInterval(() => { sendClientData1(ws) }, 3000) let data4 = {type: 10, payload: {id: 2, name: }}//3 let closeData = ws => {ws.send(json.stringify (data4))} setTimeout(() => {closeData(ws) clearInterval(timer) }, 30000) })Copy the code
const ws = new WebSocket('ws://localhost:8181')
ws.onmessage = e => {
  this.localOnMessage(JSON.parse(e.data))
}

localOnMessage (data) {
  console.log(data)
}   
Copy the code