Hi All,
Sorry for asking a very newbie question...
I could successfully connect my Arduino BLE to my client app and tested out the examples.
My arduino sketch can do Serial.print to serial monitor. How can I print my output to my client app through BLE? Also, how can I refresh my output on the same line?
Thanks
how to send print from Arduino to client app thru BLE?
-
- Posts: 14
- Joined: 12:00, 15 Oct 2014
-
- Posts: 14
- Joined: 12:00, 15 Oct 2014
Re: how to send print from Arduino to client app thru BLE?
Is there any examples out that? Thanks!
Re: how to send print from Arduino to client app thru BLE?
The BLE Arduino library we use have functions ble_read() and ble_write_bytes(). See the example "arduinoble".
If you know a bit of C++, you could wrap those in a new class that inherits from Print, thus allowing you to call something like "ble.println()".
If you know a bit of C++, you could wrap those in a new class that inherits from Print, thus allowing you to call something like "ble.println()".
-
- Posts: 14
- Joined: 12:00, 15 Oct 2014
Re: how to send print from Arduino to client app thru BLE?
unfortunately, I am not familiar with java and C++... I think I can modify some codes, but I really don't know how to create a new one from scratch... I hope some experts out there can show me one or two examples how to do the javascript and how to call it in the index.html. Thanks!
-
- Posts: 14
- Joined: 12:00, 15 Oct 2014
Re: how to send print from Arduino to client app thru BLE?
I can successfully use ble_write_bytes() to pass my Arduino data. How can I pass this data to my Javascript function such that I can call this function from my index.html?
Re: how to send print from Arduino to client app thru BLE?
Hi,
It is a bit complex to pass data back from Arduino to JavaScript.
To learn more I suggest you run and explore the example "Arduino BLE":
http://evothings.com/doc/examples/arduino-ble.html
It has code for doing this. Then you can adopt the example to work with your own code.
We plan doing a high-level JavaScript library that will make this much easier.
Let me know how it goes!
Best regards, Mikael
It is a bit complex to pass data back from Arduino to JavaScript.
To learn more I suggest you run and explore the example "Arduino BLE":
http://evothings.com/doc/examples/arduino-ble.html
It has code for doing this. Then you can adopt the example to work with your own code.
We plan doing a high-level JavaScript library that will make this much easier.
Let me know how it goes!
Best regards, Mikael
-
- Posts: 14
- Joined: 12:00, 15 Oct 2014
Re: how to send print from Arduino to client app thru BLE?
Hi Mick,
In fact, I am using the the example "Arduino BLE" and trying to modify it.
JavaScript is totally new for me... I know C, but don't know anything about JavaScript and C++.
My added ble_write_bytes() is totally messed with the one for "canvas." I am trying to add one more data coming from Arduino below the canvas in the index.html.
Sorry for asking this kind of basis thing...
Can you please tell me which lines in your app.js are doing data passing from Arduino to index.html?
I have been studying for 5 days, still can't figure it out...
Thanks a lot!
In fact, I am using the the example "Arduino BLE" and trying to modify it.
JavaScript is totally new for me... I know C, but don't know anything about JavaScript and C++.
My added ble_write_bytes() is totally messed with the one for "canvas." I am trying to add one more data coming from Arduino below the canvas in the index.html.
Sorry for asking this kind of basis thing...
Can you please tell me which lines in your app.js are doing data passing from Arduino to index.html?
I have been studying for 5 days, still can't figure it out...
Thanks a lot!
Re: how to send print from Arduino to client app thru BLE?
Hi,
The actual data is sent from the Arduino code, in the arduino.ble file.
Look in the loop function, here are the lines that send data to the mobile phone:
In app.js the startReading function enables a notification that will read the data sent from the Arduino code. Here is the code that defines the function called when data is received:
The evothings.ble.enableNotification takes four parameters:
The functions passed to evothings.ble.enableNotification are not evaluated at the time of the actual call to evothings.ble.enableNotification, but later, when data is available or there is an error. Such functions are called "callback functions". Notice that in this case, the callback functions have not name, they are "anonymous functions" also known as "closures". This is a very common programming technique in JavaScript.
It takes some time to learn all this, so keep on learning and reading. The Arduino BLE is a fairly complex example, so you should not be surprised that it takes time to understand what is going on there.
Best, Mikael
The actual data is sent from the Arduino code, in the arduino.ble file.
Look in the loop function, here are the lines that send data to the mobile phone:
Code: Select all
// Read the analog input pin and send the data over BLE.
short i = analogRead(INPUT_PIN);
ble_write_bytes((byte*)&i, 2);
In app.js the startReading function enables a notification that will read the data sent from the Arduino code. Here is the code that defines the function called when data is received:
Code: Select all
// Start reading notifications.
evothings.ble.enableNotification(
deviceHandle,
app.characteristicRead,
function(data)
{
app.drawLines([new DataView(data).getUint16(0, true)]);
},
function(errorCode)
{
console.log('enableNotification error: ' + errorCode);
});
The evothings.ble.enableNotification takes four parameters:
- A device handle (this is the Arduino)
- A handle to the characteristic to enable
- A function called repeatedly as soon as new data is sent from the Arduino
- An error function called if something goes wrong
The functions passed to evothings.ble.enableNotification are not evaluated at the time of the actual call to evothings.ble.enableNotification, but later, when data is available or there is an error. Such functions are called "callback functions". Notice that in this case, the callback functions have not name, they are "anonymous functions" also known as "closures". This is a very common programming technique in JavaScript.
It takes some time to learn all this, so keep on learning and reading. The Arduino BLE is a fairly complex example, so you should not be surprised that it takes time to understand what is going on there.
Best, Mikael
Re: how to send print from Arduino to client app thru BLE?
micke wrote:Hi,
The functions passed to evothings.ble.enableNotification are not evaluated at the time of the actual call to evothings.ble.enableNotification, but later, when data is available or there is an error. Such functions are called "callback functions". Notice that in this case, the callback functions have not name, they are "anonymous functions" also known as "closures". This is a very common programming technique in JavaScript.
It takes some time to learn all this, so keep on learning and reading. The Arduino BLE is a fairly complex example, so you should not be surprised that it takes time to understand what is going on there.
Best, Mikael
Is there any way to process the data instantaneously? I mean if DataArray!="value" do something. I tried it and I modified the example but it takes 7 seconds since the value changes in Arduino Serial Monitor.
Thanks!
By the way, You did and you are doing a great job!!
Re: how to send print from Arduino to client app thru BLE?
Hi Juan, thanks for the feedback!
I wonder what causes the 7 second delay?
Is your setup similar to that of the Arduino BLE example? How is performance of the Arduino BLE example on your device? Would be interesting to see if there is a difference.
Regards, Mikael
I wonder what causes the 7 second delay?
Is your setup similar to that of the Arduino BLE example? How is performance of the Arduino BLE example on your device? Would be interesting to see if there is a difference.
Regards, Mikael
Return to “Questions and answers”
Who is online
Users browsing this forum: No registered users and 16 guests