Skip to content

Instantly share code, notes, and snippets.

@LosantGists
LosantGists / index.js
Created April 12, 2016 15:07
spy-satellites-and-the-internet-of-things
var async = require('async');
var Wemo = require('wemo-client');
var Device = require('losant-sdk-js').Device;
// The serial number of the Wemo. Makes sure that if there's multiple on
// the network, we pick the right one.
var myWemoSerial = 'my-wemo-serial';
var wemo = new Wemo();
var device = new Device({
@LosantGists
LosantGists / hello-world.cpp
Created April 12, 2016 15:08
getting-started-with-platformio-esp8266
#include <Arduino.h>
void setup() {
Serial.begin(9600);
}
void loop() {
delay(1000);
Serial.println("Hello World!");
}
@LosantGists
LosantGists / function.js
Created April 12, 2016 15:09
how-to-connect-discourse-to-slack
var result = {
newPost: null,
newPostId: null
};
// If this is the first time through, lastID will be undefined.
// Set it to the most recent post and return.
if(!payload.data.lastId) {
if(payload.data.latest.body.latest_posts.length) {
result.newPostId = payload.data.latest.body.latest_posts[0].id;
@LosantGists
LosantGists / losant-step1.ino
Last active May 4, 2016 20:04
how-to-connect-a-particle-photon-to-the-losant-iot-platform
// This #include statement was automatically added by the Particle IDE.
#include "SparkJson/SparkJson.h"
// This #include statement was automatically added by the Particle IDE.
#include "MQTT/MQTT.h"
void setup() {
}
@LosantGists
LosantGists / device-button.ino
Created April 12, 2016 15:21
losant-sneak-preview-2-m2m-communication
void buttonPressed() {
Serial.println("Button Pressed!");
// Losant uses a JSON protocol. Construct the simple state object.
// { "button" : true }
StaticJsonBuffer<200> jsonBuffer;
JsonObject& root = jsonBuffer.createObject();
root["button"] = true;
// Send the state to Losant.
@LosantGists
LosantGists / main.js
Created April 12, 2016 15:21
how-to-build-an-amazon-echo-clone-with-ibm-watson-and-intel-edison Raw
/*jslint node:true, vars:true, bitwise:true, unparam:true */
/*jshint unused:true */
// load required modules
var async = require('async'); // helps control asynchronous flow
var path = require('path'); // utility for handling file paths
var exec = require('child_process').exec; // runs a command in a shell and buffers the output
var spawn = require('child_process').spawn; // launches a child process
var request = require('request'); // http request client
var watson = require('watson-developer-cloud'); // IBM Watson services client
@LosantGists
LosantGists / creating-a-motion-sensitive-light-using-an-edison-and-a-wemo.js
Created April 12, 2016 15:22
creating-a-motion-sensitive-light-using-an-edison-and-a-wemo
var Cylon = require('cylon');
var Wemo = require('wemo-client');
var findOutlet = function(cb){
var wemo = new Wemo();
var stop = false;
wemo.discover(function(deviceInfo) {
if(stop || deviceInfo.friendlyName !== 'LosantOutlet_1') { return; }
stop = true;
console.log('Found outlet!');
@LosantGists
LosantGists / edison-automatic-process-startup.service.ini
Created April 12, 2016 15:23
edison-automatic-process-startup
[Unit]
Description=Hue Light Control Service
Wants=network-online.target
After=network-online.target
[Service]
ExecStart=/usr/bin/node /usr/local/hue-light-control/worker.js
User=nobody
Restart=on-failure
RestartSec=10
@LosantGists
LosantGists / how-to-build-an-arduino-powered-led-dice.js
Created April 12, 2016 15:26
how-to-build-an-arduino-powered-led-dice
/* Define the GPIO pins each LED is connected to */
int leftTop = 2;
int leftMiddle = 3;
int leftBottom = 4;
int middleMiddle = 5;
int rightTop = 6;
int rightMiddle = 7;
int rightBottom = 8;
/* Save them in an array so we can easily iterate all of them. */
'use strict';
const doc = require('dynamodb-doc');
const dynamo = new doc.DynamoDB();
exports.handler = (event, context, callback) => {
if(!event || !Array.isArray(event)){ return callback(null, null); }
let deviceSerial;
event.forEach((pair) => {
if(pair.key === 'deviceSerial'){ deviceSerial = pair.value; }