Community
cancel
Showing results for 
Search instead for 
Did you mean: 
CLin82
New Contributor I
1,541 Views

How to redirect the terminal window content to a serial port? Intel Edison

Hi all,

I am doing a BLE project using Bluez and gatttool.

I can read what my BLE sensor has sent to me by using command as follows:

> rfkill unblock bluetooth

> export PATH=$PATH:~/bluez-5.24/attrib

> gatttool -b D2:AD:9F:B7:BB:60 -t random --char-write-req -a 0x000e -n 0100 --listen

The data I received is in the terminal window, now I want to export them to a serial port so that I can log it.

Anyone has any idea?

And when I try to use system() function in arduino sketch, it didn't work. For example

void setup

{

system(rfkill unblock bluetooth);

system(export PATH=$PATH:~/bluez-5.24/attrib);

system(gatttool -b D2:AD:9F:B7:BB:60 -t random --char-write-req -a 0x000e -n 0100 --listen);

}

My image version is 146.

Tags (1)
8 Replies
Diego_V_Intel
Employee
71 Views

Hi channinglin,

You have to add quotation marks in the system() method, like this:

system("command");

Regarding your original question, do you want to send the command output to the pins 0 and 1, or do you want to see the output in the Serial Monitor when running the Arduino sketch?

Regards,

Diego

CLin82
New Contributor I
71 Views

Hi DiegoV_Intel,

Yes I added the quotation in my arduino sketch. But it didn't work for me. I want to see the command output in serial monitor when running the arduino sketch.

I can definitely use the log function of Putty to save all the things in the command window (COM3 in my laptop). But I am more like to see it in the serial window (COM5) with other sensor data together.

Cheers,

Diego_V_Intel
Employee
71 Views

Hi channinglin,

To send the command output to the Serial Monitor you have to run the following line in the Arduino sketch:

system("date > /dev/ttyGS0");

The example above uses the "date" command, but you could use another command as well.

On the other hand, I was trying to install GATTTool in the image version 146 but I got an error. Did you follow a particular guide to install it?

I haven't tested it, but try adding a delay after the first line to see if there is any change:

system("rfkill unblock bluetooth");

delay(4000);

system("export PATH=$PATH:~/bluez-5.24/attrib");

system("gatttool -b D2:AD:9F:B7:BB:60 -t random --char-write-req -a 0x000e -n 0100 --listen > /dev/ttyGS0");

Regards,

Diego

CLin82
New Contributor I
71 Views

Hi DiegoV_Intel,

The system("date > /dev/ttyGS0") works for me. I got the time on my serial port.

But the system("gatttool -b D2:AD:9F:B7:BB:60 -t random --char-write-req -a 0x000e -n 0100 --listen > /dev/ttyGS0") didn't work. Nothing shows in the serial port.

 

I follow the instruction here: http://https://software.intel.com/en-us/articles/using-the-generic-attribute-profile-gatt-in-bluetoo... http://https://software.intel.com/en-us/articles/using-the-generic-attribute-profile-gatt-in-bluetoo...

to install the gatttool.

 

Cheers,

 

CLin82
New Contributor I
71 Views

Diego_V_Intel
Employee
71 Views

Hi channinglin,

I found the reason why there isn't an output when running the gatttool command in the Arduino sketch. It seems that the command "gatttool" is not recognized when it is executed from the Arduino sketch. You can check this by uploading the following sketch:

void setup() {

system("rfkill unblock bluetooth");

delay(4000);

system("export PATH=$PATH:~/bluez-5.24/attrib");

system("gatttool -b D2:AD:9F:B7:BB:60 -t random --char-write-req -a 0x000e -n 0100 --listen > /dev/ttyGS0 2>&1");

}

void loop() {

}

This is the same sketch I suggested you before, but I added a little change to see the output errors in the Serial Monitor. You should get an error when trying to run the gatttool command.

If you run the command in the Edison's console, there is no error. That happens only from the Arduino IDE so I'm afraid that you won't be able to run the command this way. The workaround I tried was to execute the command directly in the Edison's console and redirect the output to the Serial Monitor. You only have to run the same command in the Edison's console while the Serial Monitor is open. The output you would normally get in the console will appear in the Serial Monitor instead:

gatttool -b D2:AD:9F:B7:BB:60 -t random --char-write-req -a 0x000e -n 0100 --listen > /dev/ttyGS0 2>&1

I hope this works for you.

Regards,

Diego

CLin82
New Contributor I
71 Views

Hi Diego,

Thanks a lot ! It works when adding " >dev>ttyGS0 2>&1". I got the output in the serial monitor !

Now I have one more question, in my project, I used the Edison as a BLE central device that listens the advertising from my BLE PIR sensor. I first turn on my BLE PIR sensor, then input the gatttool command to build the link. What if the BLE PIR sensor is disconnected by accident? For example, I can move the PIR to 50 meters away and the link is lost, but it will then keep advertising. For the edison, I have to run the command again to build the link. I am wondering whether gatttool has re-connection ability? Or the reconnect work should given to the BLE PIR sensor.

Thanks a lot!

Diego_V_Intel
Employee
71 Views

Hi channinglin,

I'm not aware of any command to re-connect to the device in case the link is lost. However, you could try to build the link again once you have detected that the device has been disconnected. For example, when I tested the gatttool command above, I got a connection error message because I didn't have any device; I was only trying to run the command regardless of the fact that there wasn't a device to build a link. So, if you get the connection error message, you could try to build the link with the device a couple of times until the connection is reestablished.

I hope this suggestion helps you. Anyhow, I recommend you to check the gatttool documentation; you might find a better approach for this.

Regards,

Diego