javascripttcpcloudflareweathercloudflare-workers

Trouble Sending to CWOP over TCP Sockets via Cloudflare Workers


Cloudflare Workers now have the ability to connect directly over TCP sockets. I want to use this feature to send an APRS packet to CWOP.

I have the following function in my code:

export async function sendPacket(packet, server, port) {

  console.log('Opening connection to ' + server + ':' + port);

  const socket = connect({ "hostname": server, "port": port });
  const writer = socket.writable.getWriter();
  const reader = socket.readable.getReader();
  const encoder = new TextEncoder();
  
  // Wait for server's initial message - http://www.wxqa.com/faq.html
  let initialMessage = await reader.read();
  console.log('Received from server: ', new TextDecoder().decode(initialMessage.value));

  // Send login line
  const id = packet.split('>')[0];
  const loginLine = 'user ' + id + ' pass -1 vers cwop.rest 0.1\r\n';
  console.log('Sending to server: ', loginLine);
  let encoded = encoder.encode(loginLine);
  await writer.write(encoded);

  // Wait for server's acknowledgement
  let { value, done } = await reader.read();
  console.log('Received from server: ', new TextDecoder().decode(value));

  // Send packet
  console.log('Sending to server: ', packet);
  encoded = encoder.encode(packet + '\r\n');
  await writer.write(encoded);

  writer.close();
  reader.releaseLock();
  
  let serverResponse = new TextDecoder().decode(value);
  console.log('Received from server: ', serverResponse);

  console.log('Closing connection to ' + server + ':' + port);
  
  return new Response(serverResponse, { "headers": { "Content-Type": "text/plain" } });
  
}

The log shows the following:

Opening connection to rotate.aprs.net:14580
worker.js:15 Received from server:  # aprsc 2.1.5-g8af3cdc
worker.js:20 Sending to server:  user K9ZOG pass -1 vers cwop.rest 0.1
worker.js:26 Received from server:  # logresp K9ZOG unverified, server NINTH
worker.js:29 Sending to server:  K9ZOG>APRS,TCPIP\*:@181242z4246.58N/0866.22W\_119/001g001t048r000p000h64b09968L162appsscriptforwarder
worker.js:37 Received from server:  # logresp K9ZOG unverified, server NINTH
worker.js:39 Closing connection to rotate.aprs.net:14580

This has been running every five minutes for over a day now, but my data is still not showing up on findu, aprs.fi, cwopviewer.com, etc. Any ideas what might be going wrong?


Solution

  • I was sending to the verification-code-required rotate.aprs.net server without a verification code. Switching to cwop.aprs.net until I got my verification code solved my issue.