Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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'});
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