Coder Social home page Coder Social logo

mqtt-serial's Introduction

mqtt-serial

A virtual node-serialport implementation that uses MQTT as the transport.

MQTTSerialPort

Use mqtt to send/receive data to a remote physical device:

var MQTTSerialPort = require('mqtt-serial').SerialPort;
var mqtt = require('mqtt');
var firmata = require('firmata');

// setup the mqtt client with port, host, and optional credentials
var client = mqtt.connect('mqtt://127.0.0.1:1883', {username: 'A USER', password: 'A PASSWORD'});

//create the mqtt serialport and specify the send and receive topics
var serialPort = new MQTTSerialPort({
  client: client,
  transmitTopic: 'REPLACE WITH YOUR TRANSMIT TOPIC',
  receiveTopic: 'REPLACE WITH YOUR RECEIVE TOPIC'
});

//use the virtual serial port to send a command to a firmata device
var board = new firmata.Board(serialPort, function (err, ok) {
  if (err){ throw err; }
  //light up a pin
  board.digitalWrite(13, 1);
});

bindPhysical

Bind a physical serial port to receive/send data from an mqtt server:

var SerialPort = require('serialport').SerialPort;
var bindPhysical = require('mqtt-serial').bindPhysical;
var skynet = require('mqtt');

// setup the mqtt client with port, host, and optional credentials
var client = mqtt.connect('mqtt://127.0.0.1:1883', {username: 'A USER', password: 'A PASSWORD'});

// setup a connection to a physical serial port
var serialPort = new SerialPort('/dev/tty.usbmodem1411',{
    baudrate: 57600,
    buffersize: 1
});

//connects the physical device to an mqtt server
bindPhysical({
  serialPort: serialPort,
  client: client,
  transmitTopic: 'REPLACE WITH YOUR TRANSMIT TOPIC',
  receiveTopic: 'REPLACE WITH YOUR RECEIVE TOPIC'
});

mqtt-serial's People

Contributors

monteslu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

mqtt-serial's Issues

ReferenceError: mqtt is not defined

hey I just copy pasted the https://github.com/monteslu/mqtt-serial#bindphysical example and changed the mqtt server, username and password and serial port path. when I start the script, I get:

osmc@rapi3:~/node$ node -i mqtt_beamer.js 
/home/osmc/node/mqtt_beamer.js:6
var client = mqtt.connect('mqtt://deisi:1883', {username: 'user', password: 'pw'});
                  ^

ReferenceError: mqtt is not defined
    at Object.<anonymous> (/home/osmc/node/mqtt_beamer.js:6:19)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.runMain (module.js:604:10)
    at run (bootstrap_node.js:389:7)
    at startup (bootstrap_node.js:149:9)
    at bootstrap_node.js:504:3

Im suuper new to node and javascript so I guess its easy issue.

Serial to mqtt

hi great share!!

i want to bind my 2 weather stations please with mqtt so, i can use them with other tools easially.

i have 2 weather stations
both have a unique ID Example:

ID: weather1 Wind_Dir:NE Wind_Speed:0.0mph, Rain:0.00in., Temp:75.07F, Humidity:49.15%, Baro_Temp:74.75F, Pressure:1014.26hPa, Soil_Temp:0.00F, Soil_Mositure:1037

ID: weather2 Wind_Dir:NE Wind_Speed:3.0mph, Rain:0.00in., Temp:70.07F, Humidity:55.2%, Baro_Temp:70F, Pressure:1011.26hPa, Soil_Temp:0.00F, Soil_Mositure:1037

is it possible to publish each please ?
any tips how ?

thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.