Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to read from serial.print #151

Closed
laics1984 opened this issue Jan 7, 2016 · 14 comments
Closed

How to read from serial.print #151

laics1984 opened this issue Jan 7, 2016 · 14 comments

Comments

@laics1984
Copy link

Hi, i am working on one of the examples, redbearlab connecting to bluno board. I am able to use the read method to get serial.write, but unable to read from serial.print or serial.println. May i know which how to read from the string output via serial.print in the sketch?

@don
Copy link
Owner

don commented Jan 7, 2016

The examples use a notification to get data written from the redbear lab board on the phone. You could use read, but notification usually better since you don't need to poll, you just get the data when it arrived.

If you can get data from Serial.write you should be able to get it from Serial.print too. Maybe you need to send a \n character or call Serial.flush?

@laics1984
Copy link
Author

Nothing come out from startNotification. txCharacteristic has the same value with rxCharacteristic for bluno board rite? Neither success or failure functions are called.

@don
Copy link
Owner

don commented Jan 8, 2016

That's ok if TX and RX use the same characteristic. The bluno board will need to support notifications on that characteristic.

For startNotification, you won't receive the success callback until the bluno sends data. The success callback will be called over and over every time data arrived from the bluno.

Do you have the Bluno BLE service definition? Maybe there's another flow control characteristic or configuration that is necessary?

@laics1984
Copy link
Author

Yup, i have the service definition too.

here is the sketch from bruno board:

unsigned char data;
 void setup() {
  Serial.begin(115200);  //initial the Serial
}
void loop()
{
   if (Serial.available()){
    data = Serial.read();
    Serial.write(data);
    Serial.println();

    if (data == 'a'){
      Serial.print("Acknowledgement");
    }
    Serial.println();   //print line feed character
  }
}

It is able to output Serial.write(data); but not Serial.print("Acknowledgement"); when execute ble.write with the character 'a'

@don
Copy link
Owner

don commented Jan 8, 2016

I don't have the service definition or a bluno.

Can you create a repo with your Arduino and Cordova code? I'll try and make another device work like the bleno.

Also, are you running the latest bluno firmware? The wiki says there's a bug in old versions.

@laics1984
Copy link
Author

Hi Don, this is the repo that based on one of the examples https://github.com/laics1984/redbearlab, with the sketch. I can retieve the value using bluetooth ble utility app on ios with service uuid DFB0 and characteristic uuid DFB1.

@laics1984
Copy link
Author

Hi @don , anything wrong with my code? uuid? i hv yet to get it run.. guidance needed. Can you please help? Thanks.

@don
Copy link
Owner

don commented Jan 26, 2016

At first glance the Cordova code looks fine, since it's basically my example with the UUIDs changed. Unfortunately I can't run it since I don't have a Bluno.

Maybe you need to do something different on the Arduino side? Are you running the latest Bluno firmware?

See if you can get your example working with nRF Master Control Panel or LightBlue. If that doesn't work, talk to the Bluno people to see what they suggest. If you can get the code working with nRF Master Control Panel or LightBlue it should work with my plugin.

@don don closed this as completed Apr 15, 2016
@cnadeau
Copy link

cnadeau commented Jun 3, 2016

I have some problem getting the bluno to enable notifications on serial port and I think it's a firmware issue:

bluno serial service definition:
{
"descriptors": [
{
"uuid": "2901"
}
],
"characteristic": "dfb1",
"service": "dfb0",
"properties": [
"Read",
"WriteWithoutResponse",
"Write",
"Notify"
]
}

According to BLE standard:
https://www.bluetooth.com/specifications/adopted-specifications (core version 4.2, page 2229, table 3.10)

descriptor 2902 MUST be present in order to be able to enable/disable notifications for a service, which is not the case and leads to error:

error while starting notifications for service DFB0, characteristic DFB1: "Set notification failed for 0000dfb1-0000-1000-8000-00805f9b34fb"

@don does it make sense? I can't get any other information from the error itself

@don
Copy link
Owner

don commented Jun 5, 2016

@cnadeau sounds like a peripheral issue. If the firmware update doesn't fix, create a new github issue, ideally with a test app.

@don
Copy link
Owner

don commented Jun 6, 2016

@cnadeau It looks like Bluno is still broken with firmware 1.96. The Client Characteristic Configuration descriptor (0x2902) is missing. It's not clear where to file the Bluno issue.

@cnadeau
Copy link

cnadeau commented Jun 6, 2016

Just saw you posted the issue here, just replied and we'll see where it leads us!

http://www.dfrobot.com/forum/viewtopic.php?f=18&t=2035&p=9218#p9218

thanks a lot for your reply 👍

@AllanSCosta
Copy link

AllanSCosta commented Jul 18, 2016

Any updates on this issue? Like laics above, my code does output Serial.write(data), but can't get to Serial.print("Acknowledgement").

In brief, if I use the app to write something to the Serial and then read with the app, it basically returns what I've printed, even if the Bluno doen't have Serial.write(data) and the data being printed from the microcontroller is different.
I am still able to get data from other apps like BLE Reader though.

@don
Copy link
Owner

don commented Jul 18, 2016

@AllanSCosta this issue is closed so no updates. I'm not sure what the problem is. It's probably that the read is getting more than. 'a' so the if statement never fires. Try matching "a\n"

Can you create an example with code and instructions and post to github ornbitbucket? If it's ble-central related open a new issue here. If it's all DFrobot related, open a stackoverflow issue or DFrobot forum post and email me a link. I'll take a look.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants