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

Program receiving Serial Data AFTER sending serial data to Bean #22

Open
kdious opened this issue Jan 15, 2016 · 3 comments
Open

Program receiving Serial Data AFTER sending serial data to Bean #22

kdious opened this issue Jan 15, 2016 · 3 comments

Comments

@kdious
Copy link

kdious commented Jan 15, 2016

So I am trying to use Node.js and the ble-bean library to send and receive serial data to the Bean. I am able to send Serial data just fine but receiving serial data AFTER writing serial data is a problem. I have written a basic Arduino sketch and Node.js program that essentially does an echo. The javascript program sends a value to the Bean and the Bean should send the same data back. Example code is below. The Arduino sketch works just fine on the bean when I use the Virtual Serial Monitor to send data to and receive data from the Bean. However, when using my Node.js program, I cannot receive data AFTER successfully sending data to the Bean. I have tried both on Mac OS X and Linix and get the same result, so I believe the issue may be with the ble-bean and/or the noble-device libraries.

Has anyone had any success reading data AFTER sending data to the Bean using the ble-bean Node.js module?

I believe that the issue may be related to the fact that the ble-bean library does not set the "\n" character as a delimiter/parser of the data from the bean, but I am not sure. With that said, when I use the PacketLogger bluetooth sniffer on Mac OS X, I do not see the notification come from the bean. However, when I use the Serial Monitor in the Arduino IDE, I do see the notification for the serial characteristic.

I have tried playing around with Node-RED and I am able to get send and receive serial data that way but I was hoping to write my own native Node.js code because I want to use some node modules that are not supported by Node-RED (and I was hoping to avoid porting them to Node-RED).

Any help would be greatly appreciated.

ble-bean library: https://github.com/jacobrosenthal/ble-bean
bean-serial library: https://github.com/monteslu/bean-serial/blob/master/index.js

Sample Code

Arduino sketch:

void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
}

void loop() {
// put your main code here, to run repeatedly:
if(Serial.available() > 0) {
int readValue = Serial.parseInt();
Serial.println(readValue);
}
}

Node.js program

/*jslint node: true */
"use strict";

/*

  • This script requests the general BLE characteristics from the bean every second.
  • Requires a sketch on the Arduino to do a Serial.print() just like you were plugged
  • in over a serial cable. Any sketch will do.
    */

var Bean = require('ble-bean');
var SerialPort = require('bean-serial').SerialPort;
var serialPort;
var options = {
logging: true, // default to false
};

var intervalId;
var connectedBean;

Bean.discover(function(bean){
connectedBean = bean;
process.on('SIGINT', exitHandler.bind(this));

@f1erro
Copy link

f1erro commented Aug 15, 2016

I am having trouble sending serial data to the bean as well

@jacobrosenthal
Copy link
Owner

I havent looked at a bean in ages. Its totally possible they changed
something.

On Mon, Aug 15, 2016 at 3:53 PM, Mitchell Fierro [email protected]
wrote:

I am having trouble sending serial data to the bean as well


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#22 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAb0dHrkfkDaQVvRRZ2WQYnLyIcJgo3kks5qgMOqgaJpZM4HFoWj
.

@f1erro
Copy link

f1erro commented Aug 17, 2016

Actually, I've gotten it to work quite well. I didn't use serial-bean like the kdious above. I'll followup with another comment explaining what went wrong with my attempt in a bit

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

3 participants