Is it possible to effectively interpret raw data from an ionic Bluetooth module?

I am currently facing an issue where I am trying to read raw data from a device using Ionic Bluetooth Serial. The device sends 506 bytes per transmission to the app and waits for a response of "OK" before sending the next 506 bytes.

However, there are instances where the app does not receive the full 506 bytes in one transmission, even though the device is confirmed to be sending all 506 bytes. It seems that the app only receives a portion of the data initially, with the remainder being sent afterwards. Additionally, each set of 506 bytes contains CRC, which sometimes fails (which is expected). But when requesting a resend of the last 506 bytes, the CRC failure occurs again, even though the device itself is functioning correctly.

My suspicion is that something may be going wrong when the data reaches the Bluetooth buffer in Ionic/Cordova.

So my questions are: Am I making a mistake in how I am reading the data? Has anyone else encountered similar issues?

Here are the steps I've already taken: - Attempted to add time delays before requesting data. - Tried asking the device to restart sending data from the beginning.

async getBTRawData(): Promise<any> {
        let result = new Array();

        const res = this.bluetoothSerial.subscribeRawData().subscribe((data) => {
            let buffer = new Uint8Array(data);

            console.log("buffer items: ", buffer);

            buffer.forEach((item) => {
                result.push(item);
            });

            // this.bluetoothSerial.clear().then(data => {
            //     console.log("Is buffer clear before reciving new messages?:", data);
            // });
        }, err => {
            console.log("err: ", err);
        });

        return result;
    }


I anticipate receiving all 506 bytes without any loss since the cellphone and the device are in close proximity. While I understand occasional CRC failures, the ability to request a resend should resolve that issue. Ideally, the 506 bytes would not break into chunks upon reception by the app.

Edit: Data format can be viewed here.

Edit2: This is how the data is being processed by the Bluetooth serial: https://i.sstatic.net/ap9TV.png

Edit3: Raw Data retrieved from subscribe: https://i.sstatic.net/YJXEA.png

Answer №1

Big thanks to @T.J Crowder for the helpful advice. Using observable was necessary to successfully retrieve data from the device since it is continuously streaming. I'm happy to report that everything is now up and running smoothly.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

After importing this variable into index.ts, how is it possible for it to possess a function named `listen`?

Running a Github repository that I stumbled upon. Regarding the line import server from './server' - how does this API recognize that the server object has a method called listen? When examining the server.ts file in the same directory, there is ...

Interacting with a Web Socket Connection While Editing Inline Content Causes Distractions. Using Angular 9 Material Table

Not exactly an error-related inquiry, but more about behaviors. In my Angular 9 setup using RxJS and Material, I have a table connected to a web socket for updates triggered by blur or change, depending on the column. This setup works well, updating the ta ...

The Angular @Input directive may be prone to receiving inaccurate model data

I am currently working on setting up @Input for my component using a model that resembles the following: interface Car { sail?: never tires: number weight: number } interface Boat { tires?: never sail: boolean weight: number } exp ...

Preventing nested prototype methods from being transferred between objects in a WebWorker

My challenge is to reserialize an object from a WebWorker while maintaining the same definitions. However, upon receiving the message, all of the prototype functions are lost. The current solution I have only works for first level prototype functions, bu ...

Developing and employing Services in Angular 2

Having some trouble with Angular2 as I explore it for the first time, specifically in creating and using a service. I've set up a data service like this: import {Injectable} from 'angular2/core'; import {recentActivity} from './app/com ...

Tips for maintaining user sessions in Passport.js and PhoneGap: "remembering" a user after logging in

My Node.js server runs on the Sails.js framework, and I've successfully integrated passport.js to handle authentication. Here's how it works: (login)POST /auth/local: Validates credentials and returns ID, Username, and Email address. (register) ...

An issue arises following an upgrade in Angular from version 9 to version 10, where the property 'propertyName' is being utilized before it has been initialized

I've spent time looking on Google, Github, and Stackoverflow for a solution to this error, but I'm still struggling to fix it. Can anyone offer a suggestion or help? Recently, I upgraded my Angular project from version 9 to version 10, and after ...

Building a custom CellRenderer in AGGrid using TypeScript within a React environment

Currently, I am utilizing React along with TypeScript and attempting to create a custom CellRenderer in AGGrid. My code is structured like this: PriorityCellRenderer.tsx import React from 'react'; function PriorityCellRenderer(props:any) { co ...

Does moment/moment-timezone have a feature that allows for the conversion of a timezone name into a more easily comprehendible format?

Consider this example project where a timezone name needs to be converted to a more readable format. For instance: input: America/Los_Angeles output: America Los Angeles While "America/Los_Angeles" may seem human-readable, the requirement is to convert ...

Unable to retrieve the updated value from the service variable

I'm attempting to implement a filter that allows me to search for items based on a service variable that is updated with user input. However, I am only able to retrieve the initial value from the service in my component. Service HTML (whatever is typ ...

Ensuring the correct type for an object's interface property value

I am currently working on defining a new interface interface SUser { ID: number; NAME: string; MAIL: string; PASSWORD: string; GENDER: number; BIRTHDATE: string; ID_FB: string; CREDIT: number; ID_REFERRAL: number; } My objective is to c ...

Utilizing Typescript to extract type information from both keys and values of an object

I have a unique challenge of mapping two sets of string values from one constant object to another. The goal is to generate two distinct types: one for keys and one for values. const KeyToVal = { MyKey1: 'myValue1', MyKey2: 'myValue ...

Is it possible for the binding model of Mat-Checkbox to be optional or null?

Greetings everyone! I am a newcomer to the world of Angular, where I have successfully created a dynamic list of checkboxes. However, I have encountered a challenge when trying to bind selected values from an API to these checkboxes. <div *ngFor="let b ...

The system is failing to recognize the union data type

My code defines various types as follows: export type Property = | BooleanProperty | NumberProperty | IntegerProperty | StringProperty | ObjectProperty | ArrayProperty; export interface OneOf { oneOf: PropertyOrKeyword[]; } export interface ...

tslint is flagging an error related to cyclomatic complexity

Within my Angular 8 project, the following dependencies are utilized: "codelyzer": "^5.1.0", "ts-node": "~8.3.0", "tslint": "~5.19.0", Upon executing: ng lint myapp --fix=true An error is raised stating: ERROR: ...html:428:106 - The cyclomatic complex ...

What is the best way to play AudioBuffer on an iPhone device?

When retrieving audio data from a stream, I encounter an issue with playing audio on iPhone Safari. The sound does not play unless I allow mediaDevice access for audio. Is there a way to play the audio without having to grant this permission? This is the ...

I am unable to refresh the table data in Angular

Here is the code that I am currently working with: I am facing an issue where my webpage is not updating its data after performing delete or any other operations. The user list is not being displayed in the data. Despite my attempts, I have been unable to ...

Exploring Dependency Injection in Angular2: A Comparison of TypeScript Syntax and @Inject Approach

I'm currently working with Angular2 build 2.0.0-alpha.34 and I can't figure out why I'm getting different results from these two code snippets. The only variation is between using @Inject(TitleService) titleService and titleService: TitleSe ...

What are some ways to incorporate advanced/nested type variables when using arrow functions?

Is there a way to use "advanced/nested" type variables, similar to how T is utilized in this function declaration, when working with arrow functions? function wrapInObject<T>(key: string) { return (x: T) => ({ [key]: x }); } I attempted to ach ...

I can't seem to understand why I am receiving an undefined property when trying to access an

While working with typescript and react within a project created using create-react-app, I encountered an issue during runtime: Cannot read property 'Customer' of undefined. This error occurred while utilizing the following module imports: impor ...