Jordy De Rosa
Created February 24, 2018 © GPL3+

Kitchen Assistant

No time to write a shopping list? You don't know what cook today? This is your Kitchen Assistant - Food Scanner Hardware and Alexa Skill

IntermediateFull instructions provided6 hours433
Kitchen Assistant

Things used in this project

Hardware components

Arduino MKR1000
Arduino MKR1000
×1
LED (generic)
LED (generic)
×1
barcode scanner
×1
Echo Dot
Amazon Alexa Echo Dot
×1

Software apps and online services

Alexa Skills Kit
Amazon Alexa Alexa Skills Kit
AWS Lambda
Amazon Web Services AWS Lambda
ARTIK Cloud for IoT
Samsung ARTIK Cloud for IoT
Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Custom parts and enclosures

fritzing_file_bb_8E0ZgqPZwl.pdf

Schematics

Wiring Scheme

Code

Gateway

PHP
No preview (download only).

Lambda Deployment

JavaScript
Language NodeJS
No preview (download only).

Arduino code

Arduino
/*
 this script is written by Jordy De Rosa who is the unique owner of this software
This is a project submitted to The Alexa and Arduino Smart Home Challenge contest on 
https://www.hackster.io/contests/alexasmarthome
 */
#include <MQTTClient.h> 
#include <ArduinoJson.h> 
#include <SPI.h> 
#include <WiFi101.h> 
#include "TimerObject.h"
const char* _SSID     = "";                                         //Wi-Fi SSID  
const char* _PASSWORD = "";                                         // Wi-Fi Password  
// MQTT - Artik Cloud Server params 
char Artik_Cloud_Server[]     = "api.artik.cloud";                  // Server  
int  Artik_Cloud_Port         = 8883;                               // MQTT Port 
char Client_Name[] = "";                                            // Any Name  
char Device_ID[]   = "";                                            // DEVICE ID 
char Device_TOKEN[]   = "";                                         //  DEVICE TOKEN 
char buf[200]; 
char MQTT_Subscription[] = "/v1.1/actions/YOU_DEVICE_ID";           // (/v1.1/actions/"DEVICE ID") 
char MQTT_Publish[] = "/v1.1/messages/YOUR_DEVICE_ID";              // (/v1.1/messages/"DEVICE ID") 

TimerObject *timer1 = new TimerObject(900000);                      //Timeout to change food scanner mode carica/scarica


WiFiSSLClient client; 
MQTTClient MQTT_Artik_Client;                                       // MQTT Protocol 
//led SET 
int ledPin=17;                                                      //define a led pin in my case arduino pin n. 17

//function to manage received action from Artik Cloud
void messageReceived(String &topic, String &payload) 
{
          DynamicJsonBuffer  jsonBuffer(200);                       //you can save memory by declaring a static buffer
          Serial.println("incoming: " + topic + " - " + payload);
          JsonObject& jsonresponse = jsonBuffer.parseObject(payload);//parse json message from Artik Cloud
            
         String action=jsonresponse["actions"][0]["name"];
         if(action=="setOn")
         {
            digitalWrite(ledPin,HIGH);
            timer1->Start();
         }
         else if(action=="setOff")
            digitalWrite(ledPin,LOW);

}

void setup() 
{ 
      //inizialize pin and Serial port
      pinMode(ledPin,OUTPUT);                             
      pinMode(16,OUTPUT);                                 //i've attached led ground pin to Arduino pin n. 16 and setted it to LOW
      digitalWrite(16,LOW);
      //set timer to change food scanner mode
      timer1->setOnTimer(&ResetMode);
         
      //Inizialize Serial(to communicate with USB) and Serial1 (to communicate with barcode scanner)
      Serial.begin(9600);  
      Serial1.begin(9600); 
      // Wifi Setting 
      WiFi.begin(_SSID, _PASSWORD); 
      while (WiFi.status() != WL_CONNECTED) { 
        delay(500); 
        Serial.print("."); 
      } 
      //Some debug strings to return to serial monitor
      Serial.println(""); 
      Serial.println("WiFi connected"); 
      Serial.println("IP address: "); 
      Serial.println(WiFi.localIP()); 
      MQTT_Artik_Client.begin(Artik_Cloud_Server, Artik_Cloud_Port,client);             // Connect to Artik Server 
      while (!MQTT_Artik_Client.connect(Client_Name, Device_ID, Device_TOKEN)) {        // Connect to Artik IOT Device  
        Serial.print("*"); 
        delay(1000); 
      } 
      //MQTT listner
      MQTT_Artik_Client.subscribe(MQTT_Subscription); 
      MQTT_Artik_Client.onMessage(messageReceived);
} 
 
void loop() 
{ 
    MQTT_Artik_Client.loop();
   
    if (Serial1.available()) 
    {     
      // If anything comes in Serial1 (pins 0 & 1)
      //Serial.write(Serial1.read());   // read it and send it out Serial (USB)
      //Serial.print("Barcode=");
      String barcode=Serial1.readString();
      Serial.println();
      //publish on artik cloud
      
      //this function build json payload and return buffer lenght too
      loadBuffer(barcode);
      
      Serial.print("Publishing--->");
      Serial.println(buf);
      //publishing message to Artik Cloud
      MQTT_Artik_Client.publish(MQTT_Publish,buf);
    }
    //Update Timer1
    timer1->Update();
} 

int loadBuffer(String t ) 
{   
      DynamicJsonBuffer  jsonBuffer(200);               // reserve spot in memory 
      JsonObject& root = jsonBuffer.createObject();     // create root objects 
      root["led"]="";
      if(digitalRead(ledPin)==HIGH)
      root["mode"]= "carica";
      else
      root["mode"]= "scarica";
       
      root["barcode"] = t;
      root.printTo(buf, sizeof(buf));                   // JSON-print to buffer 
      return (root.measureLength());                    // also return length 
 
} 
//this function is fired by timeout and turn off led on food scanner and change mode from carica to scarica
void ResetMode()
{
  digitalWrite(ledPin,LOW);
  timer1->Stop();
}

Alexa interact model

JSON
{
  "languageModel": {
    "intents": [
      {
        "name": "AMAZON.CancelIntent",
        "samples": []
      },
      {
        "name": "AMAZON.HelpIntent",
        "samples": []
      },
      {
        "name": "AMAZON.StopIntent",
        "samples": []
      },
      {
        "name": "Charging",
        "samples": [
          "Charging charge the fridge",
          "Charging put the shopping into the fridge"
        ],
        "slots": []
      },
      {
        "name": "SendRecipe",
        "samples": [
          "suggest me a recipe",
          "surprise me with a recipe",
          "i want to cook something",
          "give me a recipe",
          "what should i eat today",
          "what can i cook",
          "what can i cook today",
          "what should i eat",
          "send me recipes",
          "send me some recipe"
        ],
        "slots": []
      },
      {
        "name": "Shopping",
        "samples": [
          "what should i have to buy",
          "give me shopping list",
          "help me with shopping list",
          "what should i have into the fridge",
          "what is missing into the fridge",
          "write me shopping list"
        ],
        "slots": []
      },
      {
        "name": "StopScanning",
        "samples": [
          "shopping bag is empty",
          "stop filling fridge",
          "i have finished",
          "i've finished",
          "stop scanning food"
        ],
        "slots": []
      }
    ],
    "invocationName": "food scanner"
  }
}

Credits

Jordy De Rosa

Jordy De Rosa

1 project • 6 followers

Comments