|
| 1 | + |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | +# Máster en Programación FullStack con JavaScript y Node.js |
| 8 | +### JS, Node.js, Frontend, Backend, Firebase, Express, Patrones, HTML5_APIs, Asincronía, Websockets, Testing |
| 9 | + |
| 10 | +## Clase 73 |
| 11 | + |
| 12 | +### MQTT |
| 13 | + |
| 14 | + |
| 15 | + |
| 16 | +> MQTT es un protocolo de mensajería basado en ISO estándar publicación-suscripción. Funciona sobre el protocolo TCP / IP. Está diseñado para conexiones con ubicaciones remotas donde se requiere una "huella de código pequeño" o el ancho de banda de la red es limitado [Wikipedia](https://en.wikipedia.org/wiki/MQTT) |
| 17 | +
|
| 18 | +**Funcionamiento del protocolo** |
| 19 | + |
| 20 | + |
| 21 | + |
| 22 | +**Esquema con web** |
| 23 | + |
| 24 | + |
| 25 | + |
| 26 | +**Recursos** |
| 27 | +- [How to Build an High Availability - MQTT Cluster for the Internet of Things](https://medium.com/@lelylan/how-to-build-an-high-availability-mqtt-cluster-for-the-internet-of-things-8011a06bd000) |
| 28 | +- [IBM | Conociendo MQTT](https://www.ibm.com/developerworks/ssa/library/iot-mqtt-why-good-for-iot/index.html) |
| 29 | +- [MQTT: un protocolo específico para el internet de las cosas](http://www.digitaldimension.solutions/es/blog-es/opinion-de-expertos/2015/02/mqtt-un-protocolo-especifico-para-el-internet-de-las-cosas/) |
| 30 | + |
| 31 | +### Librerías de Real Time |
| 32 | + |
| 33 | +**MQTT** |
| 34 | +- [MQTT.js](https://github.com/mqttjs/MQTT.js) *The MQTT client for Node.js and the browser* |
| 35 | +- [Mosca](https://github.com/mcollina/mosca) *MQTT broker as a module* |
| 36 | +- [aedes](https://github.com/mcollina/aedes) *Barebone MQTT broker that can run on any stream server, the node way* |
| 37 | +- [ascoltatori](https://github.com/mcollina/ascoltatori) *The pub/sub library for node backed by Redis, MongoDB, AMQP (RabbitMQ), ZeroMQ, MQTT (Mosquitto) or just plain node!* |
| 38 | + |
| 39 | +**Web Sockets** |
| 40 | + |
| 41 | +- [socket.io](https://github.com/socketio/socket.io) *Realtime application framework (Node.JS server)* |
| 42 | +- [sockjs](https://github.com/sockjs/sockjs-node) *WebSocket emulation - Node.js server* |
| 43 | +- [uWebSockets](https://github.com/uNetworking/uWebSockets) *Tiny WebSockets* |
| 44 | +- [SocketCluster](https://github.com/SocketCluster/socketcluster) *Highly scalable realtime framework* |
| 45 | +- [engine.io](https://github.com/socketio/engine.io) *Engine.IO is the implementation of transport-based cross-browser/cross-device bi-directional communication layer for Socket.IO.* |
| 46 | +- [Kalmjs](https://github.com/kalm/kalm.js) *The MQTT client for Node.js and the browser* |
| 47 | +- [rpc-websockets](https://github.com/elpheria/rpc-websockets) *JSON-RPC 2.0 implementation over WebSockets for Node.js and JavaScript* |
| 48 | +- [deepstream.io-client-js](https://github.com/deepstreamIO/deepstream.io-client-js) *The Browser / Node.js Client for deepstream.io* |
| 49 | + |
| 50 | +**Otras** |
| 51 | +- [Faye](https://github.com/faye/faye) *Simple pub/sub messaging for the web* |
| 52 | +- [Primus](https://github.com/primus/primus) *⚡️ Primus, the creator god of the transformers & an abstraction layer for real-time to prevent module lock-in.* |
| 53 | +- [node-browserchannel](https://github.com/josephg/node-browserchannel) *An implementation of a google browserchannel server in node.js* |
| 54 | + |
| 55 | +### Socket IO |
| 56 | + |
| 57 | +**Servidor con `http`** |
| 58 | + |
| 59 | +`public/index.html` |
| 60 | + |
| 61 | +```html |
| 62 | + |
| 63 | +<script src="http://localhost:3000/socket.io/socket.io.js"></script> |
| 64 | +<script> |
| 65 | + var socket = io("http://localhost:3000"); |
| 66 | + // use your socket |
| 67 | + socket.on("welcome", (message) => { |
| 68 | + // do something with the message. |
| 69 | + }) |
| 70 | +</script> |
| 71 | +``` |
| 72 | + |
| 73 | +`server.js` |
| 74 | +```js |
| 75 | +const app = require('http').createServer(handler); |
| 76 | +const io = require('socket.io')(app); |
| 77 | +const fs = require('fs'); |
| 78 | + |
| 79 | +app.listen(80); |
| 80 | + |
| 81 | +function handler (req, res) { |
| 82 | + fs.readFile(`${__dirname}/index.html`, |
| 83 | + (err, data) => { |
| 84 | + if (err) { |
| 85 | + res.writeHead(500); |
| 86 | + return res.end('Error loading index.html'); |
| 87 | + } |
| 88 | + |
| 89 | + res.writeHead(200); |
| 90 | + res.end(data); |
| 91 | + }); |
| 92 | +} |
| 93 | + |
| 94 | +io.on('connection', socket => { |
| 95 | + socket.emit('news', { hello: 'world' }); |
| 96 | + socket.on('my other event', data => { |
| 97 | + console.log(data); |
| 98 | + }); |
| 99 | +}); |
| 100 | +``` |
| 101 | + |
| 102 | + |
| 103 | +**Servidor con `Express`** |
| 104 | + |
| 105 | +`public/index.html` |
| 106 | +```html |
| 107 | + |
| 108 | +<script src="/socket.io/socket.io.js"></script> |
| 109 | +<script> |
| 110 | + var socket = io(); |
| 111 | +</script> |
| 112 | +``` |
| 113 | + |
| 114 | +`server.js` |
| 115 | +```js |
| 116 | +const app = require('express')(); |
| 117 | +const http = require('http').Server(app); |
| 118 | +const io = require('socket.io')(http); |
| 119 | + |
| 120 | +app.get('/', (req, res) => { |
| 121 | + res.sendFile(`${__dirname}/index.html`); |
| 122 | +}); |
| 123 | + |
| 124 | +io.on('connection', socket => { |
| 125 | + console.log('a user connected'); |
| 126 | +}); |
| 127 | + |
| 128 | +http.listen(3000, () => { |
| 129 | + console.log('listening on *:3000'); |
| 130 | +}); |
| 131 | +``` |
| 132 | + |
| 133 | +**Recursos** |
| 134 | +- [Web Site](https://socket.io/) |
| 135 | +- [Socket.io | Blog](https://socket.io/blog/socket-io-2-0-1-2-0-2-and-2-0-3/) |
| 136 | +- [Socket.io Docs | Overview](https://socket.io/docs/) |
| 137 | +- [Socket.io | Demos](https://socket.io/demos/chat/) |
| 138 | +- [Socket.io Docs | Server](https://socket.io/docs/server-api/) |
| 139 | +- [Socket.io Docs | Client](https://socket.io/docs/client-api/) |
| 140 | +- [Socket.io Docs | Introduction](https://socket.io/get-started/chat/) |
| 141 | +- [Socket.io Docs | The web framework](https://socket.io/get-started/chat/#The-web-framework) |
| 142 | +- [Socket.io Docs | Serving HTML](https://socket.io/get-started/chat/#Serving-HTML) |
| 143 | +- [Socket.io Docs | Integrating Socket.IO](https://socket.io/get-started/chat/#Integrating-Socket-IO) |
| 144 | +- [Socket.io Docs | Emitting events](https://socket.io/get-started/chat/#Emitting-events) |
| 145 | +- [Socket.io Docs | Broadcasting](https://socket.io/get-started/chat/#Broadcasting) |
| 146 | +- [Socket.io Docs | Homework](https://socket.io/get-started/chat/#Homework) |
| 147 | +- [Socket.io Docs | Getting this example](https://socket.io/get-started/chat/#Getting-this-example) |
| 148 | +- [How to build a real time chat application in Node.js using Express, Mongoose and Socket.io](https://medium.freecodecamp.org/simple-chat-application-in-node-js-using-express-mongoose-and-socket-io-ee62d94f5804) |
| 149 | +- [Carlos Azaustre | WebSockets: Cómo utilizar Socket.io en tus aplicaciones web](https://carlosazaustre.es/websockets-como-utilizar-socket-io-en-tu-aplicacion-web/) |
| 150 | +- [Introducción a Socket.io #nodejs](http://www.nodehispano.com/2012/09/introduccion-a-socket-io-nodejs/) |
| 151 | +- [Servidor real time con socket.io](https://medium.com/@eddydecena/servidor-real-time-con-socket-io-18e84d39d12b) |
| 152 | +- [You don't need express to get started with socket.io](https://dev.to/sadick/you-dont-need-express-to-get-started-with-socketio-4ieg) |
| 153 | + |
| 154 | +### Mosca |
| 155 | + |
| 156 | + |
| 157 | + |
| 158 | +**Claves** |
| 159 | + |
| 160 | +- Standalone con `$ mosca` |
| 161 | +- Puede embeberse en otras aplicaciones |
| 162 | +- Autenticable con APIs |
| 163 | +- Soporta AMQP, Mongo, Redis, y MQTT como pub/sub backends |
| 164 | +- Necesita una base de datos como LevelDB, Mongo, o Redis |
| 165 | +- Soporta websockets |
| 166 | +- Rápido, 10k+ mensajes ruteados por segundo |
| 167 | +- Escalable, 10k+ conexiones concurrentes |
| 168 | + |
| 169 | +**Esquema de funcionamiento** |
| 170 | + |
| 171 | + |
| 172 | + |
| 173 | +**Servidor standalone** |
| 174 | +```js |
| 175 | +var mosca = require('mosca'); |
| 176 | + |
| 177 | +var ascoltatore = { |
| 178 | + //using ascoltatore |
| 179 | + type: 'mongo', |
| 180 | + url: 'mongodb://localhost:27017/mqtt', |
| 181 | + pubsubCollection: 'ascoltatori', |
| 182 | + mongo: {} |
| 183 | +}; |
| 184 | + |
| 185 | +var settings = { |
| 186 | + port: 1883, |
| 187 | + backend: ascoltatore |
| 188 | +}; |
| 189 | + |
| 190 | +var server = new mosca.Server(settings); |
| 191 | + |
| 192 | +server.on('clientConnected', function(client) { |
| 193 | + console.log('client connected', client.id); |
| 194 | +}); |
| 195 | + |
| 196 | +// fired when a message is received |
| 197 | +server.on('published', function(packet, client) { |
| 198 | + console.log('Published', packet.payload); |
| 199 | +}); |
| 200 | + |
| 201 | +server.on('ready', setup); |
| 202 | + |
| 203 | +// fired when the mqtt server is ready |
| 204 | +function setup() { |
| 205 | + console.log('Mosca server is up and running'); |
| 206 | +} |
| 207 | +``` |
| 208 | + |
| 209 | +**Recursos** |
| 210 | +- [Mosca Wiki](https://github.com/mcollina/mosca/wiki) |
| 211 | +- [Mosca Wiki | MQTT over Websockets](https://github.com/mcollina/mosca/wiki/MQTT-over-Websockets) |
| 212 | +- [Mosca Wiki | Authentication & Authorization](https://github.com/mcollina/mosca/wiki/Authentication-&-Authorization) |
| 213 | +- [Mosca Wiki | Docker support](https://github.com/mcollina/mosca/wiki/Docker-support) |
| 214 | +- [Mosca Wiki | FAQ (Frequently asked questions)](https://github.com/mcollina/mosca/wiki/FAQ-(Frequently-asked-questions)) |
| 215 | +- [Mosca Wiki | Mosca & Redis & Ascoltatori](https://github.com/mcollina/mosca/wiki/Mosca-&-Redis-&-Ascoltatori) |
| 216 | +- [Mosca Wiki | Mosca advanced usage](https://github.com/mcollina/mosca/wiki/Mosca-advanced-usage) |
| 217 | +- [Mosca Wiki | Mosca as a standalone service](https://github.com/mcollina/mosca/wiki/Mosca-as-a-standalone-service.) |
| 218 | +- [Mosca Wiki | Mosca basic usage](https://github.com/mcollina/mosca/wiki/Mosca-basic-usage) |
| 219 | +- [Mosca Wiki | Mosca Showcase](https://github.com/mcollina/mosca/wiki/Mosca-Showcase) |
| 220 | +- [Mosca Wiki | Persistence support](https://github.com/mcollina/mosca/wiki/Persistence-support) |
| 221 | +- [Mosca Wiki | TLS SSL Configuration](https://github.com/mcollina/mosca/wiki/TLS-SSL-Configuration) |
| 222 | +- [Mosca Wiki | Under the hood aka how mosca works](https://github.com/mcollina/mosca/wiki/Under-the-hood---aka-how-mosca-works) |
| 223 | +- [Mosca in Github](https://github.com/mcollina/mosca) |
| 224 | +- [MQTT and Node.js - Messaging in the Internet of Things](http://mcollina.github.io/mqtt_and_nodejs/) |
| 225 | +- [Setting up private MQTT broker using Mosca in Node.js](https://medium.com/@alifabdullah/setting-up-private-mqtt-broker-using-mosca-in-node-js-c61a3c74f952) |
| 226 | +- [Control your home using only Javascript](https://medium.com/@marassi/control-your-home-using-only-javascript-72a3b071c894) |
| 227 | +- [Real time communications between IoT devices and Front-End JS apps](https://medium.com/@armova/real-time-communications-between-iot-devices-and-front-end-js-apps-20db4629b6f5) |
| 228 | + |
| 229 | +### Node RED |
| 230 | + |
| 231 | + |
| 232 | + |
| 233 | + |
| 234 | +**[Funcionamieto](https://www.youtube.com/watch?v=f5o4tIz2Zzc)** |
| 235 | + |
| 236 | + |
| 237 | + |
| 238 | +**Recursos** |
| 239 | +- [Node-RED](https://nodered.org/) |
| 240 | +- [Node-RED | Blog](https://nodered.org/blog/) |
| 241 | +- [Node-RED | Docs](https://nodered.org/docs/) |
| 242 | +- [Node-RED | Flows](https://flows.nodered.org/?num_pages=1) |
| 243 | +- [Node-RED Docs | Getting Started](https://nodered.org/docs/getting-started/) |
| 244 | +- [Node-RED Docs | User Guide](https://nodered.org/docs/user-guide/) |
| 245 | +- [Node-RED Docs | Node-RED Cookbook](https://cookbook.nodered.org/) |
| 246 | +- [Node-RED Docs | Creating Nodes](https://nodered.org/docs/creating-nodes/) |
| 247 | +- [Node-RED Docs | Developing Node-RED](https://nodered.org/docs/developing/) |
| 248 | +- [Node-RED Docs | API Reference](https://nodered.org/docs/api/) |
| 249 | +- [Github](https://github.com/node-red/node-red) |
| 250 | +- [Introducción a Node-RED y Raspberry Pi con un sistema de alarma con Arduino](https://programarfacil.com/blog/raspberry-pi/introduccion-node-red-raspberry-pi/) |
| 251 | +- [Node Red in 5 minutes](https://www.youtube.com/watch?v=f5o4tIz2Zzc) |
| 252 | +- [Intro to Node-RED: Part 1 Fundamentals](https://www.youtube.com/watch?v=3AR432bguOY) |
| 253 | +- [Node-RED un software para dominarlos a todos](https://www.youtube.com/watch?v=ZgG-rKLP_XI) |
| 254 | +- [Programación Visual con Node-Red: Conectando el Internet de las Cosas con Facilidad](https://www.toptal.com/nodejs/programacion-visual-con-node-red-conectando-el-internet-de-las-cosas-con-facilidad/es) |
0 commit comments