Skip to content

Instantly share code, notes, and snippets.

# Listen to all MQTT requests (port 1883)
listen mqtt
# MQTT binding to port 1883
bind *:1883
# communication mode (MQTT works on top of TCP)
mode tcp
option tcplog
# balance mode (to choose which MQTT server to use)
balance leastconn
# MQTT server 1
# Container to start from with a working HAProxy definition
FROM dockerfile/haproxy
MAINTAINER Andrea Reginato <andrea.reginato@gmail.com>
# Add personalized configuration
ADD haproxy.cfg /etc/haproxy/haproxy.cfg
# Add restart commands
ADD restart.bash /haproxy-restart
# node image
FROM node:0.10-onbuild
# docker mantainer
MAINTAINER reggie
# add the files to load
ADD ./ .
# install all needed packages
var mongoose = require('mongoose')
, debug = require('debug')('lelylan')
, Device = require('../app/models/devices/device');
module.exports.authenticate = function(client, username, password, callback) {
Device.findOne({ _id: username, secret: password }, function (err, doc) {
if (doc) client.device_id = doc.id
callback(null, doc);
});
}
var server = require('./lib/server')
, debug = require('debug')('lelylan');
var ascoltatore = {
type: 'redis',
redis: require('redis'),
db: 12,
port: 6379,
host: process.env.REDIS_HOST }
, settings = {
// MQTT server address
byte server[] = { 178, 62, 108, 47 };
// Yun definition
YunClient yun;
// subscription callback
void callback(char* topic, byte* payload, unsigned int length);
// mqtt client connection
PubSubClient client(server, 1883, callback, yun);
/* arduino setup */
void setup() {
Serial.begin(9600);
delay(500);
Serial.println("Start initialization of Yun...");
Bridge.begin();
Serial.println("Starting connection to lelylan...");
lelylanConnection(); // MQTT server connection
pinMode(inPin, INPUT); // button pin setup
pinMode(outPin, OUTPUT); // led pin setup
/* Pins configuration */
int inPin = 3; // button
int outPin = 13; // led
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD)
GPIO.cleanup()
# led pin setup
GPIO.setup(7, GPIO.OUT)
# button pin setup
GPIO.setup(12, GPIO.IN)
import mosquitto, json, time
#include <Adafruit_CC3000.h>
#include <ccspi.h>
#include <SPI.h>
#include <cc3000_PubSubClient.h>
// These are the interrupt and control pins
#define ADAFRUIT_CC3000_IRQ 3
// These can be any two pins
#define ADAFRUIT_CC3000_VBAT 9
#define ADAFRUIT_CC3000_CS 10