soundanalogous / breakout Goto Github PK
View Code? Open in Web Editor NEWBreakout is a javascript library and toolkit for connecting Arduino and other IOBoards to the web
Home Page: www.breakoutjs.com
License: MIT License
Breakout is a javascript library and toolkit for connecting Arduino and other IOBoards to the web
Home Page: www.breakoutjs.com
License: MIT License
Hello,
First of all the auto connect option is a very good step to make the server more usable for production and i think it will be better if:
1- the server can tun as a service so no GUI unless we need to change the config.
2- we can use more than one serial<->TCP bridge so it can handle all ports either broadcasting all serial ports to one netport or one to one connection so in stead of listing serial ports in a dropdown we can have a table with all ports each in raw with the corresponding netport and connect button + auto connect check.
it will be pefect. thanks.
Some users are having issues with location.hostname. Need to resolve while maintaining support for both mobile and desktop browsers.
hi,
i have a problem with running breakout.js on Mountain Lion :-(
i tried it in a virtual machine with Windows 7 and the server runs. so my setup is correct and the examples work.
now the problems in os x:
when using the breakout server app, it displays the GUI, but when i try to change the serial port to my arduino the selection flips back to the first entry which is in my case a wireless AP of my iPhone. it's impossible to select an other serial port than the first one in the list. btw. if connected to the first serial port, after running the server the button still states "connect" and not "disconnect" as in the windows version
as the first approach didn't work i tried the node_server. again everything seems to work, i get the correct messages in the terminal, get the messages that client xyz connected or disconnected, but when actually clicking something in the hello world example or pressing the button on the arduino (which worked on windows) i get nothing. nothing happens, no error messages, nada.
i use mac os x 10.8.2, an arduino uno, uploaded advanced firmata, on the windows side everything works. I had to install JRE 7u15 in 64 bit, additionally to the default java on mountain lion to get JAVA applets running in Safari.
hopefully someone can help me.
thanks
There is a bug in version 0.1.7 that prevents negative values when using the convolution filter.
While you could write a script to "auto connect" by passing a known serial port name when launching node_server/server.js, it may be helpful to attempt to auto connect without passing a serial port name parameter.
node-serialport will report the manufacturer for some devices so highest priority match could be for /Arduino/
. Next lower priority could be match common port names used by Arduino: /usbmodemfd/
/ACM/
etc. Windows is tricky because I've only ever seen 'COMx' for any Arduino. Not sure how you'd know what name relates to an Arduino if there are ever more than one COM port listed.
I would like to share with you another option for the server. Is a modified version of the https://github.com/kalanda/serial2socket-proxy coded for Processing but focused to use with BreakoutJS. Maybe you want to use it as another alternative like the node_server in you next release. Is your choice.
Just need to download Processing (2.0 alpha5 because some problems with rxtx in 1.5.1 are resolved in this version) and install two libraries for processing: controlP5 (http://www.sojamo.de/libraries/controlP5/#installation) and websocketp5 (http://p5.twelvebytes.net/websocketP5-0.1.2/). Then, open Processing and paste the code below.
Is very similar to the Java based Breakout Server, but is very easy to distribute because Processing can export this code to applications for osx, windows32, linux32 and linux64 with one click. The exported applications run out of the box in all OS. In linux just need Java VM but don't need to install the 'rxtx-java' package.
This code use a 'html' folder inside the scketch folder as server root. You can't change the server root path, but is more easy to distribute html applications based on breakoutjs because inside the application folder you only find the executable and some folders, including the "html" with the webapp.
I hope you like ;)
/**
* Import libraries
*/
import processing.serial.*;
import controlP5.*;
import muthesius.net.*;
import org.webbitserver.*;
/**
* Event IDs
*/
final static int ID_REFRESH_BUTTON = 101;
final static int ID_SERVER_PORT_TEXTFIELD = 102;
final static int ID_CONNECT_BUTTON = 103;
final static int ID_SERIALPORTS_COMBO = 104;
/**
* Default values
*/
int DEFAULT_PORT = 8887;
int DEFAULT_SERIAL_SPEED = 57600;
/**
* Status variables
*/
boolean isSerialConnected;
boolean isServerRunning;
String serialPortName;
int serverPortNumber;
/**
* Objects
*/
Serial serialPort;
WebSocketP5 websocket;
ControlP5 gui;
DropdownList serialPortsCombo;
Button connectButton;
Button refreshButton;
Button createServerButton;
Textfield socketPortTextfield;
Textarea logTextarea;
/**
* Setup
*/
void setup() {
serialPortName = null;
isSerialConnected = false;
isServerRunning = false;
serverPortNumber = DEFAULT_PORT;
// GUI instance
gui = new ControlP5(this);
// Create GUI interface
size(320, 250);
Textlabel socketPortTextfieldLabel = gui.addTextlabel("socketPortTextfieldLabel", "Socket", 15, 20);
socketPortTextfieldLabel.setColorValue(0x444444);
Textlabel serialListLabel = gui.addTextlabel("serialListLabel", "Serial port", 60, 20);
serialListLabel.setColorValue(0x444444);
// Textfield for socket port number
socketPortTextfield = gui.addTextfield("Socket Port", 10, 30, 40, 19);
socketPortTextfield.setId(ID_SERVER_PORT_TEXTFIELD);
socketPortTextfield.setText(str(DEFAULT_PORT));
socketPortTextfield.setAutoClear(false);
socketPortTextfield.captionLabel().setVisible(false);
socketPortTextfield.valueLabel().setWithCursorPosition(socketPortTextfield.getText(), 0);
// Button for refresh serial ports list
refreshButton = gui.addButton("Refresh list", ID_REFRESH_BUTTON, 235, 30, 75, 20);
refreshButton.setId(ID_REFRESH_BUTTON);
refreshButton.captionLabel().style().paddingLeft = 6;
// Button for refresh serial ports list
createServerButton = gui.addButton("createServerButton", ID_CONNECT_BUTTON, 10, 60, 300, 20);
createServerButton.setId(ID_CONNECT_BUTTON);
createServerButton.setLabel("connect");
createServerButton.captionLabel().style().paddingLeft = 120;
// Logging area
logTextarea = gui.addTextarea("logTextarea", "", 10, 90, 290, 150);
logTextarea.setColorBackground(color(0));
logTextarea.showScrollbar();
logTextarea.scroll(1);
// Combos from here to fix z-index
serialPortsCombo = gui.addDropdownList("serialPortList", 55, 51, 170, 250);
serialPortsCombo.setId(ID_SERIALPORTS_COMBO);
serialPortsCombo.setLabel("Select");
serialPortsCombo.setBarHeight(20);
serialPortsCombo.captionLabel().style().paddingTop = 5;
serialPortsCombo.captionLabel().style().paddingLeft = 5;
serialPortsCombo.setItemHeight(20);
serialPortsCombo.setColorBackground(color(60));
serialPortsCombo.setColorActive(color(255, 128));
// Update the serial port list
updateSerialPortsCombo();
}
/**
* Redraw
*/
void draw() {
background(0xcecece);
fill(0);
rect(10, 90, 300, 150);
gui.draw();
}
/**
* On stop applet
*/
void stop() {
websocket.stop();
serialPort.clear();
serialPort.stop();
}
/**
* Catch for serial data
*/
void serialEvent(Serial serialPort) {
if (isSerialConnected) {
while (serialPort.available () > 0) {
int whatSerialSaid = serialPort.read();
websocket.sendAll(Integer.toString(whatSerialSaid));
}
}
}
/**
* Catch released keys
*/
void keyReleased() {
if (socketPortTextfield.isFocus()) {
socketPortTextfield.setText(removeNotNumbersAndCheckMaxlength(socketPortTextfield.getText(), 5));
socketPortTextfield.valueLabel().setWithCursorPosition(socketPortTextfield.getText(), 0);
}
}
/**
* When is a new websocket connection
*/
void websocketOnOpen(WebSocketConnection con) {
logActivity("A client joined of "+websocket.howManyConnections());
}
/**
* When a websocket connection closes
*/
void websocketOnClosed(WebSocketConnection con) {
logActivity("A client left");
}
/**
* Catch for websocket messages
*/
void websocketOnMessage(WebSocketConnection con, String message) {
if (message.indexOf(',') > -1) {
String data[] = message.split(",");
for (int i=0; i<data.length; i++) {
serialSend(Integer.parseInt(data[i]));
}
}
else {
serialSend(Integer.parseInt(message));
}
}
/**
* Create server
*/
void createServer(int _serverPortNumber, String _serialPortName) {
removeServer();
// Create serial connection
try {
serialPortName = _serialPortName;
serialPort = new Serial(this, serialPortName, DEFAULT_SERIAL_SPEED);
logActivity("Connected to serial port "+serialPortName);
isSerialConnected = true;
}
catch(Exception e) {
logActivity(">> ERROR: Connecting to "+serialPortName);
logActivity(">> "+e.getMessage());
e.printStackTrace();
serialPortName = null;
serialPort = null;
}
// create a new server instance
websocket = new WebSocketP5(this, serverPortNumber, "websocket");
isServerRunning = true;
logActivity("Running server at: "+websocket.getUri());
logActivity("");
}
/**
* Remove server
*/
void removeServer(){
// Remove connection if previously connected
if (serialPort != null) {
isSerialConnected = false;
logActivity("Removing connection to "+serialPortName);
logActivity("");
serialPort.clear();
serialPort.stop();
serialPort = null;
serialPortName = null;
}
// Remove any previous server
if (websocket!=null) {
websocket.stop();
websocket = null;
isServerRunning = false;
logActivity("Removing server");
logActivity("");
}
}
/**
* Send a char to serial port
*/
public int serialSend(int data) {
if (isSerialConnected) {
serialPort.write((byte)data);
return 0;
}
else {
return -1;
}
}
/**
* Update the serial port list combo with the current serial ports list
*/
void updateSerialPortsCombo() {
String[] serialPortsList = Serial.list();
serialPortsCombo.clear();
for (int i=0; i< serialPortsList.length; i++) {
if (!serialPortsList[i].startsWith("/dev/tty.") ) {
serialPortsCombo.addItem(serialPortsList[i], i+1);
}
}
}
/**
* Log activity
*/
public void logActivity(String inText) {
this.logTextarea.setText(logTextarea.text()+inText+"\n");
println(inText);
}
/**
* Clean not numbers and limit the number of chars
*/
String removeNotNumbersAndCheckMaxlength(String strToClean, int maxlength) {
String cleanedStr = "";
for (int i=0;i<strToClean.length()&&i<maxlength;i++) {
if ('0' <= strToClean.charAt(i) && strToClean.charAt(i) <= '9') {
cleanedStr = cleanedStr+strToClean.charAt(i);
}
}
return cleanedStr;
}
/**
* GUI event listener
*/
public void controlEvent(ControlEvent event) {
int idControl;
if (event.isGroup()) idControl = event.group().id();
else idControl = event.controller().id();
switch(idControl) {
case ID_REFRESH_BUTTON :
updateSerialPortsCombo();
logActivity("Serial port list is updated");
break;
case ID_CONNECT_BUTTON :
if (serialPortsCombo.value()==0) {
logActivity("> Please, select a serial port");
break;
}
int socketPort = int(socketPortTextfield.getText());
if (!(socketPort>=2 && socketPort<=65535)) {
logActivity("> Please, set a server port number between 2 and 65535");
break;
}
if(isServerRunning) {
removeServer();
createServerButton.setLabel("connect");
} else {
createServer(socketPort, serialPortsCombo.stringValue());
createServerButton.setLabel("disconnect");
}
break;
default: break;
}
}
Add a disconnected event to be fired when the websocket connection is closed.
Add the ability to remove a single filter from a Pin.
pinInstance.removeFilter(filterInstance);
path.js:313 throw new TypeError('Arguments to path.resolve must be strings');
The fadeTo method is not working properly for LED or RGBLED.
Currently you must have a 32-bit JVM installed to use Breakout in Windows. However you can have both a 32-bit and 64-bit JVM installed on your system simultaneously, you'll just need the 32-bit to run Breakout Server.
I recently update to Firefox 11 and console start showing this error:
Component returned failure code: 0x80460001 (NS_ERROR_CANNOT_CONVERT_DATA)
Breakout-core.js (línea 17) I am using the minified version.
I not sure, but I think that it don't show this error in previous version of firefox.
The schematics for the rgb led examples need to be updated to reflect the pin numbers assigned to the rgb led in the example code.
an attempt to call the motor and speed variables is made when they are not in scope
Currently you have to call the LED object's on() or off() method before calling toggle() or it will not work properly for an LED attached to a non-PWM pin.
In the toggle method, the intensity should be set rather than the value.
Moving from StandardFirmata to AdvancedFirmata so documentation needs to be updated to address this change. Keep reference to StandardFirmata for users with boards that have < 16k of flash memory.
Hi, can i use Breakout server to collect data from barcode scanner or send zpl/esc commands to thermal pos printers that uses serial ports by passing firmata?
I have a BeagleBone black and have been meaning to get it to work with Breakout. The plan is to use the Adafruit python library for the beaglebone to create a Firmata implementation. The beaglebone could then communicate with Breakout directly via a websocket interface (should be no need for Breakout Server).
This looks so awesome and I can't wait to try it out.
I made my own feeble attempt at this:
http://mainehackerclub.github.io/JohnnySocket/
Glad to see that something much more legit is out there!
I have submitted a pull request to add Tone functionality to the configurable
branch of Firmata. This enables users to access the tone()
(and eventually noTone()
) function for Arduino to play a tone (via a buzzer or other output).
Add tone()
and noTone()
methods to either IOBoard or Pin.
Need to determine min, max and average post pin filters.
I've tried on 10.8.2 and 10.6.8. Starts only on the latter. Found this in console: 14/11/12 00:07:50,260 CoreServicesUIAgent[16219]: Error SecAssessmentCreate: L’opération n’a pas pu s’achever. (OSStatus erreur -67061).
hope it helps
Hi breakout crew!
Does it possible change the Pin value in arduino.getDigitalPin(XX)' by a spinner jQuery ui function?
I try do this:
`
var ledPort = 9; //Default port is 9.
function onReady(event) {
arduino.removeEventListener(IOBoardEvent.READY, onReady);
led = new LED(arduino, arduino.getDigitalPin(ledPort));
$('#spinner').spinner({
min: 3,
max: 13,
step: 1
});
}
$( "#spinner" ).bind( "spinchange", function() {
var spinnerValue = $("#spinner").spinner("value");
ledPort = spinnerValue;
})
`
obrigado :)
I made this private for a reason at some point. Have had requests for the functionality it provides however so I'll look into making it public again.
Need to first add to StandardFirmata. Should use the Arduino Stepper library since I don't want to create any external dependencies with StandardFirmata.
Could also create BreakoutFirmata and use a more advanced Stepper library.
Need to create a tutorial on how to write your own firmware (rather than running StandardFirmata on your board) for more advanced Breakout projects. Will hopefully get to this within the next couple of weeks.
getValueFromTwo7bitBytes should really be a static method. Will keep but deprecate the existing instance method.
IOBoard.getValueFromTwo7bitBytes(lsb, msb)
re all,
I'm trying make a change in pwd_led.html example to use the same slider issue to change the interval params in blink led method.
<script type="text/javascript"> $(document).ready(function() { var IOBoard = BO.IOBoard; var IOBoardEvent = BO.IOBoardEvent; var LED = BO.io.LED; var Pin = BO.Pin; var PinEvent = BO.PinEvent; var arduino = new IOBoard(location.hostname, 8887); var led; var delays; arduino.addEventListener(IOBoardEvent.READY, onReady); function onReady(event) { arduino.removeEventListener(IOBoardEvent.READY, onReady); led = new LED(arduino, arduino.getDigitalPin(9)); arduino.setDigitalPinMode(9, Pin.DOUT); $('#btnStart').click(function() { LedStart(2000); }); $('#btnStop').on('click', LedStop); $("#sliderBlink").slider({ step: 10, min : 200, max : 2000 }); } $( "#sliderBlink" ).bind( "slideBlink", function(event, ui) { var value2 = ui.value; delays.value = value2; }); function LedStart(delays) { led.blink(delays, 0); } function LedStop(evt) { ledOsc.stopBlinking(); } }); </script>any idea?
thanks a lot for breakout, it's ool!
The configurable
branch of Firmata provides support for the onewire protocol. Add this functionality to Breakout as well along with an example application.
The high-pass filter is not working.
Use jquery-1.7.min.js for custom_examples. Currently the string example tries to import the wrong version.
Is there a simple and useful method to stabilize analog input values?
I've made a little change in Scaler example to get values from analogIn to handler blink() led but doesn't work because the values from analogIn always change and the blink doen't fired correctly.
I'm thinking too about if there are a way to solve this controlling the bind values to blink() method instead of stabilize analog input values.
Anyone can help me?
cheers from brazil
TMP36 is much simpler in that it does not require calibration and don't have to convert from degrees Kelvin.
Update schematic and example code.
Need to first add to Firmata. Two proposals for shift support in Firmata can be found here: https://github.com/firmata/protocol/blob/master/shift-proposal.md.
It is theoretically possible to use an Arduino Yun with Breakout without the need for Breakout Server. This is because the Yun is powerful enough to handle the websocket connection and all Breakout Server does is proxy the serial data from the Arduino to a websocket connection with your web application. Once I get my hands on an Arduino Yun I'll start work on this.
This issue is because of a routine that tries to refresh the list of available serial ports when Breakout Server is in the disconnected state. Need to figure out a better way to detect when a USB serial connection id connected or disconnected, or set a flag once a user clicks the drop-down to prevent the list from refreshing again until the server is disconnected.
A couple of people have reported this issue. It may be Mavericks specific. Need to look into this.
Consider prepending firmata websocket messages with 'serial:' so that if a server other than Breakout Server is used, additional data can be sent and received on the same websocket connection.
When 2 or more buttons are wired on the same port (for example on pins 2 - 7 or an Arduino Uno), pressing one button will fire a release event on all other buttons (even if there is no listener set). Seems to be an issue with the startup pin states of the Arduino not matching the expected startup pin states in the breakoutjs.
Add the ability to set an RGB LED color using a hex value or separate red, green and blue colors. Currently only the latter is supported.
Hi,
There are a way to require breakout.js in node app like jhonny-five?
I want to create an app server to handlers some breakoutjs functions like:
`
app.get('/led', function(req, res) {
});
app.get('/pot', function(req, res) {
});
`
best from brazil
It would be great if one could start the server gui-less, giving the configuration via parameters or even without any parameters, by guessing and autoconnecting the correct port.
Equations in Scaler.js are not working because they are assigned to the prototype when they should be static.
provide an on()
alias for addEventListener()
and an off()
alias for `removeEventListener()'
When creating a instance of an io component, allow users to pass "A0"
instead of boardRef.getAnalogPin(0)
and "D5"
instead of boardRef.getDigitalPin(5)
. Also passing just a number should call boardRef.getDigitalPin(num)
for that number.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.