Create a gist now

Instantly share code, notes, and snippets.

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