Jerrin George James
Published © GPL3+

Accio - Searching for Things Using Voice

Losing things is a part of life. Accio makes sure you always get back what you lose, via voice.

AdvancedFull instructions provided15 hours664
Accio - Searching for Things Using Voice

Things used in this project

Story

Read more

Custom parts and enclosures

KiCAD project

Project file for the PCB design

KiCAD PCB file

Open using KiCAD. This is the layout for the PCB

Schematics

KiCAD schematic file for Accio

Can be opened using KiCAD, which is an open source tool for PCB schema and layout design, or using several online tools

Code

Arduino program for the ESP_8266

Arduino
Just upload this code one by one onto the ESP boards, after un-commenting all the marker identity specific parts. For eg, for a marker named "keys", only that particular code for "keys" section is to be uncommented. Similarly, for "wallet" marker, keep the "wallet" section uncommented, and comment the "keys" section
#include <ESP8266WiFi.h>
#include <PubSubClient.h>


// Update these with values suitable for your network.
const char* ssid = "WiFi_name_here";
const char* password = "WiFi_passwd_here";
const char* mqtt_server = "IP_address_of_the_MQTT_master(raspberry pi 3b+ in this case)";
#define mqtt_port 1883
#define MQTT_USER ""
#define MQTT_PASSWORD ""
#define MQTT_SERIAL_PUBLISH_CH "hermes/"
#define MQTT_SERIAL_RECEIVER_CH "hermes/asr/test"
//    "hermes/asr/test" topic has defined by me in index.js file

WiFiClient wifiClient;

PubSubClient client(wifiClient);

void setup_wifi() {

    delay(10);
    
    // We start by connecting to a WiFi network
      
    Serial.println();
    Serial.print("Connecting to ");
    Serial.println(ssid);
    WiFi.begin(ssid, password);
    while (WiFi.status() != WL_CONNECTED) {
      delay(500);
      Serial.print(".");
    }
    randomSeed(micros());
    Serial.println("");
    Serial.println("WiFi connected");
    Serial.println("IP address: ");
    Serial.println(WiFi.localIP());
}

void reconnect() {

  // Loop until reconnected
  
  while (!client.connected()) {
    
    Serial.print("Attempting MQTT connection...");
    // Create a random client ID
    String clientId = "NodeMCUClient-";
    clientId += String(random(0xffff), HEX);
    // Attempt to connect
    
    if (client.connect(clientId.c_str(),MQTT_USER,MQTT_PASSWORD)) {
      
      Serial.println("connected");
      //Once connected, publish an announcement...
      client.publish("/ic/presence/nm/", "hello world");
      // ... and resubscribe
      client.subscribe(MQTT_SERIAL_RECEIVER_CH);
    } else {
      
      Serial.print("failed, rc=");
      Serial.print(client.state());
      Serial.println(" try again in 5 seconds");
      // Wait 5 seconds before retrying
      delay(5000);
    
    }
  }
}


void callback(char* topic, byte *payload, unsigned int length) {
   
   //this is where we add the action code
   //check payload pointer to get data sent from the base station R-Pi over mqtt
   //comment the necessary sections as per requirement  
    
    if(*payload=='1')
    {
      Serial.println("got alpha"); 
      digitalWrite(2,HIGH);
      delay(500);
      digitalWrite(2,LOW);
      delay(500);
      digitalWrite(2,HIGH);
      delay(500);
      digitalWrite(2,LOW);
      delay(500);
      digitalWrite(2,HIGH);
      delay(500);
      digitalWrite(2,LOW);
      delay(500);
      
    }
    else if(*payload=='2')
    {
      Serial.println("got beta");
      digitalWrite(2,HIGH);
      delay(300);
      digitalWrite(2,LOW);
      delay(600);
      digitalWrite(2,HIGH);
      delay(1000);
      digitalWrite(2,LOW);
      delay(600);
      digitalWrite(2,HIGH);
      delay(300);
      digitalWrite(2,LOW);
      delay(300);
      
    }
    else
    {
      Serial.println("got gamma");
      digitalWrite(2,HIGH);
      delay(100);
      digitalWrite(2,LOW);
      delay(100);
      digitalWrite(2,HIGH);
      delay(1000);
      digitalWrite(2,LOW);
      delay(1000);
      digitalWrite(2,HIGH);
      delay(100);
      digitalWrite(2,LOW);
      delay(100);
      
    }
    Serial.println();
}

void setup() {

  pinMode(2, OUTPUT);
  Serial.begin(115200);
  Serial.setTimeout(500);// Set time out for 
  setup_wifi();
  client.setServer(mqtt_server, mqtt_port);
  client.setCallback(callback);
  reconnect();

}


void publishSerialData(char *serialData){
  
  if (!client.connected()) {
    reconnect();
  }
  client.publish(MQTT_SERIAL_PUBLISH_CH, serialData);
}
void loop() {

   client.loop();

     if (Serial.available() > 0) {
     char bfr[101];
     memset(bfr,0, 101);
     Serial.readBytesUntil( '\n',bfr,100);
     Serial.print(bfr);
  }

}

Node.js program for mqtt

JavaScript
This program serves to link the output from Snips.ai voice algorithms, and the ESP-8266 based marker boards. The program detects the intent identified by the software, for eg, "keys", and then translates this info for the hardware ESP-8266
var mqtt = require('mqtt');

var hostname = "mqtt://(ip_addr_of_base_station_r_pi_here)";
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) {
  
  //This function is the action code. I have set the keywords as alpha, beta and gamma for the 3 markers. When they are identified, this code sends a ping over the mqtt channel "hermes/asr/test"
    console.log("[Snips Log] Intent detected: " + JSON.stringify(intent));
    if(JSON.stringify(intent).match(/alpha/g)!== null) {
	console.log("alpha detected");
        client.publish("hermes/asr/test","1");
   }
    else if(JSON.stringify(intent).match(/beta/g) !== null) {
	client.publish("hermes/asr/test","2");
        console.log("beta detected");
   }
    else if(JSON.stringify(intent).match(/gamma/g) !== null) {
        client.publish("hermes/asr/test","3");
        console.log("gamma detected");
   }
}

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

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

Credits

Jerrin George James

Jerrin George James

1 project • 0 followers

Comments