Skip to content

Instantly share code, notes, and snippets.

@monteslu
Created March 13, 2015 22:49
  • Star 10 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save monteslu/64372bcdff6f56458ec6 to your computer and use it in GitHub Desktop.
Bind a physical serial port to an MQTT server
var SerialPort = require('serialport').SerialPort;
var bindPhysical = require('mqtt-serial').bindPhysical;
var mqtt = require('mqtt');
// might be something like COM1 on windows
var SERIAL_PORT = process.env.SERIAL_PORT || '/dev/tty.usbmodem1421';
var serialPort = new SerialPort(SERIAL_PORT,{
baudrate: 57600,
buffersize: 1
});
var client = mqtt.connect('mqtt://some_mqtt_server:1883',
{username: 'some_username', password: 'some_password'});
bindPhysical({
serialPort: serialPort,
client: client,
transmitTopic: 'some_transmit_topic',
receiveTopic: 'some_receive_topic'
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment