merakian
Created April 9, 2019

Chore Choreographer

Roommates are always out and about, and it's hard to coordinate tasks to share. I'd like tasks to be streamlined.

BeginnerShowcase (no instructions)10 hours21
Chore Choreographer

Things used in this project

Hardware components

Snips Voice Interaction Development Kit (Base Kit)
Snips Voice Interaction Development Kit (Base Kit)
×1

Software apps and online services

Raspbian
Raspberry Pi Raspbian

Story

Read more

Code

Chore Assigner

JavaScript
"use strict";
const nodemailer = require("nodemailer");
let testAccount = nodemailer.createTestAccount();
let transporter = nodemailer.createTransport({
  service: 'gmail',
  auth: {
    user: 'central_email_address',
    pass: 'central_email_address_password'
  }
});

var mqtt = require('mqtt');

var hostname = "mqtt://raspberrypi.local"; // put in ip address of raspberry pi
var client  = mqtt.connect(hostname);

client.on('connect', function () {
    console.log("[Snips Log] Connected to MQTT broker " + hostname);
    client.subscribe('hermes/#');
});

client.on('message', function (topic, message) {
    if (topic === "hermes/asr/startListening") {
        onListeningStateChanged(true);
    } else if (topic === "hermes/asr/stopListening") {
        onListeningStateChanged(false);
    } else if (topic.match(/hermes\/hotword\/.+\/detected/g) !== null) {
        onHotwordDetected()
    } else if (topic.match(/hermes\/intent\/.+/g) !== null) {
        onIntentDetected(JSON.parse(message));
    }
});

function onIntentDetected(intent) {
    console.log("[Snips Log] Intent detected: " + JSON.stringify(intent));
    var roommate_array = ["roommate_1", "roommate_2", "roommate_3"];
    var roommate_email = ["email_1", "email_2", "email_3"];
    var chore_array = ["chore_1", "chore_2", "chore_3", "chore_4"];
    var roommate;
    var chore;
    for(roommate = 0; roommate < roommate_array.length; roommate++)
    {
      if(intent.search(roommate_array[roommate]) != -1)
      {
        for(chore = 0; chore < chore_array.length; chore++)
        {
          if(intent.search(chore_array[chore]) != -1)
          {
            break;
          }
        }
        break;
      }
    }
    //console.log(intent);
    let info = transporter.sendMail({
      from: '<central_email_address>', // central address you have to replace this
      to: roommate_email[roommate],// roommate to contact
      subject: chore_array[chore] // chore to do
    });
}

function onHotwordDetected() {
    console.log("[Snips Log] Hotword detected");
}

function onListeningStateChanged(listening) {
    console.log("[Snips Log] " + (listening ? "Start" : "Stop") + " listening");
}

Credits

merakian
4 projects • 3 followers
Contact

Comments

Please log in or sign up to comment.