Upgrade to Pro — share decks privately, control downloads, hide ads and more …

OpenExpo16 slides

Sponsored · Ship Features Fearlessly Turn features on and off without deploys. Used by thousands of Ruby developers. →
Fran
June 02, 2016

OpenExpo16 slides

Fran

June 02, 2016

Transcript

61 slides
  1. Community build share use Ask us for invite you to

    our slack community team! Forum: forum.netbeast.co
  2. Javascript • Goal: to create interactive sites. • Shares many

    of the features of Java. • Interact with HTML and spice up websites with dynamic content.
  3. Node.js Server side platform built on Google Chrome’s JavaScript Engine

    Node.js = Runtime Environment + JavaScript Library 1) Asynchronous 2) event driven 2) Single threaded but highly scalable
  4. Hello Beasts! It's an event loop which is triggered by

    a request. You can try by typing node hello-world.js Then, you can access to http://localhost:8080
  5. Modules A module is a set of functions and resources

    that is wrapped. We use npm to install locally a module that we want to use in our project. npm install MODULE_WANTED You can see the -g option for global packages when you need a global utility.
  6. NPM Node Package Manager: install Node programs and manage/install dependencies.

    >npm install --global netbeast-cli #installing >npm install [email protected] #an specific version >npm info netbeast >npm ls #list installed packages
  7. Callback It's the function executed when an event is triggered.

    For example when a task is completed. In Hello World example we've seen a callback triggered by a request.
  8. Events (I) It's also known that Node.js is event oriented.

    It's easier to see the request event in the following example (take into account that it's a simple modification of the previous example)
  9. Exercise I Let’s have a look on a live example

    that shows events concept This is an exercise where you’ll use a template in order to make it work. You can find the template here: workshop/Nodejs-Fundamentals/exercise_1.js It has some instructions and tips at the end. You’ll need to have a look over: https://nodejs.org/docs/latest-v5.x/api/http.html#http_event_connection https://nodejs.org/docs/latest-v5.x/api/net.html#net_socket_remoteaddress
  10. Express.js It’s a web framework for Node.js • Great for

    building Web APIs • Nice projects built on Express.js (Ghost, MySpace, …)
  11. Exercise! Write a simple Express.js app that listen 8000 port

    and sends: • This is path1! If you access localhost:8000/path1 • This is path2! If you access localhost:8000/path2 • 403 status if you access any other location More tips on the template: workshop/Nodejs-Fundamentals/exercise_1.js http://expressjs.com/es/api.html#res.sendStatus
  12. Get on with it! We are going to have a

    look over an example app and launch it to the space!
  13. App template (I) Let’s build an app template To do

    so, type: beast new sampleApp *Don’t worry about if it doesn’t work. It’s a symlink to bin/cli.js . Use the following command instead: bin/cli.js new sample Result This process will create a base app called “sample” We’ll explain what’s inside a sample app now.
  14. App template (II) What’s inside? >cd sampleApp • server.js •

    express • minimist • package.json • dependencies • properties • public • front-end
  15. Packaging and launching Playing with the dashboard It’s necessary to

    compress your app before uploading it to the dashboard. You can do it with beast pkg ../sampleApp --to ../sampleApp.tar.gz and check localhost:8000 on your browser. After that we are ready to install it: beast install sampleApp.tar.gz
  16. Get on with it! We’ll have a look over a

    plugin and then we’ll use a virtual bulb!
  17. What’s a plugin? (I) It’s the key that allows you

    to interact with smart devices in your apps. It uses the Netbeast API. Using the netbeast-cli we can create a base plugin. Type: beast new samplePlugin –-plugin You will get the following structure: • package.json • index.js • test.js
  18. MQTT We use MQTT for data exposition. Then, one device

    could access to resources exposed by other devices. For example: Your Bulbs could be triggered if a sensor detects a luminosity reduction. MQTT is a lightweight messaging protocol. It’s commonly used in IoT. Te steps are simple: 1. *Broker Connection 2. Publish/Subscribe *The broker is the “brain” of an MQTT scenario
  19. MQTT We use Mosca in dashboard as a broker: -

    Notifications - Resources The Broker (MQTT server)
  20. MQTT You’ll connect to IP:PORT broker var client = mqtt.connect('ws://IP:PORT’)

    You can publish your data (MESSAGE) to a TOPIC client.publish(TOPIC, MESSAGE) Have a look on how we use MQTT:
  21. Hands on! How can we interact with devices? beast('topic').set({ property:

    value }) What’s the topic, property and value? Topics: lights, music, switch power: true || false hue: 0..360 saturation: 0..100 brightness: 0..100 color:#FF13AA

More Decks by Fran

Other Decks in Technology