RFduino to Javascript

Ask, and ye shall receive.
Ebervak
Posts: 5
Joined: 16:06, 06 Mar 2015

RFduino to Javascript

Postby Ebervak » 16:08, 06 Mar 2015

Hi everyone,

I'm using Evothings to link a RFduino with my phone, and I just want to send a numeric data via BLE. So I write rfduinoble.send(myNumber); in Arduino but I don't know what to write in javascript to get this number...
I'm a newbie, can you please help me ? :-)

Thanks you !

Fredrik
Site Admin
Posts: 196
Joined: 15:00, 18 Nov 2013

Re: RFduino to Javascript

Postby Fredrik » 16:18, 06 Mar 2015

I'm afraid you're out of luck for the moment; the rfduino library does not have a "read" or "onIncomingData" function yet.

Such a function could probably be added, but it will require some skill with Javascript and BLE.

DonPancoe
Posts: 25
Joined: 06:53, 20 Nov 2014
Location: Philadelphia, PA, USA
Contact:

Re: RFduino to Javascript

Postby DonPancoe » 18:30, 06 Mar 2015

Hmmm, I had written a response to this but must have forgoten to hit Submit...

Check out the work done by marc.graham in this thread.

In that thread I note that I had also successfully read data from the RFduino by modifying the the Arduino BLE example app (based on the RedBearLabs BLE Shield, not the RFduino), but I would check out Marc's library first.

Don

Ebervak
Posts: 5
Joined: 16:06, 06 Mar 2015

Re: RFduino to Javascript

Postby Ebervak » 21:02, 06 Mar 2015

Thank you very much DonPancoe, your work seems really interesting. I'll try this out this week-end and I'll give you a feedback !

Ebervak
Posts: 5
Joined: 16:06, 06 Mar 2015

Re: RFduino to Javascript

Postby Ebervak » 12:13, 09 Mar 2015

EDIT : I don't know why but now it works ! To improve the code, I replaced getUint16() by getFloat32() in JS and sentInt() by sentFloat() in arduino and now I have my tension with a good precision.


Hi,

So I tried to change your code and Marc's one, but something is going wrong and I can't figure out what is the problem. Here is my arduino code :

Code: Select all

#include <RFduinoBLE.h>

// le potentiomètre, branché sur la broche analogique 0
const int potar = 2;
const int led = 6;
//variable pour stocker la valeur lue après conversion
int valeurLue;
//on convertit cette valeur en une tension
int tension;

void setup()
{
    pinMode(led, OUTPUT);
    RFduinoBLE.begin();
}

void loop()
{
    //on convertit en nombre binaire la tension lue en sortie du potentiomètre
    valeurLue = analogRead(potar);
   
    //on traduit la valeur brute en tension (produit en croix)
    tension = valeurLue * 3.0 / 1024;
   
    if (tension < 2)
    {
    digitalWrite(led, LOW);
   
    }
    else
    {
    digitalWrite(led, HIGH);
    }
    RFduinoBLE.sendInt(tension);
    delay(500);
}


This one works alone. Now I want to get the value of 'tension' in my evothings app, so I changed the 'RFduino LED ON/OFF' example by adding a button :

Code: Select all

<button id="readcounter" type="button" class="green" onclick="app.readCount()">


and this script :

Code: Select all

app.readCount = function()
   {
      app.device.readCharacteristic(
         '00002221-0000-1000-8000-00805f9b34fb',
         function(data){
            app.showMessage([new DataView(data).getUint16(0, true)]);
         },
         function(errorCode)
         {
            app.showMessage("Connect error: " + errorCode);
         }
      );   
   };   


But nothing happens. Have you any idea why ?


Return to “Questions and answers”

Who is online

Users browsing this forum: No registered users and 53 guests