You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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).
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
};
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
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";
/*
*/
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));
The text was updated successfully, but these errors were encountered: