GithubHelp home page GithubHelp logo

mysensorsmessage's Introduction

MySensorsMessage

The aim of MySensorMessage is to provide a Node.js module which is able to parse or generate messages which are used by the MySensors project. It is compatible with the serial protocol of version 1.5. It simplifies the communication with the sensors network but doesn't cover the managing the connection to the gateway. So it can be used with serial or ethernet gateways. To use this library you need Node.js version 5.0 or greater.

Deploy Node Module

This module is currently not hosted on www.npmjs.com but when you want to try it, just pull it with npm into your project.

npm install https://github.com/sbrinkmann/MySensorsMessage

Parse Message

var MySensorsMessage = require('MySensorsMessage');

//A function which is called when a MySensorsMessage is received and shall be processed
function processMySesnsorsMessage(mySensorsRawMessage) {
    var receivedMessage = new MySensorsMessage(mySensorsRawMessage);
    console.log("Sender Node ID: " + receivedMessage.nodeId); //Number
    console.log("Child Sensor ID: " + receivedMessage.childSensorId); //Number
    console.log("Message Type: " + receivedMessage.messageType.value); //ENUM which provides the attributes ".value", ".id", ".comment"
    console.log("Message Sub Type: " + receivedMessage.subType.value); //ENUM which provides the attributes ".value", ".id", ".comment"
    console.log("Is Acknowledged requested: " + receivedMessage.isAcknowledged); //boolean
    console.log("Payload of the message: " + receivedMessage.payload); //string
}

Create Message

var MySensorsMessage = require('MySensorsMessage');

function getMessageToRequestVersionFromGateway() {
    var requestVersionMessage = new MySensorsMessage();
    requestVersionMessage.nodeId = 0;
    requestVersionMessage.childSensorId = 0;
    requestVersionMessage.messageType = MySensorsMessage.MySensorsMessageTypes.INTERNAL;
    requestVersionMessage.subType = MySensorsMessage.MySensorsInternalSubTypes.I_VERSION;
    requestVersionMessage.payload = "Get version";
    return requestVersionMessage.toString();
}

function getMessageToProvideNewNodeId(newNodeId) {
    let newIdMessage = new MySensorsMessage();
	newIdMessage.nodeId = MySensorsMessage.BROADCAST_NODE_ID;
	newIdMessage.childSensorId = MySensorsMessage.CHILD_SENSOR_ID_ON_CONFIG;
	newIdMessage.messageType = MySensorsMessage.MySensorsMessageTypes.INTERNAL;
	newIdMessage.subType = MySensorsMessage.MySensorsInternalSubTypes.I_ID_RESPONSE;
	newIdMessage.payload = newNodeId;
	return newIdMessage.toString();
}

function getMessageToSetValueOnNode(nodeId, chilSensorId, value) {
    let setValueMessage = new MySensorsMessage();
    setValueMessage.nodeId = nodeId;
    setValueMessage.childSensorId = chilSensorId;
    setValueMessage.messageType = MySensorsMessage.MySensorsMessageTypes.SET;
    setValueMessage.subType = MySensorsMessage.MySensorsSetReqSubTypes.V_VAR1;
    setValueMessage.payload = value;
    return setValueMessage.toString();
}
    

mysensorsmessage's People

Watchers

 avatar

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.