Send and recieve strings to RFduino

Discuss the company and its products.
splatman
Posts: 2
Joined: 14:13, 14 Oct 2015

Send and recieve strings to RFduino

Postby splatman » 14:36, 14 Oct 2015

Hello.

I'm working on an app for communicatring with the RFDuino.
The app sends 1-character commands to the RFDuino and vice versa. This is working good.
However, I need to be able to send a character string from Evothings to the RFduino. I have tried to send numbers as an array
(with this code:

Code: Select all

app.device && app.device.writeDataArray(new Uint8Array([1],[2],[3]));

and that only gives me the first number (data[0]) on the RFduino side. data[1] and data[2] shows me nothing.

Also, the other way around, i can only read the first byte coming from the RFduino. I think this is due to the fact that I'm only reading the first byte here:

Code: Select all

 app.device.enableNotification(
                        '00002221-0000-1000-8000-00805f9b34fb',
                        function(data)
                        {
                                var dataArray = new Uint8Array(data);
                  app.rfdstatus(dataArray[0]);
       },
      
But I really don't know how to read the rest of the package. What I want to do is:

Code: Select all

 if rfdstatus(dataArray[0]) = SomeThing, then read the rest and put it in a variable.
Any help would be appreciated .

splatman
Posts: 2
Joined: 14:13, 14 Oct 2015

Re: Send and recieve strings to RFduino

Postby splatman » 16:39, 20 Oct 2015

Anyone?

tolson
Posts: 7
Joined: 03:33, 04 Mar 2015

Re: Send and recieve strings to RFduino

Postby tolson » 04:51, 18 Dec 2015

Just some snippits for sending/receiving 20 byte buffer full to/from RFduino in case others are looking for it too.

HTML part.

Code: Select all

 . . .
       <h1>RFduino evoBuffer</h1>
        <p id="info" class="lead">...</p>
        <p id="info2" class="lead">... </p>
        <p id="info3" class="lead">... </p>
        <div id="input">
                <input type="text" name="myInput" maxlength="20" size="20" id="myInput" value="Good Day!">
                <input type="button" class="red" value="Send" onclick="app.sendInput()">
        </div>
. . .



Script parts...


Example of sending a buffer full to RFduino...

Code: Select all

. . .
        app.sendInput = function()
        {
                var myVal = (document.getElementById("myInput").value);
                //console.log("myVal: " + myVal);
                var te = new TextEncoder("utf-8").encode(myVal);
                //console.log("te: " + te);
                app.device && app.device.writeDataArray(new Uint8Array(te));
        }
       
. . .

        app.showMessage = function(info)
        {
                document.getElementById("info").innerHTML = info;
        };

        app.showMessage2 = function(info2)
        {
                document.getElementById("info2").innerHTML = info2;
        }

        app.showMessage3 = function(info3)
        {
                document.getElementById("info3").innerHTML = info3;
        }
. . .


Example of receiving a variable length buffer from RFduino...

Code: Select all

. . .
                app.device.enableNotification(
                        '00002221-0000-1000-8000-00805f9b34fb',
                        function(data){
                                // for this app pass data to my handler
                                app.rfdHandler(data);
                        },
                        function(errorCode)
                        {
                                app.showMessage("Connect error: " + errorCode);
                        }
                );
. . .               


Code: Select all

. . .
        app.rfdHandler = function(rfdData)
        {
                var myDataArray = new Uint8Array(rfdData);
                // Probably should do some maximum length tests for production someday.
                var myString ="Received Length: ";   
                myString = myString + myDataArray.byteLength + " Bytes";       
                app.showMessage(myString);
       
                myString = "HEX: ";
                for(i=0;i<myDataArray.byteLength;i++){
                        myString = myString + " " + myDataArray[i].toString(16);               
                }
                app.showMessage2(myString);
                myString = "ASC: ";
                for(i=0;i<myDataArray.byteLength;i++){
                        myString = myString + " " + String.fromCharCode(myDataArray[i]);               
                }

                //myString = myString + myDataArray[0];
                app.showMessage3(myString);
        }
. . .



I hope your project is working good.
God Dag!


Return to “General discussion”

Who is online

Users browsing this forum: No registered users and 3 guests