Giter Site home page Giter Site logo

johnny-telegram's Introduction

Johnny Telegram

A simple way to communicate with Arduino using Johnny-Five and Telegram

Creates a Telegram Bot with the node-telegram-bot-api to send data to Arduino using Johnny-Five.

Usage

A example that allows the user to call the method 'blink' from the led

// Require the modules
var johnnyTelegram = require('../src/johnny-telegram.js');
var five = require('johnny-five');
var TelegramBot = require('node-telegram-bot-api');

// Instantiate a new board
var board = new five.Board();

// Creates a new Telegram Bot
var bot = new TelegramBot('YOUR_TELEGRAM_KEY', {polling: true});

// Initiates the Johnny Telegram instance
johnnyTelegram.init(bot);

// Listen the board 'ready' event be sure that all 
//  the hardware initialization is ok 
board.on('ready', function () {
  // Creates a led that will be available on pin 13
  var led = new five.Led(13);

  // Adds a peripheral called 'led' to Johnny Telegram
  johnnyTelegram.add('led', led);

  // This will set Johnny Telegram events like receiving a message from Telegram
  johnnyTelegram.bindEvents();
});

// And now you can send a message to the bot like 'call led blink 500'
//  and the command 'call' will call the method led's method 'blink' with 500 as parameter :)

Command list that can be sent via Telegram (quick reference)

list
call peripheral_name method_name arguments
value peripheral_name
minorthan peripheral_name limit_name value
majorthan peripheral_name limit_name value
listlimits
removelimit peripheral_name limit_name

Command list that can be sent via Telegram ("complete" reference)

The commands are case insensitive.

list

Lists all the peripherals that were added. You can't add a peripheral via Telegram.

Example:

list

# response is a list with the added peripherals like 'led, proximity, photoresistor'

call peripheral_name method_name arguments

Call a method of the peripheral Johnny Five API.

Example:

call led off
call led on
call led blink 500

# response shows which method was called from the peripheral 'led.off called with', 
#  'led.on called with' and 'led.blink called with 500'
#  in negative case is 'method does not exist'

value peripheral

Shows the current value of a peripheral.

Example:

value proximity

# response is something like '16.03' that is the value in centimeters of a proximity sensor

minorthan peripheral_name value period

Shows the peripheral name and value if it's minor than the one passed on command. The period in minutes is the interval where the value is checked.

Example:

minorthan proximity 30cm 30 1

# the response will show something like 'proximity, 30cm = 17.216'

majorthan peripheral_name limit_name value period

Shows the peripheral name, the limit name and value if it's major than the one passed on command. The period in minutes is the interval where the value is checked. "Limit Name" was added because it's possible to add more than one limit trigger for each peripheral.

Example:

majorthan proximity 50cm 50 1

# the response will show something like 'proximity, 50cm = 50.216'

listlimits

List all the limits added to all peripherals with the limit names.

listlimits

# the response will show something like 
# limits:
# proximity: 30cm, 50cm

removelimit peripheral_name limit_name

Remove a specific limit of a peripheral and so it'll checked no more.

removelimit prox 50cm

# the response will show something like 'prox, 50cm removed'

After try some IoT experiments with the awesome Johny Five, like to have a Node server running where you could send commands according the url: http://192.168.0.1/servo/angle/80 to set a servo angle, for example, I started to search a way to have a easy communication through the web.

johnny-telegram's People

Contributors

rssilva avatar

Watchers

James Cloos avatar  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.