Johnny Five + Arduino + Node Web Server

Johnny Five Node Module

Johnny Five – Buttons

Arduino + Johnny Five

Johnny Five – Relay

Originally wired the relay and button based on a different diagram. With Johnny five though, its looking for a much more logical and clear setup. So I rewired based on the diagrams and had to see the relay to type: "NC" and was able to get the lights to turn on and off with the correct button pushes.

Johnny Five really helps abstract away the need to figure out how Firmata is handling everything but also allows you a lot of control with great documentation (once you find it).

Pass one of Button + Web Browser turning off and on a light:


var express = require("express"); var five = require("johnny-five"); var board = new five.Board(); var bumper; var app = express(); var httpServer = require("http").createServer(app); var io=require('socket.io')(httpServer); var port = 3000; app.use(express.static(__dirname + '/public')); app.get('/', function(req, res) { res.sendFile(__dirname + '/public/index.html'); }); httpServer.listen(port); console.log('Server available at http://localhost:' + port); var led; var relayShelfLed; var bumperShelfLed; board.on("ready", function() { relayShelfLed = new five.Relay({ pin: 22, isOn: true, type: "NC" }); this.repl.inject({ relay: relayShelfLed }); bumperShelfLed = new five.Button({ pin: 52, // invert: true }); relayShelfLed.off(); bumperShelfLed.on("hold", function() { console.log( "Button held" ); }); bumperShelfLed.on("press", function() { if(relayShelfLed.isOn){ console.log('turn off'); relayShelfLed.off(); }else{ console.log('turn on'); relayShelfLed.on(); } console.log( "Button pressed" ); }); bumperShelfLed.on("release", function() { console.log( "Button released" ); }); //Socket connection handler io.on('connection', function (socket) { console.log(socket.id); console.log(relayShelfLed.isOn); socket.on('led:on', function (data) { relayShelfLed.on(); console.log('LED ON RECEIVED'); }); socket.on('led:off', function (data) { relayShelfLed.off(); console.log('LED OFF RECEIVED'); }); }); console.log('Waiting for connection'); }); //turn light on //turn light off //event emiter for light

I created a quick project to make this work with my arduino and a relay.

Office Manager

Continue reading Johnny Five + Arduino + Node Web Server

headless websites – intro

To coin a coined phrase, headless website.

Headless Website – Whats the big deal

I haven’t found a good way to describe this web architecture. There is the repository pattern that starts this idea off.

It looks like this:

Database (MySQL) –> Private (or Public) Api – (PHP) – “The Backend” –> Middleware Api / Restful Api –> Frontend – (AngularJS)

Best Practices REST API from Scratch – Introduction

This structure introduces the decoupling of code for better control, great accessibility and a robust api interface. Now the api is able to be used for accessing data for the web app and the iOS app. Now you can spin up more front end servers to handle the load with out having to as many backend servers (possibly dedicated) running allowing for better monitoring, stability and deployment.

Continue reading headless websites – intro