Created
March 13, 2015 22:49
-
-
Save monteslu/64372bcdff6f56458ec6 to your computer and use it in GitHub Desktop.
Bind a physical serial port to an MQTT server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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