简体   繁体   中英

Javascript/Cordova - Streaming data from NTRIP Caster to Bluetooth device

I'm writing a small app that needs to stream data from a NTRIP Caster to a Bluetooth GNSS receiver. I'm using XHR to fetch the data from the server and Cordova's bluetooth plugin to communicate with my device.

I am able to receive the data that I need, but I'm running into a problem when trying to write it to the device -- basically, nothing happens; although the data is sent succesfully, the device doesn't "do" anything with the byte array.

The data transmission works with open-source apps written in VB and Java (by Lefebure), so I can only conclude that something in the structure of the data I'm sending is different to how it was done in those applications and I'm missing it, or I have a fundamental misunderstanding of something.

Here is a JSFiddle: https://jsfiddle.net/mpwacuLb/

if (this.responseText.indexOf("ICY 200 OK") > -1) {
    var rtkData = this.response.substr(seenBytes);
    seenBytes = this.responseText.length;
    var byteData = stringToByte(rtkData);
    var bytes = new Uint8Array(byteData);
    bluetooth.write(bytes,
        (success) => {
            console.log("bt write: " + success);
        },
        (error) => {
            console.log("bt err: " + error);
        });
     }

Basically, I'm establishing a connection to the server, and upon receiving a "ICY 200 OK" message I convert it to bytes and write it to the Bluetooth com port.

Here is Lefebure's source code in VB: http://pastebin.com/Q5cZzBjF

(The entire project can be downloaded at LeFebure's site - just google "LeFebure ntrip")

The file is long , but I figured I'd leave it intact in case I missed something crucial. As far as I can tell, the relevant blocks to my questions are:

  • 1557 to 1615 (fetching data from the NTRIP server)
  • 1698 to 1716 (writing the data to the COM port)

What am I doing wrong?

Solved by setting the desired MIME type to the following:

xhr.overrideMimeType('text/plain; charset=x-user-defined');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM